Fixed relative forwarding
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Dispatcher.pm
index b9bc30f..8f94316 100644 (file)
@@ -58,7 +58,7 @@ sub dispatch {
     my ( $self, $c ) = @_;
 
     if ( $c->action ) {
-        $c->forward( join( '/', '', $c->namespace, '_DISPATCH' ) );
+        $c->forward( join( '/', '', $c->action->namespace, '_DISPATCH' ) );
     }
 
     else {
@@ -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->namespace;
-            $command_copy = "${namespace}/${command}";
+            my $prefix =
+              Catalyst::Utils::class2prefix( $caller,
+                $c->config->{case_sensitive} )
+              || '';
+            $command_copy = "${prefix}/${command}";
         }
 
         unless ( $command_copy =~ /\// ) {
@@ -268,6 +278,10 @@ sub get_containers {
     return map { $_->getNodeValue } @match;
 }
 
+=item $self->register( $c, $action )
+
+=cut
+
 sub register {
     my ( $self, $c, $action ) = @_;