fix ->uri_for*
John Napiorkowski [Sat, 21 Mar 2015 23:51:02 +0000 (18:51 -0500)]
lib/Catalyst/DispatchType/Chained.pm
t/arg_constraints.t

index 2029a6e..f413d9d 100644 (file)
@@ -387,11 +387,15 @@ sub uri_for_action {
     my @captures = @$captures;
     my $parent = "DUMMY";
     my $curr = $action;
+    # If this is an action chain get the last action in the chain
+    if($curr->can('chain') ) {
+      $curr = ${$curr->chain}[-1];
+    }
     while ($curr) {
-        if (my $cap = $curr->attributes->{CaptureArgs}) {
-            return undef unless @captures >= ($cap->[0]||0); # not enough captures
-            if ($cap->[0]) {
-                unshift(@parts, splice(@captures, -$cap->[0]));
+        if (my $cap = $curr->number_of_captures) {
+            return undef unless @captures >= $cap; # not enough captures
+            if ($cap) {
+                unshift(@parts, splice(@captures, -$cap));
             }
         }
         if (my $pp = $curr->attributes->{PathPart}) {
index 62571ce..cfd4f09 100644 (file)
@@ -133,6 +133,9 @@ BEGIN {
 
       sub int_priority_link3 :Chained(link_tuple) PathPart('') Args(Int) { $_[1]->res->body('int_priority_link3') }
 
+      sub link2_int :Chained(link_tuple) PathPart('') CaptureArgs(UserId) { }
+
+        sub finally :Chained(link2_int) PathPart('') Args(Int) { $_[1]->res->body('finally') }
 
   sub default :Default {
     my ($self, $c, $int) = @_;
@@ -292,11 +295,23 @@ SKIP: {
   is $res->content, 'default';
 }
 
-#{
-  # URI testing
-  #my ($res, $c) = ctx_request '/';
+=over
 
+| /chain_base/*/*/*/*/*/*         | /chain_base (1)                    |
+|                                 | -> /link_tuple (3)                 |
+|                                 | -> /link2_int (1)                  |
+|                                 | => /finally (missing...)           |
 
-#}
+=cut
+
+{
+  # URI testing
+  my ($res, $c) = ctx_request '/';
+  ok my $url1 = $c->uri_for($c->controller('Root')->action_for('finally'), [1,2,3,4,5],6);
+  warn $url1;
+
+  ok my $url2 = $c->uri_for($c->controller('Root')->action_for('finally'), [1,2,3,4,5,6]);
+  warn $url2;
+}
 
 done_testing;