[Catalyst] calling detach within begin
Jim Spath
jspath at pangeamedia.com
Thu Nov 29 20:20:12 GMT 2007
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
More information about the Catalyst
mailing list