[Bps-public-commit] Path-Dispatcher branch, master, updated. 69b918a02b9931e93d82b1f1f5a460bc282ea856

sartak at bestpractical.com sartak at bestpractical.com
Wed Jan 6 19:58:37 EST 2010


The branch, master has been updated
       via  69b918a02b9931e93d82b1f1f5a460bc282ea856 (commit)
      from  7fd79d2487d93bc880f76789abd06a6e935f0d74 (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule/Sequence.pm |   14 ++++++++++++++
 t/024-sequence.t                     |    7 ++++++-
 2 files changed, 20 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 69b918a02b9931e93d82b1f1f5a460bc282ea856
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Jan 6 19:58:27 2010 -0500

    Some better error checking. Not very happy with this yet.

diff --git a/lib/Path/Dispatcher/Rule/Sequence.pm b/lib/Path/Dispatcher/Rule/Sequence.pm
index 1c800de..209eaae 100644
--- a/lib/Path/Dispatcher/Rule/Sequence.pm
+++ b/lib/Path/Dispatcher/Rule/Sequence.pm
@@ -11,6 +11,20 @@ has delimiter => (
     default => ' ',
 );
 
+sub BUILD {
+    my $self = shift;
+    my @rules = $self->rules;
+
+    # the last rule only needs to be prefix if this entire sequence is prefix
+    if (!$self->prefix) {
+        pop @rules;
+    }
+
+    for (@rules) {
+        $_->prefix or confess "$_ is not prefix. Better diagnostics forthcoming.";
+    }
+}
+
 sub _match {
     my $self = shift;
     my $path = shift;
diff --git a/t/024-sequence.t b/t/024-sequence.t
index 777bc02..200e5ed 100644
--- a/t/024-sequence.t
+++ b/t/024-sequence.t
@@ -64,12 +64,13 @@ $dispatcher->add_rule(
                         prefix => 1,
                     ),
                 ],
+                prefix => 1,
             ),
             Path::Dispatcher::Rule::Eq->new(
                 string => 'Man',
             ),
         ],
-        block  => sub { push @calls, [$1, $2, $3] },
+        block => sub { push @calls, [$1, $2, $3] },
     ),
 );
 
@@ -86,13 +87,17 @@ $dispatcher->add_rule(
     Path::Dispatcher::Rule::Sequence->new(
         rules => [
             Path::Dispatcher::Rule::Alternation->new(
+                prefix => 1,
                 rules => [
                     Path::Dispatcher::Rule::Alternation->new(
+                        prefix => 1,
                         rules => [
                             Path::Dispatcher::Rule::Alternation->new(
+                                prefix => 1,
                                 rules => [
                                     Path::Dispatcher::Rule::Regex->new(
                                         regex => qr/Deep/,
+                                        prefix => 1,
                                     ),
                                 ],
                             ),

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



More information about the Bps-public-commit mailing list