[Catalyst] $c->forward return stuff

Yuval Kogman nothingmuch at woobling.org
Wed May 10 13:45:24 CEST 2006


We can't change that due to compatibility.

In the future we may have a 'call' which is like forward only
without the eval and without the return value munging, so that you
can also return lists.

On Wed, May 10, 2006 at 06:31:28 +0000, fayland wrote:
> is it a bug?
> my code are as follows:
> 
> # common validate
> sub validate : Private {
>     my ( $self, $c, $input ) = @_;
>     my $error;
>     $error->{title} = 'required' unless ($input->{title});
>     <snip> # this place we need $c, so we use "Private" instead normal sub
>     return $error;
> }
> 
> # in another Controller
> my $error = $c->forward('validate', [ { title => $title, ... } ] );
> $error->{another} = '..' unless .. # special validate
> $c->stash->{error} = $error;
> 
> NOW we have problem. Assuming that the validate sub return "$error" is 
> undef, that "in another Controller" my $error would be "0". and 
> *$error->{another}* would complain. I dig into the code and find that:
> 
> Catalyst.pm 1121
>     eval { $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 ) };
> 
> is it a correct return?
> 
> ok I know I can set my $error = { }; in the validate sub. but I just 
> doubt that why there is a "|| 0" needed.
> 
> thanks.
> 
> -- 
> Fayland Lam // http://www.fayland.org/ 
> 
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst

-- 
  Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org  0xEBD27418

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060510/c572fcd9/attachment.pgp 


More information about the Catalyst mailing list