[Catalyst] $c->forward and Exception

Tatsuhiko Miyagawa miyagawa at gmail.com
Sat Jan 28 22:19:48 CET 2006


On 1/27/06, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> 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();
>   }

Yes, true. But it doesn't work with

  $c->forward('/foo/bar')
  $c->forward('Foo::Bar', 'baz');


Thanks,

> -- 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



More information about the Catalyst mailing list