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

sartak at bestpractical.com sartak at bestpractical.com
Sun Oct 19 05:48:42 EDT 2008


Author: sartak
Date: Sun Oct 19 05:48:42 2008
New Revision: 16361

Removed:
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Stage.pm
   Path-Dispatcher/trunk/t/004-stages.t
Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
   Path-Dispatcher/trunk/t/001-api.t
   Path-Dispatcher/trunk/t/003-404.t
   Path-Dispatcher/trunk/t/005-multi-rule.t
   Path-Dispatcher/trunk/t/006-abort.t
   Path-Dispatcher/trunk/t/007-coderef-matcher.t
   Path-Dispatcher/trunk/t/008-super-dispatcher.t
   Path-Dispatcher/trunk/t/009-args.t
   Path-Dispatcher/trunk/t/010-return.t
   Path-Dispatcher/trunk/t/011-next-rule.t
   Path-Dispatcher/trunk/t/013-tokens.t
   Path-Dispatcher/trunk/t/101-subclass.t

Log:
 r74125 at onn:  sartak | 2008-10-19 05:48:38 -0400
 Remove stages! They kind of muddy things for little benefit at this point


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm	Sun Oct 19 05:48:42 2008
@@ -4,11 +4,9 @@
 
 our $VERSION = '0.02';
 
-use Path::Dispatcher::Stage;
 use Path::Dispatcher::Rule;
 use Path::Dispatcher::Dispatch;
 
-sub stage_class    { 'Path::Dispatcher::Stage' }
 sub dispatch_class { 'Path::Dispatcher::Dispatch' }
 
 has name => (
@@ -23,11 +21,15 @@
     },
 );
 
