X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=a0958110ac4baa5d84e383f3a88c3e59a07a66a7;hb=890511ad3dac68ac7e9b8965dc7484beb4cee5fa;hp=63dbee96ab47d5a04224ecfa40694e88acf160f9;hpb=1c470b06b8c6fec5226397ea2bc017ad5021fd38;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 63dbee9..a095811 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 { @@ -191,8 +205,12 @@ sub execute { else { $c->state( &$code( $class, $c, @{ $c->req->args } ) ) } }; if ( my $error = $@ ) { - chomp $error; - $error = qq/Caught exception "$error"/; + + unless ( ref $error ) { + chomp $error; + $error = qq/Caught exception "$error"/; + } + $c->log->error($error); $c->error($error); $c->state(0);