[Bps-public-commit] Path-Dispatcher branch, master, updated. 05836f7eb86cb817b49b1dc48890acb9f902a281
Shawn Moore
sartak at bestpractical.com
Sun Oct 24 01:26:04 EDT 2010
The branch, master has been updated
via 05836f7eb86cb817b49b1dc48890acb9f902a281 (commit)
via 0e5f84a976247b552049aa8dca6c64a3d2bcba36 (commit)
via 8bdc70d7ea395ec8b607dcb3d64ab502d2aac573 (commit)
via 699ed8d9f621521124b205bb61b73f49dfa0349c (commit)
from 074101f4f457303ec1c132bcfee6833eaf8fc114 (commit)
Summary of changes:
lib/Path/Dispatcher/Match.pm | 6 ++++++
lib/Path/Dispatcher/Rule.pm | 2 ++
lib/Path/Dispatcher/Rule/Under.pm | 9 ++++++++-
t/031-structured-match.t | 30 ++++++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 1 deletions(-)
create mode 100644 t/031-structured-match.t
- Log -----------------------------------------------------------------
commit 699ed8d9f621521124b205bb61b73f49dfa0349c
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sun Oct 24 14:24:55 2010 +0900
Give matches a parent match (for Under etc)
diff --git a/lib/Path/Dispatcher/Match.pm b/lib/Path/Dispatcher/Match.pm
index 3963f65..4794313 100644
--- a/lib/Path/Dispatcher/Match.pm
+++ b/lib/Path/Dispatcher/Match.pm
@@ -33,6 +33,12 @@ has named_captures => (
default => sub { {} },
);
+has parent => (
+ is => 'ro',
+ isa => 'Path::Dispatcher::Match',
+ predicate => 'has_parent',
+);
+
sub run {
my $self = shift;
commit 8bdc70d7ea395ec8b607dcb3d64ab502d2aac573
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sun Oct 24 14:25:25 2010 +0900
Let the caller easily pass extra args to the match constructor
diff --git a/lib/Path/Dispatcher/Rule.pm b/lib/Path/Dispatcher/Rule.pm
index c08405c..4e02648 100644
--- a/lib/Path/Dispatcher/Rule.pm
+++ b/lib/Path/Dispatcher/Rule.pm
@@ -20,6 +20,7 @@ has prefix => (
sub match {
my $self = shift;
my $path = shift;
+ my %args = @_;
my $result;
@@ -39,6 +40,7 @@ sub match {
my $match = $self->match_class->new(
path => $path,
rule => $self,
+ %{ $args{extra_constructor_args} || {} },
%$result,
);
commit 0e5f84a976247b552049aa8dca6c64a3d2bcba36
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sun Oct 24 14:25:42 2010 +0900
Pass the parent match to the new match's constructor
diff --git a/lib/Path/Dispatcher/Rule/Under.pm b/lib/Path/Dispatcher/Rule/Under.pm
index e28acc1..908cdd0 100644
--- a/lib/Path/Dispatcher/Rule/Under.pm
+++ b/lib/Path/Dispatcher/Rule/Under.pm
@@ -32,7 +32,14 @@ sub match {
# Because the checking for ::Chain endpointedness is here, this means that outside of an ::Under, ::Chain behaves like
# an ::Always (one that will always trigger next_rule if it's block is ran)
#
- return unless my @matches = grep { defined } map { $_->match($new_path) } $self->rules;
+ my @matches = map {
+ $_->match(
+ $new_path,
+ extra_constructor_args => {
+ parent => $prefix_match,
+ },
+ )
+ } $self->rules;
pop @matches while @matches && $matches[-1]->rule->isa('Path::Dispatcher::Rule::Chain');
return @matches;
}
commit 05836f7eb86cb817b49b1dc48890acb9f902a281
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Sun Oct 24 14:25:55 2010 +0900
Tests for capturing Under prefix parameters
diff --git a/t/031-structured-match.t b/t/031-structured-match.t
new file mode 100644
index 0000000..2c5370a
--- /dev/null
+++ b/t/031-structured-match.t
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Path::Dispatcher;
+
+my $dispatcher = Path::Dispatcher->new(
+ rules => [
+ Path::Dispatcher::Rule::Under->new(
+ predicate => Path::Dispatcher::Rule::Regex->new(
+ regex => qr/^(\w+) /,
+ prefix => 1,
+ ),
+ rules => [
+ Path::Dispatcher::Rule::Regex->new(
+ regex => qr/^(\w+)/,
+ block => sub { return shift }
+ ),
+ ],
+ ),
+ ],
+);
+
+my $match = $dispatcher->run("hello world");
+ok($match, "matched");
+is($match->pos(1), 'world', 'inner capture');
+is($match->parent->pos(1), 'hello', 'outer capture');
+
+done_testing;
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list