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

sartak at bestpractical.com sartak at bestpractical.com
Wed Jul 30 16:46:00 EDT 2008


Author: sartak
Date: Wed Jul 30 16:45:49 2008
New Revision: 14673

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher.pm

Log:
 r68112 at onn:  sartak | 2008-07-30 16:44:16 -0400
 Small refactor to give defer_to_super_dispatcher more control


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	Wed Jul 30 16:45:49 2008
@@ -54,15 +54,13 @@
 
     for my $stage ($self->stages) {
         $self->begin_stage($stage, \@matches);
-        my $stage_matches = 0;
 
         for my $rule (@{ $rules_for_stage{$stage} || [] }) {
             my $vars = $rule->match($path)
                 or next;
 
-            ++$stage_matches;
-
             push @matches, {
+                stage  => $stage,
                 rule   => $rule,
                 result => $vars,
             };
@@ -70,11 +68,7 @@
             last if !$rule->fallthrough;
         }
 
-        my $defer = $stage_matches == 0
-                 && $self->has_super_dispatcher
-                 && $self->defer_to_super_dispatcher($stage);
-
-        if ($defer) {
+        if ($self->defer_to_super_dispatcher($stage, \@matches)) {
             push @matches, $self->super_dispatcher->dispatch($path);
         }
 
@@ -150,9 +144,21 @@
 sub defer_to_super_dispatcher {
     my $self = shift;
     my $stage = shift;
+    my $matches = shift;
+
+    return 0 if !$self->has_super_dispatcher;
+
+    # we only defer in the "on" stage.. this is sort of yucky, maybe we want
+    # implicit "before/after" every stage
+    return 0 unless $stage eq 'on';
+
+    # do not defer if we have any matches for this stage
+    return 0 if grep { $_->{stage} eq $stage }
+                grep { ref($_) eq 'HASH' }
+                @$matches;
 
-    return 1 if $stage eq 'on';
-    return 0;
+    # okay, let dad have at it!
+    return 1;
 }
 
 __PACKAGE__->meta->make_immutable;



More information about the Bps-public-commit mailing list