[Catalyst] Re: [again] die() in an action chain : does not
breakthe chain !
Dami Laurent (PJ)
laurent.dami at justice.ge.ch
Mon Mar 17 08:15:50 GMT 2008
Hi all,
It seems that the discussion on how to break a chain now has moved to
"let's write a special method for breaking the chain, and let's find a
good name for it (candidates : die, abort, halt, fail, error_out,
explode, collapse, stop_that, ...)"
However, this approach still implies that one would have to eval{...} in
almost every method, in order to catch exceptions possibly raised deep
in some remote packages. Spreading eval{...} all around the Catalyst app
is not nice!
So I think something more radical is needed, at the core of the chained
actions mechanism. I tried the following modification to
Catalyst::ActionChain
sub dispatch {
my ( $self, $c ) = @_;
my @captures = @{$c->req->captures||[]};
my @chain = @{ $self->chain };
my $last = pop(@chain);
foreach my $action ( @chain ) {
my @args;
if (my $cap = $action->attributes->{CaptureArgs}) {
@args = splice(@captures, 0, $cap->[0]);
}
local $c->request->{arguments} = \@args;
$action->dispatch( $c );
# ADDED LINE HERE
return if $c->error;
}
$last->dispatch( $c );
}
and it seems to work fine. However, I don't know if this would create
undesirable side-effects, nor if the modification above should become
default, or something that would be toggled by a global Catalyst option.
Any thoughts on that ?
Best regards, Laurent
More information about the Catalyst
mailing list