[Catalyst-commits] r9593 - in Catalyst-Runtime/5.80/branches/uri_for_action: lib t/aggregate t/lib/TestApp/Controller/Action/Chained

hdp at dev.catalyst.perl.org hdp at dev.catalyst.perl.org
Sat Mar 28 04:49:22 GMT 2009


Author: hdp
Date: 2009-03-28 04:49:21 +0000 (Sat, 28 Mar 2009)
New Revision: 9593

Modified:
   Catalyst-Runtime/5.80/branches/uri_for_action/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/uri_for_action/t/aggregate/unit_core_uri_for_action.t
   Catalyst-Runtime/5.80/branches/uri_for_action/t/lib/TestApp/Controller/Action/Chained/Foo.pm
Log:
add uri_for_action and switch tests to use it

Modified: Catalyst-Runtime/5.80/branches/uri_for_action/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_for_action/lib/Catalyst.pm	2009-03-28 04:48:21 UTC (rev 9592)
+++ Catalyst-Runtime/5.80/branches/uri_for_action/lib/Catalyst.pm	2009-03-28 04:49:21 UTC (rev 9593)
@@ -1224,6 +1224,35 @@
     $res;
 }
 
+=head2 $c->uri_for_action( $path, \@captures?, @args?, \%query_values? )
+
+=head2 $c->uri_for_action( $action, \@captures?, @args?, \%query_values? )
+
+=over
+
+=item $path
+
+A private path to the Catalyst action you want to create a URI for.
+
+This is a shortcut for calling C<< $c->dispatcher->get_action_by_path($path)
+>> and passing the resulting C<$action> and the remaining arguments to C<<
+$c->uri_for >>.
+
+You can also pass in a Catalyst::Action object, in which case it is passed to
+C<< $c->uri_for >>.
+
+=back
+
+=cut
+
+sub uri_for_action {
+    my ( $c, $path, @args ) = @_;
+    my $action = blessed($path) 
+      ? $path 
+      : $c->dispatcher->get_action_by_path($path);
+    return $c->uri_for( $action, @args );
+}
+
 =head2 $c->welcome_message
 
 Returns the Catalyst welcome HTML page.

