[Catalyst] $c->forward and Exception

Zbigniew Lukasiak zzbbyy at gmail.com
Sat Jan 28 08:49:03 CET 2006


If you don't need the eval in forward than you can just use simple
subroutine call:
   sub foo : Local {
       my($self, $c) = @_;
       $self->bar($c);
       do_something();
   }

-- Zbyszek

On 1/27/06, Tatsuhiko Miyagawa <miyagawa at gmail.com> wrote:
> I have a Catalyst app which code goes like:
>
>   sub foo : Local {
>       my($self, $c) = @_;
>       $c->forward('bar');
>       do_something();
>   }
>
>   sub bar : Private {
>       my($self, $c) = @_;
>       throw My::Exception() if cond();
>   }
>
> I thought do_something() is not executed when bar throws an Excpetion.
> But it wasn't true. Because forward() is executed in eval {} and
> excpetion is set to $c->error, do_something() *is* executed.
>
> Apparently, I have to write something like:
>
>   $c->forward('bar');
>   die $c->error if $c->error;
>
> everywhere, to make forward() DWIM.
>
> 1) The current $c->forward() behaviour doesn't look intuitive. You'd
> probably need to document it at least.
>
> 2) I'm currently thinking about adding the forward wrapper to do what
> I mean, like:
>
>   sub forward_nice {
>       my $c = shift;
>       $c->forward(@_);
>       die $c->error if $c->error;
>       return $c->state;
>   }
>
> Do you think it's a good idea? If not, lemme know the reason, and
> point me to the alternative solution.
>
>
> --
> Tatsuhiko Miyagawa
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>


More information about the Catalyst mailing list