X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=8e0b5130df39dfb0523b5e62c85b0ce0a42c19b5;hb=e7c0c583d6e12e822dd26bf1282eb610c9a59351;hp=a0958110ac4baa5d84e383f3a88c3e59a07a66a7;hpb=890511ad3dac68ac7e9b8965dc7484beb4cee5fa;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index a095811..8e0b513 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -121,14 +121,13 @@ sub dispatch { $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; + return if scalar @{ $c->error }; } # Execute the auto chain for my $auto ( @{ $c->get_action( 'auto', $namespace ) } ) { $c->execute( @{ $auto->[0] } ); - return if scalar @{$c->error}; + return if scalar @{ $c->error }; last unless $c->state; } @@ -142,8 +141,7 @@ sub dispatch { # 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; + return if scalar @{ $c->error }; } } else { @@ -210,7 +208,7 @@ sub execute { chomp $error; $error = qq/Caught exception "$error"/; } - + $c->log->error($error); $c->error($error); $c->state(0); @@ -232,7 +230,7 @@ sub finalize { if ( my $location = $c->response->redirect ) { $c->log->debug(qq/Redirecting to "$location"/) if $c->debug; $c->response->header( Location => $location ); - $c->response->status(302) if $c->response->status !~ /3\d\d$/; + $c->response->status(302) if $c->response->status !~ /^3\d\d$/; } if ( $#{ $c->error } >= 0 ) { @@ -442,6 +440,8 @@ sub forward { } for my $result ( @{$results} ) { $c->execute( @{ $result->[0] } ); + return if scalar @{ $c->error }; + last unless $c->state; } return $c->state; } @@ -460,17 +460,37 @@ sub get_action { $namespace = '' if $namespace eq '/'; my $parent = $c->tree; my @results; - my $result = $c->actions->{private}->{ $parent->getUID }->{$action}; - push @results, [$result] if $result; - my $visitor = Tree::Simple::Visitor::FindByPath->new; - for my $part ( split '/', $namespace ) { - $visitor->setSearchPath($part); - $parent->accept($visitor); - my $child = $visitor->getResult; - my $uid = $child->getUID if $child; - my $match = $c->actions->{private}->{$uid}->{$action} if $uid; - push @results, [$match] if $match; - $parent = $child if $child; + my %allowed = ( begin => 1, auto => 1, default => 1, end => 1 ); + if ( $allowed{$action} ) { + my $result = $c->actions->{private}->{ $parent->getUID }->{$action}; + push @results, [$result] if $result; + my $visitor = Tree::Simple::Visitor::FindByPath->new; + for my $part ( split '/', $namespace ) { + $visitor->setSearchPath($part); + $parent->accept($visitor); + my $child = $visitor->getResult; + my $uid = $child->getUID if $child; + my $match = $c->actions->{private}->{$uid}->{$action} if $uid; + push @results, [$match] if $match; + $parent = $child if $child; + } + } + else { + if ($namespace) { + my $visitor = Tree::Simple::Visitor::FindByPath->new; + $visitor->setSearchPath( split '/', $namespace ); + $parent->accept($visitor); + my $child = $visitor->getResult; + my $uid = $child->getUID if $child; + my $match = $c->actions->{private}->{$uid}->{$action} + if $uid; + push @results, [$match] if $match; + } + else { + my $result = + $c->actions->{private}->{ $parent->getUID }->{$action}; + push @results, [$result] if $result; + } } return \@results; } @@ -796,7 +816,7 @@ sub set_action { $absolute = 1; } $absolute = 1 if $flags{global}; - my $name = $absolute ? $path : "$prefix/$path"; + my $name = $absolute ? $path : $prefix ? "$prefix/$path" : $path; $c->actions->{plain}->{$name} = [ $namespace, $code ]; } if ( my $regex = $flags{regex} ) {