[Bps-public-commit] r14607 - in Path-Dispatcher/trunk: lib/Path t
sartak at bestpractical.com
sartak at bestpractical.com
Tue Jul 29 13:26:26 EDT 2008
Author: sartak
Date: Tue Jul 29 13:26:25 2008
New Revision: 14607
Added:
Path-Dispatcher/trunk/t/000-compile.t
Path-Dispatcher/trunk/t/001-api.t
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/Makefile.PL
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Log:
r67884 at onn: sartak | 2008-07-29 13:26:05 -0400
Begin the API (upon which the sugar will be built)
Modified: Path-Dispatcher/trunk/Makefile.PL
==============================================================================
--- Path-Dispatcher/trunk/Makefile.PL (original)
+++ Path-Dispatcher/trunk/Makefile.PL Tue Jul 29 13:26:25 2008
@@ -3,6 +3,9 @@
name 'Path-Dispatcher';
all_from 'lib/Path/Dispatcher.pm';
+requires 'Moose';
+requires 'MooseX::AttributeHelpers';
+
build_requires 'Test::More';
WriteAll;
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 13:26:25 2008
@@ -1,8 +1,32 @@
#!/usr/bin/env perl
package Path::Dispatcher;
-use strict;
-use warnings;
+use Moose;
+use MooseX::AttributeHelpers;
+has rules => (
+ metaclass => 'Collection::Array',
+ is => 'rw',
+ isa => 'ArrayRef',
+ default => sub { [] },
+ provides => {
+ push => 'add_rule',
+ },
+);
+
+sub dispatch {
+ my $self = shift;
+
+ return sub {};
+}
+
+sub run {
+ my $self = shift;
+ my $code = $self->dispatch(@_);
+ return $code->();
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
1;
Added: Path-Dispatcher/trunk/t/000-compile.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/000-compile.t Tue Jul 29 13:26:25 2008
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+use_ok 'Path::Dispatcher';
+
Added: Path-Dispatcher/trunk/t/001-api.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/001-api.t Tue Jul 29 13:26:25 2008
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Path::Dispatcher;
+
+my $calls = 0;
+
+my $dispatcher = Path::Dispatcher->new;
+$dispatcher->add_rule(
+ stage => 'on',
+ match => '*',
+ run => sub { ++$calls },
+);
+
+is($calls, 0, "no calls to the dispatcher block yet");
+my $thunk = $dispatcher->dispatch('foo');
+is($calls, 0, "no calls to the dispatcher block yet");
+
+$thunk->();
+is($calls, 1, "made a call to the dispatcher block");
+
+$calls = 0;
+
+$dispatcher->run('foo');
+is($calls, 1, "run does all three stages");
+
More information about the Bps-public-commit
mailing list