[Bps-public-commit] Path-Dispatcher branch, complete, updated. 7f66ddf66a1d3a0f4908d96a9a4d5669db2788ea

sartak at bestpractical.com sartak at bestpractical.com
Fri Dec 18 19:05:47 EST 2009


The branch, complete has been updated
       via  7f66ddf66a1d3a0f4908d96a9a4d5669db2788ea (commit)
       via  d3c829adb17dc791e379ec829f76d608c7497b81 (commit)
      from  61d055f4b1ca9f6d32bc1ce90592d641b2ef30f7 (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule/Under.pm |   14 ++++++++++++++
 t/301-complete-complex.t          |   14 +++++++++++++-
 2 files changed, 27 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit d3c829adb17dc791e379ec829f76d608c7497b81
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Dec 18 19:05:37 2009 -0500

    More tests

diff --git a/t/301-complete-complex.t b/t/301-complete-complex.t
index 50ef538..641b526 100644
--- a/t/301-complete-complex.t
+++ b/t/301-complete-complex.t
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 6;
+use Test::More tests => 12;
 
 do {
     package MyApp::Dispatcher;
@@ -22,6 +22,11 @@ do {
         on two => sub { die "do not call blocks!" };
         on three => sub { die "do not call blocks!" };
     };
+
+    under beta => sub {
+        on a => sub { die "do not call blocks!" };
+        on b => sub { die "do not call blocks!" };
+    };
 };
 
 my $dispatcher = MyApp::Dispatcher->dispatcher;
@@ -30,6 +35,13 @@ is_deeply([$dispatcher->complete('a')], ['alpha'], 'one completion for "a"');
 is_deeply([$dispatcher->complete('alpha')], ['one', 'two', 'three'], 'three completions for "alpha"');
 is_deeply([$dispatcher->complete('q')], ['quux'], 'one completion for "quux"');
 
+is_deeply([$dispatcher->complete('bet')], ['beta'], 'one completion for "beta"');
+is_deeply([$dispatcher->complete('beta')], ['beta a', 'beta b'], 'two completions for "beta"');
+is_deeply([$dispatcher->complete('beta ')], ['beta a', 'beta b'], 'two completions for "beta "');
+is_deeply([$dispatcher->complete('beta a')], [], 'no completions for "beta a"');
+is_deeply([$dispatcher->complete('beta b')], [], 'no completions for "beta b"');
+is_deeply([$dispatcher->complete('beta c')], [], 'no completions for "beta c"');
+
 TODO: {
     local $TODO = "cannot complete regex rules (yet!)";
     is_deeply([$dispatcher->complete('quux')], ['quux-'], 'one completion for "quux"');

commit 7f66ddf66a1d3a0f4908d96a9a4d5669db2788ea
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Dec 18 19:05:41 2009 -0500

    complete for Under rules

diff --git a/lib/Path/Dispatcher/Rule/Under.pm b/lib/Path/Dispatcher/Rule/Under.pm
index ce2996e..eb31198 100644
--- a/lib/Path/Dispatcher/Rule/Under.pm
+++ b/lib/Path/Dispatcher/Rule/Under.pm
@@ -37,6 +37,20 @@ sub match {
     return @matches;
 }
 
+sub complete {
+    my $self = shift;
+    my $path = shift;
+
+    my $predicate = $self->predicate;
+
+    my $prefix_match = $predicate->match($path)
+        or return $predicate->complete($path);
+
+    my $new_path = $path->clone_path($prefix_match->leftover);
+
+    return map { $_->complete($new_path) } $self->rules;
+}
+
 sub readable_attributes { shift->predicate->readable_attributes }
 
 __PACKAGE__->meta->make_immutable;

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



More information about the Bps-public-commit mailing list