From: John Napiorkowski Date: Sat, 21 Mar 2015 23:51:02 +0000 (-0500) Subject: fix ->uri_for* X-Git-Tag: 5.90089_002~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b684787167ee18eb7e81245f55e0b48a72a8a1b8 fix ->uri_for* --- diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 2029a6e..f413d9d 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -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}) { diff --git a/t/arg_constraints.t b/t/arg_constraints.t index 62571ce..cfd4f09 100644 --- a/t/arg_constraints.t +++ b/t/arg_constraints.t @@ -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;