-has stages => (
-    is         => 'rw',
-    isa        => 'ArrayRef[Path::Dispatcher::Stage]',
-    auto_deref => 1,
-    builder    => 'default_stages',
+has _rules => (
+    metaclass => 'Collection::Array',
+    is        => 'rw',
+    isa       => 'ArrayRef[Path::Dispatcher::Rule]',
+    default   => sub { [] },
+    provides  => {
+        push     => 'add_rule',
+        elements => 'rules',
+    },
 );
 
 has super_dispatcher => (
@@ -36,38 +38,15 @@
     predicate => 'has_super_dispatcher',
 );
 
-sub default_stages {
-    my $self = shift;
-    my $stage_class = $self->stage_class;
-
-    my $before = $stage_class->new(name => 'on', qualifier => 'before');
-    my $on     = $stage_class->new(name => 'on');
-    my $after  = $stage_class->new(name => 'on', qualifier => 'after');
-
-    return [$before, $on, $after];
-}
-
-# ugh, we should probably use IxHash..
-sub stage {
-    my $self = shift;
-    my $name = shift;
-
-    for my $stage ($self->stages) {
-        return $stage if $stage->qualified_name eq $name;
-    }
-
-    return;
-}
-
 sub dispatch {
     my $self = shift;
     my $path = shift;
 
     my $dispatch = $self->dispatch_class->new;
 
-    for my $stage ($self->stages) {
-        $self->dispatch_stage(
-            stage    => $stage,
+    for my $rule ($self->rules) {
+        $self->dispatch_rule(
+            rule     => $rule,
             dispatch => $dispatch,
             path     => $path,
         );
@@ -79,20 +58,6 @@
     return $dispatch;
 }
 
-sub dispatch_stage {
-    my $self = shift;
-    my %args = @_;
-
-    my $stage = $args{stage};
-
-    for my $rule ($stage->rules) {
-        $self->dispatch_rule(
-            %args,
-            rule => $rule,
-        );
-    }
-}
-
 sub dispatch_rule {
     my $self = shift;
     my %args = @_;
@@ -151,14 +116,14 @@
     use Path::Dispatcher;
     my $dispatcher = Path::Dispatcher->new;
 
-    $dispatcher->stage("on")->add_rule(
+    $dispatcher->add_rule(
         Path::Dispacher::Rule::Regex->new(
             regex => qr{^/(foo)/.*},
             block => sub { warn $1; }, # foo
         )
     );
 
-    $dispatcher->stage("on")->add_rule(
+    $dispatcher->add_rule(
         Path::Dispacher::Rule::CodeRef->new(
             matcher => sub { /^\d+$/ && $_ % 2 == 0 },
             block   => sub { warn "$_ is an even number" },
@@ -181,8 +146,6 @@
 
 =head1 BUGS
 
-C<after> substages are not yet run properly when primary stage is run.
-
 The order matches when a super dispatch is added B<will> change.
 
 Please report any bugs or feature requests to

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm	Sun Oct 19 05:48:42 2008
@@ -121,7 +121,7 @@
         or die "I don't know how to create a rule for type $matcher";
     my $rule = $rule_creator->($matcher, $block);
 
-    $dispatcher->stage($stage)->add_rule($rule);
+    $dispatcher->add_rule($rule);
 }
 
 1;

Modified: Path-Dispatcher/trunk/t/001-api.t
==============================================================================
--- Path-Dispatcher/trunk/t/001-api.t	(original)
+++ Path-Dispatcher/trunk/t/001-api.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub { push @calls, [@_] },
@@ -26,7 +26,7 @@
 $dispatcher->run('foo');
 is_deeply([splice @calls], [ [] ], "invoked the rule block on 'run'");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/(bar)/,
         block => sub { push @calls, [$1, $2] },

Modified: Path-Dispatcher/trunk/t/003-404.t
==============================================================================
--- Path-Dispatcher/trunk/t/003-404.t	(original)
+++ Path-Dispatcher/trunk/t/003-404.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub { push @calls, [@_] },

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	Sun Oct 19 05:48:42 2008
@@ -8,7 +8,7 @@
 
 my $dispatcher = Path::Dispatcher->new;
 for my $number (qw/first second/) {
-    $dispatcher->stage('on')->add_rule(
+    $dispatcher->add_rule(
         Path::Dispatcher::Rule::Regex->new(
             regex => qr/foo/,
             block => sub { push @calls, $number },

Modified: Path-Dispatcher/trunk/t/006-abort.t
==============================================================================
--- Path-Dispatcher/trunk/t/006-abort.t	(original)
+++ Path-Dispatcher/trunk/t/006-abort.t	Sun Oct 19 05:48:42 2008
@@ -8,7 +8,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub {
@@ -18,7 +18,7 @@
     ),
 );
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub {
@@ -38,7 +38,7 @@
 };
 is_deeply([splice @calls], ['on'], "correctly aborted the entire dispatch");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/bar/,
         block => sub {

Modified: Path-Dispatcher/trunk/t/007-coderef-matcher.t
==============================================================================
--- Path-Dispatcher/trunk/t/007-coderef-matcher.t	(original)
+++ Path-Dispatcher/trunk/t/007-coderef-matcher.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 my (@matches, @calls);
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::CodeRef->new(
         matcher => sub { push @matches, $_; length > 5 },
         block   => sub { push @calls, [@_] },

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	Sun Oct 19 05:48:42 2008
@@ -18,7 +18,7 @@
 is($sub_dispatcher->super_dispatcher, $super_dispatcher, "the super dispatcher is correct");
 
 for my $stage (qw/before_on on after_on/) {
-    $super_dispatcher->stage($stage)->add_rule(
+    $super_dispatcher->add_rule(
         Path::Dispatcher::Rule::Regex->new(
             regex => qr/foo/,
             block => sub { push @calls, "super $stage" },
@@ -27,7 +27,7 @@
 }
 
 for my $stage (qw/before_on after_on/) {
-    $sub_dispatcher->stage($stage)->add_rule(
+    $sub_dispatcher->add_rule(
         Path::Dispatcher::Rule::Regex->new(
             regex => qr/foo/,
             block => sub { push @calls, "sub $stage" },
@@ -51,7 +51,7 @@
 #    'super after_on',
 ]);
 
-$sub_dispatcher->stage('on')->add_rule(
+$sub_dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub { push @calls, "sub on" },

Modified: Path-Dispatcher/trunk/t/009-args.t
==============================================================================
--- Path-Dispatcher/trunk/t/009-args.t	(original)
+++ Path-Dispatcher/trunk/t/009-args.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub { push @calls, [@_] },

Modified: Path-Dispatcher/trunk/t/010-return.t
==============================================================================
--- Path-Dispatcher/trunk/t/010-return.t	(original)
+++ Path-Dispatcher/trunk/t/010-return.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 # we currently have no defined return strategy :/
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub { return @_ },
@@ -20,7 +20,7 @@
 is_deeply([$dispatch->run(24)], []);
 
 for my $stage (qw/before_on on after_on/) {
-    $dispatcher->stage($stage)->add_rule(
+    $dispatcher->add_rule(
         Path::Dispatcher::Rule::Regex->new(
             regex => qr/foo/,
             block => sub { return @_ },

Modified: Path-Dispatcher/trunk/t/011-next-rule.t
==============================================================================
--- Path-Dispatcher/trunk/t/011-next-rule.t	(original)
+++ Path-Dispatcher/trunk/t/011-next-rule.t	Sun Oct 19 05:48:42 2008
@@ -8,7 +8,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub {
@@ -19,7 +19,7 @@
     ),
 );
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub {
@@ -39,7 +39,7 @@
 };
 is_deeply([splice @calls], ['on', 'last'], "correctly continued to the next rule");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/bar/,
         block => sub {

Modified: Path-Dispatcher/trunk/t/013-tokens.t
==============================================================================
--- Path-Dispatcher/trunk/t/013-tokens.t	(original)
+++ Path-Dispatcher/trunk/t/013-tokens.t	Sun Oct 19 05:48:42 2008
@@ -7,7 +7,7 @@
 my @calls;
 
 my $dispatcher = Path::Dispatcher->new;
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Tokens->new(
         tokens => ['foo', 'bar'],
         block  => sub { push @calls, [$1, $2, $3] },
@@ -17,7 +17,7 @@
 $dispatcher->run('foo bar');
 is_deeply([splice @calls], [ ['foo', 'bar', undef] ], "correctly populated number vars from [str, str] token rule");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Tokens->new(
         tokens => ['foo', qr/bar/],
         block  => sub { push @calls, [$1, $2, $3] },
@@ -33,7 +33,7 @@
 $dispatcher->run('foo bar baz');
 is_deeply([splice @calls], [], "no matches");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Tokens->new(
         tokens => [["Bat", "Super"], "Man"],
         block  => sub { push @calls, [$1, $2, $3] },
@@ -49,7 +49,7 @@
 $dispatcher->run('Aqua Man');
 is_deeply([splice @calls], [ ], "no match");
 
-$dispatcher->stage('on')->add_rule(
+$dispatcher->add_rule(
     Path::Dispatcher::Rule::Tokens->new(
         tokens => [[[[qr/Deep/]]], "Man"],
         block  => sub { push @calls, [$1, $2, $3] },

Modified: Path-Dispatcher/trunk/t/101-subclass.t
==============================================================================
--- Path-Dispatcher/trunk/t/101-subclass.t	(original)
+++ Path-Dispatcher/trunk/t/101-subclass.t	Sun Oct 19 05:48:42 2008
@@ -23,7 +23,7 @@
 #    'framework after foo',
 ]);
 
-Path::Dispatcher::Test::App->dispatcher->stage('on')->add_rule(
+Path::Dispatcher::Test::App->dispatcher->add_rule(
     Path::Dispatcher::Rule::Regex->new(
         regex => qr/foo/,
         block => sub {



More information about the Bps-public-commit mailing list