DispatchType/Chained:
Gareth Kirwan [Mon, 18 Aug 2008 19:03:08 +0000 (19:03 +0000)]
A chain of equal actions but less captures should win over one with more captures.
Less captures is taken to mean it did so less ambiguously, and therefore wins the fight.
A chain of more actions will lose to one of less actions even if it had less captures, though.
i.e.: Actions beat Captures, but Captures decide betwixt Actions.

lib/Catalyst/DispatchType/Chained.pm

index 0a2a038..71fec41 100644 (file)
@@ -157,7 +157,14 @@ sub recurse_match {
                 my ($actions, $captures, $action_parts) = $self->recurse_match(
                                              $c, '/'.$action->reverse, \@parts
                                            );
-                if ($actions && (!$best_action || $#$action_parts < $#{$best_action->{parts}})){
+                #    No best action currently
+                # OR The action has less parts
+                # OR The action has equal parts but less captured data (ergo more defined)
+                if ($actions    &&
+                    (!$best_action                                 ||
+                     $#$action_parts < $#{$best_action->{parts}}   ||
+                     ($#$action_parts == $#{$best_action->{parts}} &&
+                      $#$captures < $#{$best_action->{captures}}))){
                     $best_action = {
                         actions => [ $action, @$actions ],
                         captures=> [ @captures, @$captures ],