[Bps-public-commit] r14626 - in Path-Dispatcher/trunk: lib/Path lib/Path/Dispatcher t
sartak at bestpractical.com
sartak at bestpractical.com
Tue Jul 29 16:57:39 EDT 2008
Author: sartak
Date: Tue Jul 29 16:57:39 2008
New Revision: 14626
Added:
Path-Dispatcher/trunk/t/005-multi-rule.t
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
Log:
r67917 at onn: sartak | 2008-07-29 16:57:29 -0400
Allow rules to be "fallthrough" or not; by default, "on" rules are not fallthrough, others are
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm Tue Jul 29 16:57:39 2008
@@ -57,6 +57,8 @@
rule => $rule,
vars => $vars,
};
+
+ last if !$rule->fallthrough;
}
$self->end_stage($stage, \@matches);
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm Tue Jul 29 16:57:39 2008
@@ -21,6 +21,16 @@
required => 1,
);
+has fallthrough => (
+ is => 'ro',
+ isa => 'Bool',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ $self->stage eq 'on' ? 0 : 1;
+ },
+);
+
sub match {
my $self = shift;
my $path = shift;
Added: Path-Dispatcher/trunk/t/005-multi-rule.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/005-multi-rule.t Tue Jul 29 16:57:39 2008
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+use Path::Dispatcher;
+
+my @calls;
+
+my $dispatcher = Path::Dispatcher->new;
+for my $stage (qw/before on after/) {
+ for my $number (qw/first second/) {
+ $dispatcher->add_rule(
+ stage => $stage,
+ regex => qr/foo/,
+ block => sub { push @calls, "$stage: $number" },
+ );
+ }
+}
+
+$dispatcher->run('foo');
+is_deeply(\@calls, [
+ 'before: first',
+ 'before: second',
+ 'on: first',
+ 'after: first',
+ 'after: second',
+]);
+
More information about the Bps-public-commit
mailing list