Added Catalyst::Request::Upload
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index 21cf434..95f7058 100644 (file)
@@ -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};
+            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;
         }
 
@@ -141,7 +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};
+            return if scalar @{ $c->error };
         }
     }
     else {
@@ -208,7 +209,7 @@ sub execute {
             chomp $error;
             $error = qq/Caught exception "$error"/;
         }
-        
+
         $c->log->error($error);
         $c->error($error);
         $c->state(0);
@@ -230,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 ) {
@@ -440,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;
 }
@@ -458,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;
     }
@@ -794,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} ) {