[Bps-public-commit] r14615 - in Path-Dispatcher/trunk: lib/Path/Dispatcher t
sartak at bestpractical.com
sartak at bestpractical.com
Tue Jul 29 15:45:40 EDT 2008
Author: sartak
Date: Tue Jul 29 15:45:30 2008
New Revision: 14615
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
Path-Dispatcher/trunk/t/001-api.t
Log:
r67897 at onn: sartak | 2008-07-29 15:34:10 -0400
Refactor the dispatcher rule, solidify the "match" method
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm Tue Jul 29 15:45:30 2008
@@ -9,7 +9,7 @@
required => 1,
);
-has match => (
+has regex => (
is => 'rw',
isa => 'Regexp',
required => 1,
@@ -21,22 +21,13 @@
required => 1,
);
-around BUILDARGS => sub {
- my $orig = shift;
- my $self = shift;
- my $args = $self->$orig(@_);
-
- $args->{match} = qr/$args->{match}/
- if !ref($args->{match});
-
- return $args;
-};
-
-sub matches {
+sub match {
my $self = shift;
my $path = shift;
- return $path =~ $self->match;
+ return unless $path =~ $self->regex;
+
+ return [ map { substr($path, $-[$_], $+[$_] - $-[$_]) } 1 .. $#- ]
}
sub run {
Modified: Path-Dispatcher/trunk/t/001-api.t
==============================================================================
--- Path-Dispatcher/trunk/t/001-api.t (original)
+++ Path-Dispatcher/trunk/t/001-api.t Tue Jul 29 15:45:30 2008
@@ -8,7 +8,7 @@
my $dispatcher = Path::Dispatcher->new;
$dispatcher->add_rule(
- match => 'foo',
+ regex => qr/foo/,
block => sub { push @calls, [@_] },
);
More information about the Bps-public-commit
mailing list