[Bps-public-commit] r16921 - in Path-Dispatcher/trunk: lib/Path/Dispatcher/Rule t

sartak at bestpractical.com sartak at bestpractical.com
Tue Nov 18 20:08:14 EST 2008


Author: sartak
Date: Tue Nov 18 20:08:14 2008
New Revision: 16921

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm
   Path-Dispatcher/trunk/t/018-metadata.t

Log:
 r75793 at onn:  sartak | 2008-11-18 20:08:11 -0500
 Refactor Metadata to take a rule for matching the metadata


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Metadata.pm	Tue Nov 18 20:08:14 2008
@@ -10,9 +10,9 @@
     required => 1,
 );
 
-has value => (
+has matcher => (
     is       => 'rw',
-    isa      => 'Str',
+    isa      => 'Path::Dispatcher::Rule',
     required => 1,
 );
 
@@ -21,7 +21,9 @@
     my $path = shift;
     my $got = $path->get_metadata($self->name);
 
-    return 0 if $self->value ne $got;
+    # wow, offensive.. but powerful
+    my $faux_path = Path::Dispatcher::Path->new(path => $got);
+    return 0 unless $self->matcher->match($faux_path);
 
     return 1, $path->path;
 }

Modified: Path-Dispatcher/trunk/t/018-metadata.t
==============================================================================
--- Path-Dispatcher/trunk/t/018-metadata.t	(original)
+++ Path-Dispatcher/trunk/t/018-metadata.t	Tue Nov 18 20:08:14 2008
@@ -9,9 +9,9 @@
 my $dispatcher = Path::Dispatcher->new(
     rules => [
         Path::Dispatcher::Rule::Metadata->new(
-            name  => "http_method",
-            value => "GET",
-            block => sub { push @calls, $_ },
+            name    => "http_method",
+            matcher => Path::Dispatcher::Rule::Eq->new(string => "GET"),
+            block   => sub { push @calls, $_ },
         ),
     ],
 );



More information about the Bps-public-commit mailing list