Mailing List Archive

[PATCH] forwarding to Catalyst::Action objects (5.8)
This patch lets you forward to a Catalyst::Action object, which
currently does not work.

--
Caelum
Re: [PATCH] forwarding to Catalyst::Action objects (5.8) [ In reply to ]
On Thu, Oct 16, 2008 at 09:11:55PM -0700, Rafael Kitover wrote:
> This patch lets you forward to a Catalyst::Action object, which
> currently does not work.

I could've sworn this used to work via the stringify. I wonder why it
doesn't anymore ... (that was definitely why I put that stringify in
there, anyway - always possible I only -thought- it worked and forgot
the test)

> --
> Caelum

> Index: t/lib/TestApp/Controller/Action/Forward.pm
> ===================================================================
> --- t/lib/TestApp/Controller/Action/Forward.pm (revision 8548)
> +++ t/lib/TestApp/Controller/Action/Forward.pm (working copy)
> @@ -57,6 +57,11 @@
> $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';
> Index: t/aggregate/live_component_controller_action_forward.t
> ===================================================================
> --- t/aggregate/live_component_controller_action_forward.t (revision 8548)
> +++ t/aggregate/live_component_controller_action_forward.t (working copy)
> @@ -10,7 +10,7 @@
>
> 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 @@
> 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: lib/Catalyst/Dispatcher.pm
> ===================================================================
> --- lib/Catalyst/Dispatcher.pm (revision 8548)
> +++ lib/Catalyst/Dispatcher.pm (working copy)
> @@ -133,8 +133,13 @@
> 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)

> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev@lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev