added a comment, compacted a couple of elses.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index 7e534e0..3d43f9c 100644 (file)
@@ -33,6 +33,7 @@ Like C<forward> but doesn't return.
 sub detach {
     my ( $c, $command, @args ) = @_;
     $c->forward( $command, @args ) if $command;
+    # die with DETACH signal, which will be caught in dispatching.
     die $Catalyst::Engine::DETACH;
 }
 
@@ -92,9 +93,7 @@ sub dispatch {
             $c->execute( @{ $end->[0] } );
             return if scalar @{ $c->error };
         }
-    }
-
-    else {
+    } else {
         my $path  = $c->req->path;
         my $error = $path
           ? qq/Unknown resource "$path"/
@@ -128,7 +127,10 @@ sub forward {
         return 0;
     }
 
-    my $caller    = caller(0);
+    # Relative forwards from detach
+    my $caller = ( caller(0) )[0]->isa('Catalyst::Dispatcher')
+      && ( ( caller(1) )[3] =~ /::detach$/ ) ? caller(1) : caller(0);
+
     my $namespace = '/';
     my $arguments = ( ref( $_[-1] ) eq 'ARRAY' ) ? pop(@_) : $c->req->args;
 
@@ -149,7 +151,7 @@ sub forward {
 
     unless ( @{$results} ) {
 
-        unless ( $c->components->{$command} ) {
+        unless ( defined( $c->components->{$command} ) ) {
             my $error =
 qq/Couldn't forward to command "$command". Invalid action or component./;
             $c->error($error);
@@ -163,9 +165,7 @@ qq/Couldn't forward to command "$command". Invalid action or component./;
         if ( my $code = $c->components->{$class}->can($method) ) {
             $c->actions->{reverse}->{"$code"} = "$class->$method";
             $results = [ [ [ $class, $code ] ] ];
-        }
-
-        else {
+        } else {
             my $error =
               qq/Couldn't forward to "$class". Does not implement "$method"/;
             $c->error($error);
@@ -320,15 +320,15 @@ sub set_action {
     if ( $flags{path} ) {
         $flags{path} =~ s/^\w+//;
         $flags{path} =~ s/\w+$//;
-        if ( $flags{path} =~ /^'(.*)'$/ ) { $flags{path} = $1 }
-        if ( $flags{path} =~ /^"(.*)"$/ ) { $flags{path} = $1 }
+        if ( $flags{path} =~ /^\s*'(.*)'\s*$/ ) { $flags{path} = $1 }
+        if ( $flags{path} =~ /^\s*"(.*)"\s*$/ ) { $flags{path} = $1 }
     }
 
     if ( $flags{regex} ) {
         $flags{regex} =~ s/^\w+//;
         $flags{regex} =~ s/\w+$//;
-        if ( $flags{regex} =~ /^'(.*)'$/ ) { $flags{regex} = $1 }
-        if ( $flags{regex} =~ /^"(.*)"$/ ) { $flags{regex} = $1 }
+        if ( $flags{regex} =~ /^\s*'(.*)'\s*$/ ) { $flags{regex} = $1 }
+        if ( $flags{regex} =~ /^\s*"(.*)"\s*$/ ) { $flags{regex} = $1 }
     }
 
     my $reverse = $prefix ? "$prefix/$method" : $method;