[Bps-public-commit] Path-Dispatcher branch, named_captures, updated. 293783a9b46025707533ca785e0356f157b46ad2

Shawn Moore sartak at bestpractical.com
Thu Jun 24 15:33:11 EDT 2010


The branch, named_captures has been updated
       via  293783a9b46025707533ca785e0356f157b46ad2 (commit)
      from  62822641333e685e3534102653d80dcc95e1438e (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule.pm              |   17 +++++++----------
 lib/Path/Dispatcher/Rule/Alternation.pm  |    6 +++---
 lib/Path/Dispatcher/Rule/Always.pm       |    2 +-
 lib/Path/Dispatcher/Rule/Empty.pm        |    4 ++--
 lib/Path/Dispatcher/Rule/Enum.pm         |    4 ++--
 lib/Path/Dispatcher/Rule/Eq.pm           |    6 ++++--
 lib/Path/Dispatcher/Rule/Intersection.pm |    6 +++---
 lib/Path/Dispatcher/Rule/Metadata.pm     |    6 ++++--
 lib/Path/Dispatcher/Rule/Regex.pm        |    9 +++------
 lib/Path/Dispatcher/Rule/Sequence.pm     |    3 ++-
 lib/Path/Dispatcher/Rule/Tokens.pm       |    3 ++-
 11 files changed, 33 insertions(+), 33 deletions(-)

- Log -----------------------------------------------------------------
commit 293783a9b46025707533ca785e0356f157b46ad2
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Jun 24 15:34:17 2010 -0400

    Require return value from _match to be a hashref or not

diff --git a/lib/Path/Dispatcher/Rule.pm b/lib/Path/Dispatcher/Rule.pm
index 4eab217..1d7b366 100644
--- a/lib/Path/Dispatcher/Rule.pm
+++ b/lib/Path/Dispatcher/Rule.pm
@@ -27,28 +27,25 @@ sub match {
     my $self = shift;
     my $path = shift;
 
-    my ($result, $leftover);
+    my $result;
 
     if ($self->prefix) {
-        ($result, $leftover) = $self->_prefix_match($path);
+        $result = $self->_prefix_match($path);
     }
     else {
-        ($result, $leftover) = $self->_match($path);
+        $result = $self->_match($path);
     }
 
     if (!$result) {
-        $self->trace(leftover => $leftover, match => undef, path => $path)
+        $self->trace(match => undef, path => $path, %$result)
             if $ENV{'PATH_DISPATCHER_TRACE'};
         return;
     }
 
-    $leftover = '' if !defined($leftover);
-
     my $match = $self->match_class->new(
-        path     => $path,
-        rule     => $self,
-        leftover => $leftover,
-        (ref $result eq 'HASH') ? %$result : (),
+        path => $path,
+        rule => $self,
+        %$result,
     );
 
     $self->trace(match => $match) if $ENV{'PATH_DISPATCHER_TRACE'};
diff --git a/lib/Path/Dispatcher/Rule/Alternation.pm b/lib/Path/Dispatcher/Rule/Alternation.pm
index d329a82..b58d01d 100644
--- a/lib/Path/Dispatcher/Rule/Alternation.pm
+++ b/lib/Path/Dispatcher/Rule/Alternation.pm
@@ -9,13 +9,13 @@ sub _match {
     my $path = shift;
 
     my @rules = $self->rules;
-    return 0 if @rules == 0;
+    return if @rules == 0;
 
     for my $rule (@rules) {
-        return 1 if $rule->match($path);
+        return {} if $rule->match($path);
     }
 
-    return 0;
+    return;
 }
 
 sub complete {
diff --git a/lib/Path/Dispatcher/Rule/Always.pm b/lib/Path/Dispatcher/Rule/Always.pm
index 8828f9e..c53f374 100644
--- a/lib/Path/Dispatcher/Rule/Always.pm
+++ b/lib/Path/Dispatcher/Rule/Always.pm
@@ -5,7 +5,7 @@ extends 'Path::Dispatcher::Rule';
 sub _match {
     my $self = shift;
     my $path = shift;
-    return (1, $path->path);
+    return { leftover => $path->path };
 }
 
 __PACKAGE__->meta->make_immutable;
diff --git a/lib/Path/Dispatcher/Rule/Empty.pm b/lib/Path/Dispatcher/Rule/Empty.pm
index a026139..30a9020 100644
--- a/lib/Path/Dispatcher/Rule/Empty.pm
+++ b/lib/Path/Dispatcher/Rule/Empty.pm
@@ -5,8 +5,8 @@ extends 'Path::Dispatcher::Rule';
 sub _match {
     my $self = shift;
     my $path = shift;
-    return 0 if length $path->path;
-    return (1, $path->path);
+    return if length $path->path;
+    return { leftover => $path->path };
 }
 
 __PACKAGE__->meta->make_immutable;
diff --git a/lib/Path/Dispatcher/Rule/Enum.pm b/lib/Path/Dispatcher/Rule/Enum.pm
index e88dc09..870187f 100644
--- a/lib/Path/Dispatcher/Rule/Enum.pm
+++ b/lib/Path/Dispatcher/Rule/Enum.pm
@@ -20,12 +20,12 @@ sub _match {
 
     if ($self->case_sensitive) {
         for my $value (@{ $self->enum }) {
-            return 1 if $path->path eq $value;
+            return {} if $path->path eq $value;
         }
     }
     else {
         for my $value (@{ $self->enum }) {
-            return 1 if lc($path->path) eq lc($value);
+            return {} if lc($path->path) eq lc($value);
         }
     }
 }
diff --git a/lib/Path/Dispatcher/Rule/Eq.pm b/lib/Path/Dispatcher/Rule/Eq.pm
index 96870d4..a7170d1 100644
--- a/lib/Path/Dispatcher/Rule/Eq.pm
+++ b/lib/Path/Dispatcher/Rule/Eq.pm
@@ -19,11 +19,13 @@ sub _match {
     my $path = shift;
 
     if ($self->case_sensitive) {
-        return $path->path eq $self->string;
+        return {} if $path->path eq $self->string;
     }
     else {
-        return lc($path->path) eq lc($self->string);
+        return {} if lc($path->path) eq lc($self->string);
     }
+
+    return;
 }
 
 sub _prefix_match {
diff --git a/lib/Path/Dispatcher/Rule/Intersection.pm b/lib/Path/Dispatcher/Rule/Intersection.pm
index a1f6a99..29e82fc 100644
--- a/lib/Path/Dispatcher/Rule/Intersection.pm
+++ b/lib/Path/Dispatcher/Rule/Intersection.pm
@@ -9,13 +9,13 @@ sub _match {
     my $path = shift;
 
     my @rules = $self->rules;
-    return 0 if @rules == 0;
+    return if @rules == 0;
 
     for my $rule (@rules) {
-        return 0 unless $rule->match($path);
+        return unless $rule->match($path);
     }
 
-    return 1;
+    return {};
 }
 
 __PACKAGE__->meta->make_immutable;
diff --git a/lib/Path/Dispatcher/Rule/Metadata.pm b/lib/Path/Dispatcher/Rule/Metadata.pm
index 357ceff..e25b47b 100644
--- a/lib/Path/Dispatcher/Rule/Metadata.pm
+++ b/lib/Path/Dispatcher/Rule/Metadata.pm
@@ -21,9 +21,11 @@ sub _match {
 
     # wow, offensive.. but powerful
     my $metadata_path = $path->clone_path($got);
-    return 0 unless $self->matcher->match($metadata_path);
+    return unless $self->matcher->match($metadata_path);
 
-    return 1, $path->path;
+    return {
+        leftover => $path->path,
+    };
 }
 
 sub readable_attributes {
diff --git a/lib/Path/Dispatcher/Rule/Regex.pm b/lib/Path/Dispatcher/Rule/Regex.pm
index 77bdd43..c73ffed 100644
--- a/lib/Path/Dispatcher/Rule/Regex.pm
+++ b/lib/Path/Dispatcher/Rule/Regex.pm
@@ -14,17 +14,14 @@ sub _match {
 
     return unless my @matches = $path->path =~ $self->regex;
 
+    # if $' is in the program at all, then it slows down every single regex
+    # we only want to include it if we have to
     my $results = {
         positional_captures => \@matches,
         named_captures      => \%+,
+        ($self->prefix ? (leftover => eval q{$'}) : ()),
     };
 
-    # if $' is in the program at all, then it slows down every single regex
-    # we only want to include it if we have to
-    if ($self->prefix) {
-        return $results, eval q{$'};
-    }
-
     return $results;
 }
 
diff --git a/lib/Path/Dispatcher/Rule/Sequence.pm b/lib/Path/Dispatcher/Rule/Sequence.pm
index df6c279..a8771f7 100644
--- a/lib/Path/Dispatcher/Rule/Sequence.pm
+++ b/lib/Path/Dispatcher/Rule/Sequence.pm
@@ -44,7 +44,8 @@ sub _match {
     my $leftover = $self->untokenize(@$tokens);
     return {
         positional_captures => $matched,
-    }, $leftover;
+        leftover => $leftover,
+    };
 }
 
 sub complete {
diff --git a/lib/Path/Dispatcher/Rule/Tokens.pm b/lib/Path/Dispatcher/Rule/Tokens.pm
index 8bbb090..ad98c13 100644
--- a/lib/Path/Dispatcher/Rule/Tokens.pm
+++ b/lib/Path/Dispatcher/Rule/Tokens.pm
@@ -55,7 +55,8 @@ sub _match {
     my $leftover = $self->untokenize(@$got);
     return {
         positional_captures => $matched,
-    }, $leftover;
+        leftover => $leftover,
+    };
 }
 
 sub complete {

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



More information about the Bps-public-commit mailing list