Modified: Catalyst-Runtime/5.80/branches/uri_for_action/t/aggregate/unit_core_uri_for_action.t
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_for_action/t/aggregate/unit_core_uri_for_action.t	2009-03-28 04:48:21 UTC (rev 9592)
+++ Catalyst-Runtime/5.80/branches/uri_for_action/t/aggregate/unit_core_uri_for_action.t	2009-03-28 04:49:21 UTC (rev 9593)
@@ -120,52 +120,50 @@
 #   More Chained with Context Tests
 #
 {
-    sub __action { shift->get_action_by_path( @_ ) }
-
-    is( $context->uri_for( __action( $dispatcher, '/action/chained/endpoint2' ), [1,2], (3,4), { x => 5 } ),
+    is( $context->uri_for_action( '/action/chained/endpoint2', [1,2], (3,4), { x => 5 } ),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2/3/4?x=5',
-        'uri_for correct for chained with multiple captures and args' );
+        'uri_for_action correct for chained with multiple captures and args' );
 
-    is( $context->uri_for( __action( $dispatcher, '/action/chained/three_end' ), [1,2,3], (4,5,6) ),
+    is( $context->uri_for_action( '/action/chained/three_end', [1,2,3], (4,5,6) ),
         'http://127.0.0.1/foo/chained/one/1/two/2/3/three/4/5/6',
-        'uri_for correct for chained with multiple capturing actions' );
+        'uri_for_action correct for chained with multiple capturing actions' );
 
-    my $action_needs_two = __action( $dispatcher, '/action/chained/endpoint2' );
+    my $action_needs_two = '/action/chained/endpoint2';
     
-    ok( ! defined( $context->uri_for($action_needs_two, [1],     (2,3)) ),
-        'uri_for returns undef for not enough captures' );
+    ok( ! defined( $context->uri_for_action($action_needs_two, [1],     (2,3)) ),
+        'uri_for_action returns undef for not enough captures' );
         
-    is( $context->uri_for($action_needs_two,            [1,2],   (2,3)),
+    is( $context->uri_for_action($action_needs_two,            [1,2],   (2,3)),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2/2/3',
-        'uri_for returns correct uri for correct captures' );
+        'uri_for_action returns correct uri for correct captures' );
         
-    ok( ! defined( $context->uri_for($action_needs_two, [1,2,3], (2,3)) ),
-        'uri_for returns undef for too many captures' );
+    ok( ! defined( $context->uri_for_action($action_needs_two, [1,2,3], (2,3)) ),
+        'uri_for_action returns undef for too many captures' );
     
-    is( $context->uri_for($action_needs_two, [1,2],   (3)),
+    is( $context->uri_for_action($action_needs_two, [1,2],   (3)),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2/3',
-        'uri_for returns uri with lesser args than specified on action' );
+        'uri_for_action returns uri with lesser args than specified on action' );
 
-    is( $context->uri_for($action_needs_two, [1,2],   (3,4,5)),
+    is( $context->uri_for_action($action_needs_two, [1,2],   (3,4,5)),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2/3/4/5',
-        'uri_for returns uri with more args than specified on action' );
+        'uri_for_action returns uri with more args than specified on action' );
 
-    is( $context->uri_for($action_needs_two, [1,''], (3,4)),
+    is( $context->uri_for_action($action_needs_two, [1,''], (3,4)),
         'http://127.0.0.1/foo/chained/foo2/1//end2/3/4',
-        'uri_for returns uri with empty capture on undef capture' );
+        'uri_for_action returns uri with empty capture on undef capture' );
 
-    is( $context->uri_for($action_needs_two, [1,2], ('',3)),
+    is( $context->uri_for_action($action_needs_two, [1,2], ('',3)),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2//3',
-        'uri_for returns uri with empty arg on undef argument' );
+        'uri_for_action returns uri with empty arg on undef argument' );
 
-    is( $context->uri_for($action_needs_two, [1,2], (3,'')),
+    is( $context->uri_for_action($action_needs_two, [1,2], (3,'')),
         'http://127.0.0.1/foo/chained/foo2/1/2/end2/3/',
-        'uri_for returns uri with empty arg on undef last argument' );
+        'uri_for_action returns uri with empty arg on undef last argument' );
 
-    my $complex_chained = __action( $dispatcher, '/action/chained/empty_chain_f' );
-    is( $context->uri_for( $complex_chained, [23], (13), {q => 3} ),
+    my $complex_chained = '/action/chained/empty_chain_f';
+    is( $context->uri_for_action( $complex_chained, [23], (13), {q => 3} ),
         'http://127.0.0.1/foo/chained/empty/23/13?q=3',
-        'uri_for returns correct uri for chain with many empty path parts' );
+        'uri_for_action returns correct uri for chain with many empty path parts' );
 }
 
 

Modified: Catalyst-Runtime/5.80/branches/uri_for_action/t/lib/TestApp/Controller/Action/Chained/Foo.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/uri_for_action/t/lib/TestApp/Controller/Action/Chained/Foo.pm	2009-03-28 04:48:21 UTC (rev 9592)
+++ Catalyst-Runtime/5.80/branches/uri_for_action/t/lib/TestApp/Controller/Action/Chained/Foo.pm	2009-03-28 04:49:21 UTC (rev 9593)
@@ -30,8 +30,7 @@
 #
 sub to_root : Chained('/') PathPart('action/chained/to_root') {
     my ( $self, $c ) = @_;
-    my $uri = $c->uri_for(
-        $c->controller('Root')->action_for('chain_root_index') );
+    my $uri = $c->uri_for_action('/chain_root_index');
     $c->res->body( "URI:$uri" );
     $c->stash->{no_end}++;
 }




More information about the Catalyst-commits mailing list