From: John Napiorkowski Date: Mon, 23 Mar 2015 00:17:46 +0000 (-0500) Subject: handle infinite args X-Git-Tag: 5.90089_002~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=79b7db20af61e914389b144e57bb7edfd107743c handle infinite args --- diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index aa1abf8..8c86df0 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -120,6 +120,8 @@ has args_constraints => ( my @arg_protos = @{$self->attributes->{Args}||[]}; return [] unless scalar(@arg_protos); + return [] unless defined($arg_protos[0]); + # If there is only one arg and it looks like a number # we assume its 'classic' and the number is the number of # constraints. @@ -187,6 +189,7 @@ has captures_constraints => ( my @arg_protos = @{$self->attributes->{CaptureArgs}||[]}; return [] unless scalar(@arg_protos); + return [] unless defined($arg_protos[0]); # If there is only one arg and it looks like a number # we assume its 'classic' and the number is the number of # constraints. diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index f9e49fa..421175f 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -98,7 +98,7 @@ sub list { @{ $self->_endpoints } ) { my $args = $endpoint->list_extra_info->{Args}; - my @parts = (defined($args) ? (("*") x $args) : '...'); + my @parts = (defined($endpoint->attributes->{Args}[0]) ? (("*") x $args) : '...'); my @parents = (); my $parent = "DUMMY"; my $extra = $self->_list_extra_http_methods($endpoint); @@ -150,13 +150,11 @@ sub list { push(@rows, [ '', $name ]); } - if(defined $endpoint->number_of_args) { - if($endpoint->has_args_constraints) { - my $tc = join ',', @{$endpoint->args_constraints}; - $endpoint .= " ($tc)"; - } else { - $endpoint .= " (${\$endpoint->number_of_args})"; - } + if($endpoint->has_args_constraints) { + my $tc = join ',', @{$endpoint->args_constraints}; + $endpoint .= " ($tc)"; + } else { + $endpoint .= defined($endpoint->attributes->{Args}[0]) ? " ($args)" : " (...)"; } push(@rows, [ '', (@rows ? "=> " : '').($extra ? "$extra " : ''). ($scheme ? "$scheme: ":'')."/${endpoint}". ($consumes ? " :$consumes":"" ) ]); my @display_parts = map { $_ =~s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; decode_utf8 $_ } @parts; diff --git a/t/arg_constraints.t b/t/arg_constraints.t index 02ef732..aabf1f4 100644 --- a/t/arg_constraints.t +++ b/t/arg_constraints.t @@ -135,6 +135,7 @@ BEGIN { sub link2_int :Chained(link_tuple) PathPart('') CaptureArgs(UserId) { } + sub finally2 :GET Chained(link2_int) PathPart('') Args { $_[1]->res->body('finally2') } sub finally :GET Chained(link2_int) PathPart('') Args(Int) { $_[1]->res->body('finally') } sub default :Default { @@ -295,13 +296,27 @@ SKIP: { is $res->content, 'default'; } -=over +{ + my $res = request '/chain_base/1/2/3/3/3/6'; + is $res->content, 'finally'; +} + +{ + my $res = request '/chain_base/1/2/3/3/3/a'; + is $res->content, 'finally2'; +} -| /chain_base/*/*/*/*/*/* | /chain_base (1) | -| | -> /link_tuple (3) | -| | -> /link2_int (1) | -| | => /finally (missing...) | +{ + my $res = request '/chain_base/1/2/3/3/3/6/7/8/9'; + is $res->content, 'finally2'; +} + +=over +| /chain_base/*/*/*/*/*/* | /chain_base (1) | +| | -> /link_tuple (Tuple[Int,Int,Int]) | +| | -> /link2_int (UserId) | +| | => GET /finally (Int) =cut {