[Bps-public-commit] Path-Dispatcher branch, master, updated. 663b35374ce5fe45786b504af97e134125d58d04
sartak at bestpractical.com
sartak at bestpractical.com
Tue Mar 16 09:05:43 EDT 2010
The branch, master has been updated
via 663b35374ce5fe45786b504af97e134125d58d04 (commit)
via 74fd5511730bbfc06e7a7c689419327b6322ef15 (commit)
via 5da49266b687ffe4c1bfa75792aab244daa40477 (commit)
from f53ef41293dbcd0eddcba3794869a19701cf0f04 (commit)
Summary of changes:
lib/Path/Dispatcher/Builder.pm | 7 +++++++
lib/Path/Dispatcher/Declarative.pm | 1 +
lib/Path/Dispatcher/Rule/Enum.pm | 8 ++++++--
...-complete-alternation.t => 304-complete-enum.t} | 2 +-
4 files changed, 15 insertions(+), 3 deletions(-)
copy t/{303-complete-alternation.t => 304-complete-enum.t} (96%)
- Log -----------------------------------------------------------------
commit 5da49266b687ffe4c1bfa75792aab244daa40477
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Mar 16 09:02:45 2010 -0400
By convention, ->complete does not include the path itself
diff --git a/lib/Path/Dispatcher/Rule/Enum.pm b/lib/Path/Dispatcher/Rule/Enum.pm
index 5d483ac..341597d 100644
--- a/lib/Path/Dispatcher/Rule/Enum.pm
+++ b/lib/Path/Dispatcher/Rule/Enum.pm
@@ -55,14 +55,18 @@ sub complete {
my $path = shift->path;
my @completions;
+ # by convention, complete does include the path itself if it
+ # is a complete match
+ my @enum = grep { length($path) < length($_) } @{ $self->enum };
+
if ($self->case_sensitive) {
- for my $value (@{ $self->enum }) {
+ for my $value (@enum) {
my $partial = substr($value, 0, length($path));
push @completions, $value if $partial eq $path;
}
}
else {
- for my $value (@{ $self->enum }) {
+ for my $value (@enum) {
my $partial = substr($value, 0, length($path));
push @completions, $value if lc($partial) eq lc($path);
}
commit 74fd5511730bbfc06e7a7c689419327b6322ef15
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Mar 16 09:03:07 2010 -0400
Add enum sugar to Declarative
diff --git a/lib/Path/Dispatcher/Builder.pm b/lib/Path/Dispatcher/Builder.pm
index d5220d9..3ffdab3 100644
--- a/lib/Path/Dispatcher/Builder.pm
+++ b/lib/Path/Dispatcher/Builder.pm
@@ -76,6 +76,13 @@ sub on {
$self->_add_rule(@_);
}
+sub enum {
+ my $self = shift;
+ Path::Dispatcher::Rule::Enum->new(
+ enum => [@_],
+ );
+}
+
sub then {
my $self = shift;
my $block = shift;
diff --git a/lib/Path/Dispatcher/Declarative.pm b/lib/Path/Dispatcher/Declarative.pm
index 649932a..bf01e94 100644
--- a/lib/Path/Dispatcher/Declarative.pm
+++ b/lib/Path/Dispatcher/Declarative.pm
@@ -56,6 +56,7 @@ sub build_sugar {
on => sub { $builder->on(@_) },
under => sub { $builder->under(@_) },
redispatch_to => sub { $builder->redispatch_to(@_) },
+ enum => sub { $builder->enum(@_) },
next_rule => sub { $builder->next_rule(@_) },
last_rule => sub { $builder->last_rule(@_) },
complete => sub { $builder->complete(@_) },
commit 663b35374ce5fe45786b504af97e134125d58d04
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Mar 16 09:03:27 2010 -0400
Add tests for completing enums
diff --git a/t/304-complete-enum.t b/t/304-complete-enum.t
new file mode 100644
index 0000000..dddbf2e
--- /dev/null
+++ b/t/304-complete-enum.t
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 20;
+
+do {
+ package MyApp::Dispatcher;
+ use Path::Dispatcher::Declarative -base;
+
+ under gate => sub {
+ on enum('foo', 'bar', 'baz') => sub { die };
+ on quux => sub { die };
+ };
+};
+
+my $dispatcher = MyApp::Dispatcher->dispatcher;
+
+sub complete_ok {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my $path = shift;
+ my @expected = @_;
+
+ my @got = $dispatcher->complete($path);
+
+ my $message = @expected == 0 ? "no completions"
+ : @expected == 1 ? "one completion"
+ : @expected . " completions";
+ $message .= " for path '$path'";
+
+ is_deeply(\@got, \@expected, $message);
+}
+
+complete_ok('z');
+complete_ok('gate z');
+complete_ok('zig ');
+complete_ok('zig f');
+complete_ok('zig fo');
+complete_ok('zig foo');
+
+complete_ok(g => 'gate');
+complete_ok(ga => 'gate');
+complete_ok(gat => 'gate');
+
+complete_ok(gate => 'gate foo', 'gate bar', 'gate baz', 'gate quux');
+complete_ok('gate ' => 'gate foo', 'gate bar', 'gate baz', 'gate quux');
+
+complete_ok('gate f' => 'gate foo');
+
+complete_ok('gate b' => 'gate bar', 'gate baz');
+complete_ok('gate ba' => 'gate bar', 'gate baz');
+
+complete_ok('gate q' => 'gate quux');
+complete_ok('gate quu' => 'gate quux');
+
+complete_ok('gate foo');
+complete_ok('gate bar');
+complete_ok('gate baz');
+complete_ok('gate quux');
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list