X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatcher.pm;h=1b8dfa721f92aab5e4660bd2fafe06a2fd28f859;hp=02b312245e92f3b6430450cfdc70bcaad0a77844;hb=66e28e3f90fa1c00c75ef7e551b7a4c2e6e453be;hpb=ffd92403ac50b1b68ac1ad7934925b465c2d9d4c diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 02b3122..1b8dfa7 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -45,40 +45,26 @@ sub detach { sub dispatch { my ( $self, $c ) = @_; - my $action = $c->req->action; - my $namespace = ''; - $namespace = ( join( '/', @{ $c->req->args } ) || '/' ) - if $action eq 'default'; - - unless ($namespace) { - if ( my $result = $c->get_action($action) ) { - $namespace = $result->[0]->[0]->prefix; - } - } - - my $default = $action eq 'default' ? $namespace : undef; - my $results = $c->get_action( $action, $default, $default ? 1 : 0 ); - $namespace ||= '/'; - - my @containers = $self->get_containers( $namespace ); - my %actions; - foreach my $name (qw/begin auto end/) { - $actions{$name} = [ - map { $_->{$name} } - grep { exists $_->{$name} } - map { $_->actions } - @containers - ]; - } - if ( @{$results} ) { + if ( $c->action ) { + + my @containers = $self->get_containers( $c->namespace ); + my %actions; + foreach my $name (qw/begin auto end/) { + $actions{$name} = [ + map { $_->{$name} } + grep { exists $_->{$name} } + map { $_->actions } + @containers + ]; + } # Errors break the normal flow and the end action is instantly run my $error = 0; # Execute last begin $c->state(1); - if ( my $begin = @{ $actions{begin} }[-1] ) { + if ( my $begin = @{ $actions{begin} }[-1] ) { $begin->execute($c); $error++ if scalar @{ $c->error }; } @@ -97,12 +83,8 @@ sub dispatch { my $mkay = $autorun ? $c->state ? 1 : 0 : 1; if ( ( my $action = $c->req->action ) && $mkay ) { unless ($error) { - if ( my $result = - @{ $c->get_action( $action, $default, 1 ) }[-1] ) - { - $result->[0]->execute($c); - $error++ if scalar @{ $c->error }; - } + $c->action->execute($c); + $error++ if scalar @{ $c->error }; } } @@ -250,14 +232,21 @@ sub prepare_action { } $c->req->match($path); + $c->action($result->[0]); + $c->namespace($result->[0]->prefix); last; } unshift @args, pop @path; } unless ( $c->req->action ) { - $c->req->action('default'); - $c->req->match(''); + my $result = @{$c->get_action('default', $c->req->path, 1) || []}[-1]; + if ($result) { + $c->action( $result->[0] ); + $c->namespace( $c->req->path ); + $c->req->action('default'); + $c->req->match(''); + } } $c->log->debug( 'Arguments are "' . join( '/', @args ) . '"' )