From: Rafael Kitover Date: Sat, 1 Aug 2009 19:04:08 +0000 (+0000) Subject: allow uri_for($controller_instance) X-Git-Tag: 5.80008~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=7069eab51d9488288772eafa8b4854617645b2a1 allow uri_for($controller_instance) --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 7556e34..61d9bfc 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1206,6 +1206,12 @@ path, use C<< $c->uri_for_action >> instead. sub uri_for { my ( $c, $path, @args ) = @_; + if (blessed($path) && $path->isa('Catalyst::Controller')) { + $path = $path->path_prefix; + $path =~ s{/+\z}{}; + $path .= '/'; + } + if ( blessed($path) ) { # action object my $captures = ( scalar @args && ref $args[0] eq 'ARRAY' ? shift(@args) diff --git a/t/aggregate/unit_core_uri_for_action.t b/t/aggregate/unit_core_uri_for_action.t index b8f3944..4431f5a 100644 --- a/t/aggregate/unit_core_uri_for_action.t +++ b/t/aggregate/unit_core_uri_for_action.t @@ -8,7 +8,7 @@ use lib "$FindBin::Bin/../lib"; use Test::More; -plan tests => 29; +plan tests => 30; use_ok('TestApp'); @@ -97,6 +97,10 @@ my $context = TestApp->new( { namespace => 'yada', } ); +is($context->uri_for($context->controller('Action')), + "http://127.0.0.1/foo/yada/action/", + "uri_for a controller"); + is($context->uri_for($path_action), "http://127.0.0.1/foo/action/relative/relative", "uri_for correct for path action");