[Catalyst] How to redirect before some code excute

Jonathan Rockway jon at jrock.us
Wed Oct 25 17:54:32 BST 2006


> It's a subroutine, right?
>
> Tried a return?....such as:

What you really want to do is call $c->detach to completely end the
processing chain.  Return will still execute end {} actions, and
continue processing up the class hierarchy:

pacakge A;
@ISA = qw(C);
sub foo {
   ...
   print "before ";
   $self->NEXT::foo();
   print "after ";
}

package C;
sub foo {
   ...
   print "before ";
   return;
   print "after ";
}

That code will print "before before after" whereas detaching will print
"before before" and then end.

> return undef;

Never return undef.  undef in list context is defined and true!  just
"return" instead, since that will be undefined in both list and scalar
contexts.

jrockway at WS-DALI ~
$ perl -e '@array = (undef); print "true" if @array;'
true
jrockway at WS-DALI ~
$ perl -e '@array = (); print "true" if @array;'

Regards,
Jonathan Rockway

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list