[Bps-public-commit] r16372 - in Path-Dispatcher/trunk: lib/Path/Dispatcher t
sartak at bestpractical.com
sartak at bestpractical.com
Sun Oct 19 07:19:53 EDT 2008
Author: sartak
Date: Sun Oct 19 07:19:43 2008
New Revision: 16372
Added:
Path-Dispatcher/trunk/t/016-more-under.t
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
Log:
r74149 at onn: sartak | 2008-10-19 07:19:27 -0400
Initial support for "under" but it won't compose with itself so we need more syntax
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 07:19:43 2008
@@ -82,6 +82,17 @@
after => sub {
_add_rule($dispatcher, 'after_on', @_);
},
+ under => sub {
+ my $predicate = _create_rule('on', shift);
+ $predicate->prefix(1);
+ my @rules = @_;
+
+ my $under = Path::Dispatcher::Rule::Under->new(
+ predicate => $predicate,
+ rules => \@rules,
+ );
+ $dispatcher->add_rule($under);
+ },
next_rule => sub { die "Path::Dispatcher next rule\n" },
last_rule => sub { die "Path::Dispatcher abort\n" },
};
Added: Path-Dispatcher/trunk/t/016-more-under.t
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/t/016-more-under.t Sun Oct 19 07:19:43 2008
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+my @calls;
+
+do {
+ package Under::Where;
+ use Path::Dispatcher::Declarative -base;
+
+ under [ 'ticket' ] => (
+ on 'create' => sub { push @calls, "ticket create" },
+ on 'update' => sub { push @calls, "ticket update" },
+ );
+};
+
+Under::Where->run('ticket create');
+is_deeply([splice @calls], ['ticket create']);
+
+Under::Where->run('ticket update');
+is_deeply([splice @calls], ['ticket update']);
+
+Under::Where->run('ticket foo');
+is_deeply([splice @calls], []);
+
More information about the Bps-public-commit
mailing list