Added Catalyst::Request::Upload
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index b7d525e..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;
@@ -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 ) {
@@ -413,7 +414,6 @@ sub forward {
         return 0;
     }
     my $caller    = caller(0);
-    my $global    = $command =~ /^\// ? 0 : 1;
     my $namespace = '/';
     if ( $command =~ /^\// ) {
         $command =~ /^(.*)\/(\w+)$/;
@@ -421,7 +421,7 @@ sub forward {
         $command = $2;
     }
     else { $namespace = _class2prefix($caller) || '/' }
-    my $results = $c->get_action( $command, $namespace, $global );
+    my $results = $c->get_action( $command, $namespace );
     unless ( @{$results} ) {
         my $class = $command;
         if ( $class =~ /[^\w\:]/ ) {
@@ -447,30 +447,22 @@ sub forward {
     return $c->state;
 }
 
-=item $c->get_action( $action, $namespace, $global )
+=item $c->get_action( $action, $namespace )
 
 Get an action in a given namespace.
 
 =cut
 
 sub get_action {
-    my ( $c, $action, $namespace, $global ) = @_;
+    my ( $c, $action, $namespace ) = @_;
     return [] unless $action;
     $namespace ||= '';
     if ($namespace) {
-        if ($global) {
-            my @results;
-            for my $uid ( keys %{ $c->actions->{private} } ) {
-                if ( my $result = $c->actions->{private}->{$uid}->{$action} ) {
-                    push @results, [$result];
-                }
-            }
-            return \@results;
-        }
-        else {
-            $namespace = '' if $namespace eq '/';
-            my $parent = $c->tree;
-            my @results;
+        $namespace = '' if $namespace eq '/';
+        my $parent = $c->tree;
+        my @results;
+        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;
@@ -483,8 +475,25 @@ sub get_action {
                 push @results, [$match] if $match;
                 $parent = $child if $child;
             }
-            return \@results;
         }
+        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;
     }
     elsif ( my $p = $c->actions->{plain}->{$action} ) { return [ [$p] ] }
     elsif ( my $r = $c->actions->{regex}->{$action} ) { return [ [$r] ] }