authors cleanup
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Chained.pm
index f5ae7ad..0a2a038 100644 (file)
@@ -170,17 +170,28 @@ sub recurse_match {
                     local $c->req->{arguments} = [ @{$c->req->args}, @parts ];
                     next TRY_ACTION unless $action->match($c);
                 }
-                if (!$best_action || $#parts < $#{$best_action->{parts}}){
+                my $args_attr = $action->attributes->{Args}->[0];
+
+                #    No best action currently
+                # OR This one matches with fewer parts left than the current best action,
+                #    And therefore is a better match
+                # OR No parts and this expects 0 
+                #    The current best action might also be Args(0),
+                #    but we couldn't chose between then anyway so we'll take the last seen
+
+                if (!$best_action                       ||
+                    @parts < @{$best_action->{parts}}   ||
+                    (!@parts && $args_attr eq 0)){
                     $best_action = {
                         actions => [ $action ],
                         captures=> [],
                         parts   => \@parts
-                        }
                     }
+                }
             }
         }
     }
-    return @$best_action{qw/actions captures parts /} if $best_action;
+    return @$best_action{qw/actions captures parts/} if $best_action;
     return ();
 }
 
@@ -197,7 +208,7 @@ sub register {
 
     return 0 unless @chained_attr;
 
-    if (@chained_attr > 2) {
+    if (@chained_attr > 1) {
         Catalyst::Exception->throw(
           "Multiple Chained attributes not supported registering ${action}"
         );
@@ -544,9 +555,9 @@ The C<forward>ing to other actions does just what you would expect. But if
 you C<detach> out of a chain, the rest of the chain will not get called
 after the C<detach>.
 
-=head1 AUTHOR
+=head1 AUTHORS
 
-Matt S Trout <mst@shadowcatsystems.co.uk>
+Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT