[Bps-public-commit] Path-Dispatcher branch, master, updated. 659662cdb2cf8a521412d920115df738c4f56692

sartak at bestpractical.com sartak at bestpractical.com
Tue Mar 16 09:57:12 EDT 2010


The branch, master has been updated
       via  659662cdb2cf8a521412d920115df738c4f56692 (commit)
       via  6de40f9aa5bacb805f16ee7ee87e920e477d5753 (commit)
      from  dca863ee8b9fa7507c6b7f3f6517a79bbbce0973 (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule/Alternation.pm |    6 ++++++
 lib/Path/Dispatcher/Rule/Eq.pm          |    4 ++++
 t/023-alternation.t                     |   12 +++++++++++-
 3 files changed, 21 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 6de40f9aa5bacb805f16ee7ee87e920e477d5753
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 16 09:56:51 2010 -0400

    Fix Eq's handling of complete with an already-complete path

diff --git a/lib/Path/Dispatcher/Rule/Eq.pm b/lib/Path/Dispatcher/Rule/Eq.pm
index 5818ea7..96870d4 100644
--- a/lib/Path/Dispatcher/Rule/Eq.pm
+++ b/lib/Path/Dispatcher/Rule/Eq.pm
@@ -47,6 +47,10 @@ sub complete {
     my $path = shift->path;
     my $completed = $self->string;
 
+    # by convention, complete does include the path itself if it
+    # is a complete match
+    return if length($path) >= length($completed);
+
     my $partial = substr($completed, 0, length($path));
     if ($self->case_sensitive) {
         return unless $partial eq $path;

commit 659662cdb2cf8a521412d920115df738c4f56692
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 16 09:57:05 2010 -0400

    Completion for Alternation rules

diff --git a/lib/Path/Dispatcher/Rule/Alternation.pm b/lib/Path/Dispatcher/Rule/Alternation.pm
index 1135359..d329a82 100644
--- a/lib/Path/Dispatcher/Rule/Alternation.pm
+++ b/lib/Path/Dispatcher/Rule/Alternation.pm
@@ -18,6 +18,12 @@ sub _match {
     return 0;
 }
 
+sub complete {
+    my $self = shift;
+
+    return map { $_->complete(@_) } $self->rules;
+}
+
 __PACKAGE__->meta->make_immutable;
 no Any::Moose;
 
diff --git a/t/023-alternation.t b/t/023-alternation.t
index d75059e..78ebd37 100644
--- a/t/023-alternation.t
+++ b/t/023-alternation.t
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 4;
+use Test::More tests => 13;
 use Path::Dispatcher;
 
 my @calls;
@@ -33,6 +33,16 @@ is_deeply([splice @calls], ['alternation'], "the alternation matched; doesn't au
 $dispatcher->run("baz");
 is_deeply([splice @calls], [], "each subrule of the intersection must match");
 
+is_deeply([$dispatcher->complete("")], ["foo", "bar"]);
+is_deeply([$dispatcher->complete("f")], ["foo"]);
+is_deeply([$dispatcher->complete("b")], ["bar"]);
+is_deeply([$dispatcher->complete("fo")], ["foo"]);
+is_deeply([$dispatcher->complete("ba")], ["bar"]);
+is_deeply([$dispatcher->complete("foo")], []);
+is_deeply([$dispatcher->complete("bar")], []);
+is_deeply([$dispatcher->complete("fx")], []);
+is_deeply([$dispatcher->complete("baz")], []);
+
 # test empty alternation
 $dispatcher = Path::Dispatcher->new(
     rules => [

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list