[Catalyst] calling detach within begin

Kevin Old kevinold at gmail.com
Thu Nov 29 20:22:32 GMT 2007


Thanks!  As soon as I hit send, I figured that I needed to move that
if clause into my auto method but I couldn't get it to work.  Glad
your reply came in cause I was using detach instead of forward and it
doesn't work the same with detach, must use forward.

Thanks again for your help,
Kevin

On Nov 29, 2007 3:20 PM, Jim Spath <jspath at pangeamedia.com> wrote:
>
> Kevin Old wrote:
> > Hi Jim,
> >
> > I'm running into the same situation and wonder if you could elaborate
> > on what you are doing in your begin method and/or auto method.
> >
> > Here's my begin:
> >
> > sub begin : Private {
> >     my ( $self, $c ) = @_;
> >
> >     [...]
> >
> >     if ( $c->stash->{errs} ) {
> >         $c->stash->{content} = $c->stash->{errs};
> >         $c->stash->{root_name} = 'errors';
> >         $c->stash->{key_attr} = 'error';
> >         $c->forward('V::XMLSimple');
> >         #$c->detach('V::XMLSimple');
> >     }
> >
> > }
> >
> > I'm doing some validation of parameters in my begin method and if
> > there are errors I want to immediately break to my XMLSimple view and
> > stop processing.
> >
> > Thanks for any help with this,
> > Kevin
> >
> > On Jul 16, 2007 5:42 PM, Jim Spath <jspath at pangeamedia.com> wrote:
> >> Jim Spath wrote:
> >>> I can't seem to get a detach call within my application's Root begin to
> >>> work.  While it does seem to stop processing with the begin method,
> >>> Catalyst continues processing whatever action was specified by the request.
> >>>
> >>> I've looked through the docs and it seems like I might need to use auto()?
> >>>
> >>> "The auto action is also distinguished by the fact that you can break
> >>> out of the processing chain by returning 0. If an auto action returns 0,
> >>> any remaining actions will be skipped, except for end."
> >>>
> >>> Should I create an auto() action and forward to the action I was
> >>> previously detaching to, and return 0?
> >> I've gone ahead and started returning auto and it appears to work.
> >>
> >> It might be nice to make a note in the docs somewhere that calling
> >> detach in begin might not do what you expect and that returning 0 from
> >> auto is what you should be doing.
> >>
> >>
> >> --
> >> Jim Spath
>
> Hi Kevin,
>
> I think this should work for you:
>
> sub auto : Private {
>    my ($self, $c) = @_;
>
>    [...]
>
>    if ($c->stash->{errs}) {
>      $c->stash->{content} = $c->stash->{errs};
>      $c->stash->{root_name} = 'errors';
>      $c->stash->{key_attr} = 'error';
>      $c->forward('V::XMLSimple');
>      return 0;
>    }
>
> }
>
> - Jim
>



-- 
Kevin Old
kevin at kevinold.com



More information about the Catalyst mailing list