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

sartak at bestpractical.com sartak at bestpractical.com
Fri Dec 18 18:00:33 EST 2009


The branch, complete has been updated
       via  b4b9b274486eb400b834aba38d7eaa143e79d0d7 (commit)
      from  6a50803ebdafabecafee609d8af38e53cf13d9a2 (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule.pm    |   14 +++++++++++++-
 lib/Path/Dispatcher/Rule/Eq.pm |    7 ++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit b4b9b274486eb400b834aba38d7eaa143e79d0d7
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Dec 18 17:59:54 2009 -0500

    Refactor _prefix_match out to let rules simplify their match logic

diff --git a/lib/Path/Dispatcher/Rule.pm b/lib/Path/Dispatcher/Rule.pm
index dc8e3a4..1dbafd4 100644
--- a/lib/Path/Dispatcher/Rule.pm
+++ b/lib/Path/Dispatcher/Rule.pm
@@ -27,7 +27,14 @@ sub match {
     my $self = shift;
     my $path = shift;
 
-    my ($result, $leftover) = $self->_match($path);
+    my ($result, $leftover);
+
+    if ($self->prefix) {
+        ($result, $leftover) = $self->_prefix_match($path);
+    }
+    else {
+        ($result, $leftover) = $self->_match($path);
+    }
 
     if (!$result) {
         $self->trace(leftover => $leftover, match => undef, path => $path)
@@ -60,6 +67,11 @@ sub match {
     return $match;
 }
 
+sub _prefix_match {
+    my $self = shift;
+    return $self->_match(@_);
+}
+
 sub run {
     my $self = shift;
 
diff --git a/lib/Path/Dispatcher/Rule/Eq.pm b/lib/Path/Dispatcher/Rule/Eq.pm
index 684a7e7..0a9425e 100644
--- a/lib/Path/Dispatcher/Rule/Eq.pm
+++ b/lib/Path/Dispatcher/Rule/Eq.pm
@@ -12,7 +12,12 @@ sub _match {
     my $self = shift;
     my $path = shift;
 
-    return $path->path eq $self->string unless $self->prefix;
+    return $path->path eq $self->string;
+}
+
+sub _prefix_match {
+    my $self = shift;
+    my $path = shift;
 
     my $truncated = substr($path->path, 0, length($self->string));
     return 0 unless $truncated eq $self->string;

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



More information about the Bps-public-commit mailing list