Fixed relative forwarding
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index bf72cf2..8f94316 100644 (file)
@@ -80,6 +80,13 @@ sub forward {
     my $c       = shift;
     my $command = shift;
 
+    # Get the calling class
+    my $caller = ( caller(0) )[0];
+    if ( $caller->isa('Catalyst') ) {
+        if    ( ( caller(2) )[3] =~ /detach$/ )  { $caller = caller(3) }
+        elsif ( ( caller(0) )[3] =~ /forward$/ ) { $caller = caller(1) }
+    }
+
     unless ($command) {
         $c->log->debug('Nothing to forward to') if $c->debug;
         return 0;
@@ -93,8 +100,11 @@ sub forward {
         my $command_copy = $command;
 
         unless ( $command_copy =~ s/^\/// ) {
-            my $namespace = $c->stack->[-1]->namespace;
-            $command_copy = "${namespace}/${command}";
+            my $prefix =
+              Catalyst::Utils::class2prefix( $caller,
+                $c->config->{case_sensitive} )
+              || '';
+            $command_copy = "${prefix}/${command}";
         }
 
         unless ( $command_copy =~ /\// ) {