Fix forwarding to Catalyst::Action objects.
Florian Ragwitz [Fri, 17 Oct 2008 07:27:44 +0000 (07:27 +0000)]
Patch by Caelum++

Changes
lib/Catalyst.pm
lib/Catalyst/Dispatcher.pm
t/aggregate/live_component_controller_action_forward.t
t/lib/TestApp/Controller/Action/Forward.pm

diff --git a/Changes b/Changes
index 94fff4f..755cf22 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Fix forwarding to Catalyst::Action objects (Rafael Kitover).
         - Fix links to the mailing lists (Florian Ragwitz).
         - Use Class::MOP instead of Class::Inspector (Florian Ragwitz).
         - Change Catalyst::Test to use Sub::Exporter (Florian Ragwitz).
index 5684d94..0e95451 100644 (file)
@@ -2481,6 +2481,8 @@ audreyt: Audrey Tang
 
 bricas: Brian Cassidy <bricas@cpan.org>
 
+Caelum: Rafael Kitover <rkitover@io.com>
+
 chansen: Christian Hansen
 
 chicks: Christopher Hicks
index 575b1a6..2f5430e 100644 (file)
@@ -133,8 +133,13 @@ sub _command2action {
     my $action;
 
     # go to a string path ("/foo/bar/gorch")
-    # or action object which stringifies to that
-    $action = $self->_invoke_as_path( $c, "$command", \@args );
+    # or action object
+    if (Scalar::Util::blessed($command) && $command->isa('Catalyst::Action')) {
+        $action = $command;
+    }
+    else {
+        $action = $self->_invoke_as_path( $c, "$command", \@args );
+    }
 
     # go to a component ( "MyApp::*::Foo" or $c->component("...")
     # - a path or an object)
index 750c067..3000398 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 50 * $iters;
+use Test::More tests => 53 * $iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -245,4 +245,15 @@ sub run_tests {
         is( $response->content, '/action/forward/foo/bar',
              'forward_to_uri_check correct namespace');
     }
+
+    # test forwarding to Catalyst::Action objects
+    {
+        ok( my $response = request(
+            'http://localhost/action/forward/to_action_object'),
+            'forward/to_action_object request');
+
+        ok( $response->is_success, 'forward/to_action_object successful');
+        is( $response->content, 'mtfnpy',
+             'forward/to_action_object forwards correctly');
+    }
 }
index e118d73..062d6a1 100644 (file)
@@ -57,6 +57,11 @@ sub with_method_and_args : Local {
     $c->res->body( $c->req->args->[0] );
 }
 
+sub to_action_object : Local {
+    my ( $self, $c ) = @_;
+    $c->forward($self->action_for('embed'), [qw/mtfnpy/]);
+}
+
 sub args : Local {
     my ( $self, $c, $val ) = @_;
     die "Expected argument 'new', got '$val'" unless $val eq 'new';