X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=ee6afcbb592439e978271cda721a4770f42e7637;hb=78728dc6dfe8585f3216764b359c2439be2a8e7b;hp=63dbee96ab47d5a04224ecfa40694e88acf160f9;hpb=1c470b06b8c6fec5226397ea2bc017ad5021fd38;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 63dbee9..ee6afcb 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -116,20 +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; } - if ( my $action = @{ $c->get_action( $action, $default ) }[-1] ) { - $c->execute( @{ $action->[0] } ); + + # 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; } - for my $end ( reverse @{ $c->get_action( 'end', $namespace ) } ) { + + # 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] } ); + } + } + + # 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; + last unless $c->state; } } else {