[Bps-public-commit] r14670 - in Path-Dispatcher/trunk: . lib/Path/Dispatcher t t/lib t/lib/Path t/lib/Path/Dispatcher/Test
sartak at bestpractical.com
sartak at bestpractical.com
Wed Jul 30 16:14:28 EDT 2008
Author: sartak
Date: Wed Jul 30 16:14:28 2008
New Revision: 14670
Added:
Path-Dispatcher/trunk/t/101-subclass.t
Path-Dispatcher/trunk/t/lib/
Path-Dispatcher/trunk/t/lib/Path/
Path-Dispatcher/trunk/t/lib/Path/Dispatcher/
Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/
Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/App.pm
Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/Framework.pm
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
Log:
r68086 at onn: sartak | 2008-07-30 16:14:24 -0400
Add (failing) tests for layering dispatcher rules across subclasses
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 Wed Jul 30 16:14:28 2008
@@ -47,6 +47,20 @@
block => $_[1],
);
},
+ before => sub {
+ $dispatcher->add_rule(
+ stage => 'before',
+ regex => $_[0],
+ block => $_[1],
+ );
+ },
+ after => sub {
+ $dispatcher->add_rule(
+ stage => 'after',
+ regex => $_[0],
+ block => $_[1],
+ );
+ },
};
}
Added: Path-Dispatcher/trunk/t/101-subclass.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/101-subclass.t Wed Jul 30 16:14:28 2008
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+use lib 't/lib';
+use Path::Dispatcher::Test::App;
+
+our @calls;
+
+Path::Dispatcher::Test::Framework->run('foo');
+is_deeply([splice @calls], [
+ 'framework before foo',
+ 'framework on foo',
+ 'framework after foo',
+]);
+
+TODO: {
+ local $TODO = "no layering yet :(";
+ Path::Dispatcher::Test::App->run('foo');
+ is_deeply([splice @calls], [
+ 'app before foo',
+ 'framework before foo',
+ 'framework on foo',
+ 'framework after foo',
+ 'app after foo',
+ ]);
+}
+
+Path::Dispatcher::Test::App->dispatcher->add_rule(
+ regex => qr/foo/,
+ block => sub {
+ push @calls, 'app on foo';
+ },
+);
+
+Path::Dispatcher::Test::App->run('foo');
+is_deeply([splice @calls], [
+ 'app before foo',
+ 'app on foo',
+ 'app after foo',
+]);
+
Added: Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/App.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/App.pm Wed Jul 30 16:14:28 2008
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Test::App;
+use strict;
+use warnings;
+use Path::Dispatcher::Test::Framework -base;
+
+before qr/foo/ => sub {
+ push @main::calls, 'app before foo';
+};
+
+after qr/foo/ => sub {
+ push @main::calls, 'app after foo';
+};
+
+1;
+
Added: Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/Framework.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/lib/Path/Dispatcher/Test/Framework.pm Wed Jul 30 16:14:28 2008
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Test::Framework;
+use strict;
+use warnings;
+use Path::Dispatcher::Declarative -base;
+
+before qr/foo/ => sub {
+ push @main::calls, 'framework before foo';
+};
+
+on qr/foo/ => sub {
+ push @main::calls, 'framework on foo';
+};
+
+after qr/foo/ => sub {
+ push @main::calls, 'framework after foo';
+};
+
+1;
+
More information about the Bps-public-commit
mailing list