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

sartak at bestpractical.com sartak at bestpractical.com
Wed Jan 6 19:53:40 EST 2010


The branch, master has been updated
       via  c91a2f93d6e247575483b0a2b9e15a447c9c5ab7 (commit)
      from  ffc53b70cf89ee96b64764e14c1e62e1888d24be (commit)

Summary of changes:
 lib/Path/Dispatcher/Rule/Eq.pm |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

- Log -----------------------------------------------------------------
commit c91a2f93d6e247575483b0a2b9e15a447c9c5ab7
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Jan 6 19:53:32 2010 -0500

    Case insensitivity for Eq rules

diff --git a/lib/Path/Dispatcher/Rule/Eq.pm b/lib/Path/Dispatcher/Rule/Eq.pm
index dd7138a..41d2c97 100644
--- a/lib/Path/Dispatcher/Rule/Eq.pm
+++ b/lib/Path/Dispatcher/Rule/Eq.pm
@@ -8,11 +8,22 @@ has string => (
     required => 1,
 );
 
+has case_sensitive => (
+    is      => 'rw',
+    isa     => 'Bool',
+    default => 1,
+);
+
 sub _match {
     my $self = shift;
     my $path = shift;
 
-    return $path->path eq $self->string;
+    if ($self->case_sensitive) {
+        return $path->path eq $self->string;
+    }
+    else {
+        return lc($path->path) eq lc($self->string);
+    }
 }
 
 sub _prefix_match {
@@ -20,7 +31,13 @@ sub _prefix_match {
     my $path = shift;
 
     my $truncated = substr($path->path, 0, length($self->string));
-    return 0 unless $truncated eq $self->string;
+
+    if ($self->case_sensitive) {
+        return 0 unless $truncated eq $self->string;
+    }
+    else {
+        return 0 unless lc($truncated) eq lc($self->string);
+    }
 
     return (1, substr($path->path, length($self->string)));
 }
@@ -30,7 +47,14 @@ sub complete {
     my $path = shift->path;
     my $completed = $self->string;
 
-    return unless substr($completed, 0, length($path)) eq $path;
+    my $partial = substr($completed, 0, length($path));
+    if ($self->case_sensitive) {
+        return unless $partial eq $path;
+    }
+    else {
+        return unless lc($partial) eq lc($path);
+    }
+
     return $completed;
 }
 

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



More information about the Bps-public-commit mailing list