From: Florian Ragwitz Date: Fri, 17 Oct 2008 07:27:44 +0000 (+0000) Subject: Fix forwarding to Catalyst::Action objects. X-Git-Tag: 5.8000_03~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e31b525c69917c8cc685ada77222d8d31a8263df;hp=6d4c336866c2ec8d50aecfd00b038ada55f7eea6 Fix forwarding to Catalyst::Action objects. Patch by Caelum++ --- diff --git a/Changes b/Changes index 94fff4f..755cf22 100644 --- 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). diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 5684d94..0e95451 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2481,6 +2481,8 @@ audreyt: Audrey Tang bricas: Brian Cassidy +Caelum: Rafael Kitover + chansen: Christian Hansen chicks: Christopher Hicks diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 575b1a6..2f5430e 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -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) diff --git a/t/aggregate/live_component_controller_action_forward.t b/t/aggregate/live_component_controller_action_forward.t index 750c067..3000398 100644 --- a/t/aggregate/live_component_controller_action_forward.t +++ b/t/aggregate/live_component_controller_action_forward.t @@ -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'); + } } diff --git a/t/lib/TestApp/Controller/Action/Forward.pm b/t/lib/TestApp/Controller/Action/Forward.pm index e118d73..062d6a1 100644 --- a/t/lib/TestApp/Controller/Action/Forward.pm +++ b/t/lib/TestApp/Controller/Action/Forward.pm @@ -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';