Fixed relative forwarding
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 3d2f825..4afa241 100644 (file)
@@ -19,11 +19,13 @@ use Scalar::Util qw/weaken/;
 use attributes;
 
 __PACKAGE__->mk_accessors(
-    qw/counter depth request response state action namespace/
+    qw/counter request response state action stack namespace/
 );
 
 attributes->import( __PACKAGE__, \&namespace, 'lvalue' );
 
+sub depth { scalar @{ shift->stack || [] }; }
+
 # Laziness++
 *comp = \&component;
 *req  = \&request;
@@ -52,7 +54,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI');
 __PACKAGE__->request_class('Catalyst::Request');
 __PACKAGE__->response_class('Catalyst::Response');
 
-our $VERSION = '5.49_03';
+our $VERSION = '5.49_04';
 
 sub import {
     my ( $class, @arguments ) = @_;
@@ -841,7 +843,11 @@ sub execute {
     my ( $c, $class, $code ) = @_;
     $class = $c->components->{$class} || $class;
     $c->state(0);
-    my $callsub = ( caller(1) )[3];
+
+    my $callsub =
+        ( caller(0) )[0]->isa('Catalyst::Action')
+      ? ( caller(2) )[3]
+      : ( caller(1) )[3];
 
     my $action = '';
     if ( $c->debug ) {
@@ -859,7 +865,7 @@ sub execute {
 
         $action = "-> $action" if $callsub =~ /forward$/;
     }
-    $c->{depth}++;
+    push( @{ $c->stack }, $code );
     eval {
         if ( $c->debug )
         {
@@ -876,11 +882,11 @@ sub execute {
             $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 );
         }
     };
-    $c->{depth}--;
+    pop( @{ $c->stack } );
 
     if ( my $error = $@ ) {
 
-        if ( $error eq $DETACH ) { die $DETACH if $c->{depth} > 1 }
+        if ( $error eq $DETACH ) { die $DETACH if $c->depth > 1 }
         else {
             unless ( ref $error ) {
                 chomp $error;
@@ -1083,7 +1089,7 @@ sub prepare {
     my $c = $class->context_class->new(
         {
             counter => {},
-            depth   => 0,
+            stack   => [],
             request => $class->request_class->new(
                 {
                     arguments        => [],
@@ -1667,6 +1673,10 @@ sub setup_plugins {
     }
 }
 
+=item $c->stack
+
+Contains the stack.
+
 =item $c->write( $data )
 
 Writes $data to the output stream.  When using this method directly, you will