[Bps-public-commit] r15434 - in Path-Dispatcher/trunk: lib/Path lib/Path/Dispatcher t

sartak at bestpractical.com sartak at bestpractical.com
Mon Aug 25 16:12:31 EDT 2008


Author: sartak
Date: Mon Aug 25 16:12:28 2008
New Revision: 15434

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Stage.pm
   Path-Dispatcher/trunk/t/005-multi-rule.t

Log:
 r70290 at onn:  sartak | 2008-08-25 14:32:23 -0400
 Solidify when a match ends the current stage by adding a method to the stage class


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	Mon Aug 25 16:12:28 2008
@@ -77,11 +77,13 @@
     push @{ $rules_for_stage{$_->stage_name} }, $_
         for $self->rules;
 
+    STAGE:
     for my $stage ($self->stages) {
         $self->begin_stage($stage, \@matches);
 
         my $stage_name = $stage->qualified_name;
 
+        RULE:
         for my $rule (@{ delete $rules_for_stage{$stage_name} || [] }) {
             my $vars = $rule->match($path)
                 or next;
@@ -91,11 +93,16 @@
                 rule   => $rule,
                 result => $vars,
             );
+
+            if ($stage->match_ends_stage) {
+                next STAGE;
+            }
         }
 
         $dispatch->add_redispatch($self->redispatch($path))
             if $self->can_redispatch;
-
+    }
+    continue {
         $self->end_stage($stage, \@matches);
     }
 

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Stage.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Stage.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Stage.pm	Mon Aug 25 16:12:28 2008
@@ -21,6 +21,12 @@
     return $name;
 }
 
+# If we're a before/after (qualified) rule, then yeah, we want to continue
+# dispatching. If we're an "on" (unqualified) rule, then no, you only get one.
+sub match_ends_stage {
+    return !shift->is_qualified;
+}
+
 no Moose;
 __PACKAGE__->meta->make_immutable;
 

Modified: Path-Dispatcher/trunk/t/005-multi-rule.t
==============================================================================
--- Path-Dispatcher/trunk/t/005-multi-rule.t	(original)
+++ Path-Dispatcher/trunk/t/005-multi-rule.t	Mon Aug 25 16:12:28 2008
@@ -22,9 +22,7 @@
 $dispatcher->run('foo');
 is_deeply(\@calls, [
     'first: first',
-    'first: second',
     'on: first',
     'last: first',
-    'last: second',
 ]);
 



More information about the Bps-public-commit mailing list