handle infinite args
John Napiorkowski [Mon, 23 Mar 2015 00:17:46 +0000 (19:17 -0500)]
lib/Catalyst/Action.pm
lib/Catalyst/DispatchType/Chained.pm
t/arg_constraints.t

index aa1abf8..8c86df0 100644 (file)
@@ -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.
index f9e49fa..421175f 100644 (file)
@@ -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;
index 02ef732..aabf1f4 100644 (file)
@@ -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
 
 {