[Bps-public-commit] Path-Dispatcher branch, complete, updated. 7f325bba3846f379138a66b0efdab83aef21082a
sartak at bestpractical.com
sartak at bestpractical.com
Fri Dec 18 18:52:23 EST 2009
The branch, complete has been updated
via 7f325bba3846f379138a66b0efdab83aef21082a (commit)
via e5537d5c688960cbb2bb64f284e52d4beb6020c3 (commit)
via b413c7b90bdfd20fc0d434e1a8f041251d1ebfad (commit)
via 73651995cc01ec487269df30df6a8d068e8ac4d1 (commit)
via 8d755313db504b46fc06c61966b7a5ea58ae85a0 (commit)
from d9822a3ca5065679dab760f0fedb686d4996e2e4 (commit)
Summary of changes:
lib/Path/Dispatcher/Rule/Tokens.pm | 64 +++++++++++++++++++++--------------
t/300-complete-simple.t | 6 ++--
2 files changed, 41 insertions(+), 29 deletions(-)
- Log -----------------------------------------------------------------
commit 8d755313db504b46fc06c61966b7a5ea58ae85a0
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Dec 18 18:41:12 2009 -0500
Remove tracing from Tokens->_match for now
diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index 34c53ba..78d661f 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -30,20 +30,12 @@ sub _match {
for my $expected ($self->tokens) {
unless (@tokens) {
- $self->trace(no_tokens => 1, on_token => $expected, path => $path)
- if $ENV{'PATH_DISPATCHER_TRACE'};
return;
}
my $got = shift @tokens;
unless ($self->_match_token($got, $expected)) {
- $self->trace(
- no_match => 1,
- got_token => $got,
- on_token => $expected,
- path => $path,
- ) if $ENV{'PATH_DISPATCHER_TRACE'};
return;
}
@@ -51,8 +43,6 @@ sub _match {
}
if (@tokens && !$self->prefix) {
- $self->trace(tokens_left => \@tokens, path => $path)
- if $ENV{'PATH_DISPATCHER_TRACE'};
return;
}
commit 73651995cc01ec487269df30df6a8d068e8ac4d1
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Dec 18 18:42:47 2009 -0500
Ease refactoring
diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index 78d661f..31f77ca 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -26,9 +26,10 @@ sub _match {
my $path = shift;
my @tokens = $self->tokenize($path->path);
+ my @expected = $self->tokens;
my @matched;
- for my $expected ($self->tokens) {
+ while (defined(my $expected = shift @expected)) {
unless (@tokens) {
return;
}
commit b413c7b90bdfd20fc0d434e1a8f041251d1ebfad
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Dec 18 18:47:46 2009 -0500
Refactor _match so complete will be able to reuse its logic
diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index 31f77ca..8bbc8dd 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -21,34 +21,39 @@ has case_sensitive => (
default => 1,
);
-sub _match {
+sub _match_as_far_as_possible {
my $self = shift;
my $path = shift;
- my @tokens = $self->tokenize($path->path);
+ my @got = $self->tokenize($path->path);
my @expected = $self->tokens;
my @matched;
- while (defined(my $expected = shift @expected)) {
- unless (@tokens) {
- return;
- }
-
- my $got = shift @tokens;
+ while (@got && @expected) {
+ my $expected = $expected[0];
+ my $got = $got[0];
- unless ($self->_match_token($got, $expected)) {
- return;
- }
+ last unless $self->_match_token($got, $expected);
push @matched, $got;
+ shift @expected;
+ shift @got;
}
- if (@tokens && !$self->prefix) {
- return;
- }
+ return (\@matched, \@got, \@expected);
+}
+
+sub _match {
+ my $self = shift;
+ my $path = shift;
+
+ my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path);
+
+ return if @$expected; # didn't provide everything necessary
+ return if @$got && !$self->prefix; # had tokens left over
- my $leftover = $self->untokenize(@tokens);
- return \@matched, $leftover;
+ my $leftover = $self->untokenize(@$got);
+ return $matched, $leftover;
}
sub _each_token {
commit e5537d5c688960cbb2bb64f284e52d4beb6020c3
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Dec 18 18:51:16 2009 -0500
A complete method for Tokens
diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index 8bbc8dd..8096005 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -56,6 +56,22 @@ sub _match {
return $matched, $leftover;
}
+sub complete {
+ my $self = shift;
+ my $path = shift;
+
+ my ($matched, $got, $expected) = $self->_match_as_far_as_possible($path);
+ return if @$got > 1; # had tokens leftover
+ return if !@$expected; # consumed all tokens
+
+ my $next = shift @$expected;
+ return if ref($next); # we can only deal with strings
+
+ my $part = @$got ? shift @$got : '';
+ return unless substr($next, 0, length($part)) eq $part;
+ return $next;
+}
+
sub _each_token {
my $self = shift;
my $got = shift;
commit 7f325bba3846f379138a66b0efdab83aef21082a
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Dec 18 18:52:04 2009 -0500
Complete paths should not return themselves
diff --git a/t/300-complete-simple.t b/t/300-complete-simple.t
index cb5c512..4354f19 100644
--- a/t/300-complete-simple.t
+++ b/t/300-complete-simple.t
@@ -29,10 +29,10 @@ is_deeply([$dispatcher->complete('baq')], [], 'no completions for "baq"');
is_deeply([$dispatcher->complete('f')], ['foo'], 'one completion for "f"');
is_deeply([$dispatcher->complete('fo')], ['foo'], 'one completion for "fo"');
-is_deeply([$dispatcher->complete('foo')], ['foo'], 'one completion for "foo"');
+is_deeply([$dispatcher->complete('foo')], [], '"foo" is already complete');
is_deeply([$dispatcher->complete('b')], ['bar', 'baz'], 'two completions for "b"');
is_deeply([$dispatcher->complete('ba')], ['bar', 'baz'], 'two completions for "ba"');
-is_deeply([$dispatcher->complete('bar')], ['bar'], 'one completion for "bar"');
-is_deeply([$dispatcher->complete('baz')], ['baz'], 'one completion for "baz"');
+is_deeply([$dispatcher->complete('bar')], [], '"bar" is already complete');
+is_deeply([$dispatcher->complete('baz')], [], '"baz" is already complete');
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list