X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=95f7058a1d26ff8b9ab8f86824a50ce5a1ee27f6;hb=146554c575f7f9fda102985196e0b6b364847bc0;hp=5b3e3d5610b02125e9a5e5b547c88c403c0682e1;hpb=5bf31738cf1fe7fbd4709ae17122fd2cbf326860;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 5b3e3d5..95f7058 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -14,6 +14,7 @@ use Text::ASCIITable::Wrap 'wrap'; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; use Catalyst::Request; +use Catalyst::Request::Upload; use Catalyst::Response; require Module::Pluggable::Fast; @@ -121,13 +122,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 }; last unless $c->state; } @@ -141,8 +142,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 { @@ -204,8 +204,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); @@ -227,7 +231,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 ) { @@ -437,6 +441,8 @@ sub forward { } for my $result ( @{$results} ) { $c->execute( @{ $result->[0] } ); + return if scalar @{ $c->error }; + last unless $c->state; } return $c->state; } @@ -455,17 +461,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; } @@ -791,7 +817,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} ) {