[Bps-public-commit] r16907 - in Path-Dispatcher/trunk: lib/Path lib/Path/Dispatcher lib/Path/Dispatcher/Rule
sartak at bestpractical.com
sartak at bestpractical.com
Tue Nov 18 19:06:57 EST 2008
Author: sartak
Date: Tue Nov 18 19:06:57 2008
New Revision: 16907
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Always.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Empty.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
Log:
r75738 at onn: sartak | 2008-11-18 19:06:34 -0500
First cut of conversion to use path objects
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher.pm Tue Nov 18 19:06:57 2008
@@ -7,8 +7,10 @@
use Path::Dispatcher::Rule;
use Path::Dispatcher::Dispatch;
+use Path::Dispatcher::Path;
-sub dispatch_class { 'Path::Dispatcher::Dispatch' }
+use constant dispatch_class => 'Path::Dispatcher::Dispatch';
+use constant path_class => 'Path::Dispatcher::Path';
has name => (
is => 'rw',
@@ -38,6 +40,12 @@
my $self = shift;
my $path = shift;
+ if (!ref($path)) {
+ $path = $self->path_class->new(
+ path => $path,
+ );
+ }
+
my $dispatch = $self->dispatch_class->new;
for my $rule ($self->rules) {
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm Tue Nov 18 19:06:57 2008
@@ -2,11 +2,12 @@
package Path::Dispatcher::Match;
use Moose;
+use Path::Dispatcher::Path;
use Path::Dispatcher::Rule;
has path => (
is => 'rw',
- isa => 'Str',
+ isa => 'Path::Dispatcher::Path',
required => 1,
);
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 Nov 18 19:06:57 2008
@@ -4,7 +4,7 @@
use Path::Dispatcher::Match;
-sub match_class { "Path::Dispatcher::Match" }
+use constant match_class => "Path::Dispatcher::Match";
has block => (
is => 'rw',
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Always.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Always.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Always.pm Tue Nov 18 19:06:57 2008
@@ -6,7 +6,7 @@
sub _match {
my $self = shift;
my $path = shift;
- return (1, $path);
+ return (1, $path->path);
}
__PACKAGE__->meta->make_immutable;
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm Tue Nov 18 19:06:57 2008
@@ -11,9 +11,10 @@
sub _match {
my $self = shift;
- local $_ = shift; # path
+ my $path = shift;
- return $self->matcher->($_);
+ local $_ = $path->path;
+ return $self->matcher->($path);
}
__PACKAGE__->meta->make_immutable;
@@ -54,7 +55,8 @@
A coderef that returns C<undef> if there's no match, otherwise a list of
strings (the results).
-The coderef receives the path as both its one argument and C<$_>.
+The coderef receives the path object as its argument, and the path string as
+C<$_>.
=cut
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Empty.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Empty.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Empty.pm Tue Nov 18 19:06:57 2008
@@ -6,8 +6,8 @@
sub _match {
my $self = shift;
my $path = shift;
- return 0 if length $path;
- return (1, $path);
+ return 0 if length $path->path;
+ return (1, $path->path);
}
__PACKAGE__->meta->make_immutable;
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Regex.pm Tue Nov 18 19:06:57 2008
@@ -13,7 +13,7 @@
my $self = shift;
my $path = shift;
- return unless $path =~ $self->regex;
+ return unless $path->path =~ $self->regex;
my @matches = map { substr($path, $-[$_], $+[$_] - $-[$_]) } 1 .. $#-;
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Tokens.pm Tue Nov 18 19:06:57 2008
@@ -52,7 +52,7 @@
my $self = shift;
my $path = shift;
- my @tokens = $self->tokenize($path);
+ my @tokens = $self->tokenize($path->path);
my @matched;
for my $expected ($self->tokens) {
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm Tue Nov 18 19:06:57 2008
@@ -35,8 +35,9 @@
or return;
my $suffix = $prefix_match->leftover;
+ my $new_path = $path->meta->clone_instance($path, path => $suffix);
- return grep { defined } map { $_->match($suffix) } $self->rules;
+ return grep { defined } map { $_->match($new_path) } $self->rules;
}
__PACKAGE__->meta->make_immutable;
More information about the Bps-public-commit
mailing list