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

sartak at bestpractical.com sartak at bestpractical.com
Mon Aug 25 16:11:58 EDT 2008


Author: sartak
Date: Mon Aug 25 16:11:58 2008
New Revision: 15431

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
   Path-Dispatcher/trunk/t/008-super-dispatcher.t

Log:
 r70287 at onn:  sartak | 2008-08-25 14:21:09 -0400
 Always redispatch (now more extensibly), subclasses can disable this for efficiency if they wish


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:11:58 2008
@@ -95,11 +95,8 @@
             );
         }
 
-        if ($self->defer_to_super_dispatcher($stage, \@matches)) {
-            $dispatch->add_redispatch(
-                $self->super_dispatcher->dispatch($path)
-            );
-        }
+        $dispatch->add_redispatch($self->redispatch($path))
+            if $self->can_redispatch;
 
         $self->end_stage($stage, \@matches);
     }
@@ -110,6 +107,19 @@
     return $dispatch;
 }
 
+sub can_redispatch {
+    my $self = shift;
+
+    return $self->has_super_dispatcher;
+}
+
+sub redispatch {
+    my $self = shift;
+    my $path = shift;
+
+    return $self->super_dispatcher->dispatch($path)
+}
+
 sub run {
     my $self = shift;
     my $path = shift;
@@ -123,26 +133,6 @@
 sub begin_stage {}
 sub end_stage {}
 
-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;
-
-    # okay, let dad have at it!
-    return 1;
-}
-
 sub import {
     my $self = shift;
 

Modified: Path-Dispatcher/trunk/t/008-super-dispatcher.t
==============================================================================
--- Path-Dispatcher/trunk/t/008-super-dispatcher.t	(original)
+++ Path-Dispatcher/trunk/t/008-super-dispatcher.t	Mon Aug 25 16:11:58 2008
@@ -64,7 +64,10 @@
 $sub_dispatcher->run('foo');
 is_deeply([splice @calls], [
     'sub before_on',
+    'super before_on',
     'sub on',
+    'super on',
     'sub after_on',
+    'super after_on',
 ]);
 



More information about the Bps-public-commit mailing list