X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FChained.pm;h=0274dba9e3b4de748d99a0e7038c1a2a67944eee;hp=f5ae7ad26054a5382cd9e96c792256ac0abbe55d;hb=953c176dcad596a946c91e409b902473c7369746;hpb=de19de2e6f40d9f8986df5e4f37dc8084a7c83ee diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index f5ae7ad..0274dba 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -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 == 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 (); }