X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=ee6afcbb592439e978271cda721a4770f42e7637;hb=78728dc6dfe8585f3216764b359c2439be2a8e7b;hp=41a5049c96928f55cd1c7aa815386c2dce7c917f;hpb=a135d186f7acefbbab74e8e6d9a43ccd3560d326;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 41a5049..ee6afcb 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -116,17 +116,34 @@ sub dispatch { my $results = $c->get_action( $action, $default ); $namespace ||= '/'; if ( @{$results} ) { - for my $begin ( @{ $c->get_action( 'begin', $namespace ) } ) { + + # Execute last begin + $c->state(1); + if ( my $begin = @{ $c->get_action( 'begin', $namespace ) }[-1] ) { $c->execute( @{ $begin->[0] } ); + return if scalar @{$c->error}; + last unless $c->state; + } + + # Execute the auto chain + for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { + $c->execute( @{ $auto->[0] } ); + return if scalar @{$c->error}; + last unless $c->state; } - if ( my $action = $c->req->action ) { - for my $result ( @{ $c->get_action( $action, $default ) }[-1] ) { + + # Execute the action or last default + if ( ( my $action = $c->req->action ) && $c->state ) { + if ( my $result = @{ $c->get_action( $action, $default ) }[-1] ) { $c->execute( @{ $result->[0] } ); - last unless $default; } } - for my $end ( reverse @{ $c->get_action( 'end', $namespace ) } ) { + + # Execute last end + if ( my $end = @{ $c->get_action( 'end', $namespace ) }[-1] ) { $c->execute( @{ $end->[0] } ); + return if scalar @{$c->error}; + last unless $c->state; } } else { @@ -191,7 +208,7 @@ sub execute { chomp $error; $error = qq/Caught exception "$error"/; $c->log->error($error); - $c->error($error) if $c->debug; + $c->error($error); $c->state(0); } return $c->state;