From: Sebastian Riedel Date: Mon, 4 Apr 2005 14:29:32 +0000 (+0000) Subject: auto actions X-Git-Tag: 5.7099_04~1600 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5bf31738cf1fe7fbd4709ae17122fd2cbf326860;hp=1c470b06b8c6fec5226397ea2bc017ad5021fd38 auto actions --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 63dbee9..5b3e3d5 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -116,17 +116,30 @@ 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] } ); - return if scalar @{$c->error}; + + # Execute the auto chain + for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { + $c->execute( @{ $auto->[0] } ); 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;