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

sartak at bestpractical.com sartak at bestpractical.com
Tue Dec 30 14:22:00 EST 2008


Author: sartak
Date: Tue Dec 30 14:21:56 2008
New Revision: 17448

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

Log:
 r78066 at onn:  sartak | 2008-12-30 00:17:31 -0500
 Refactor cloning path objects but changing the path inside it into $path->clone_path($new_path)


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Path.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Path.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Path.pm	Tue Dec 30 14:21:56 2008
@@ -32,6 +32,13 @@
     $self->$orig(@_);
 };
 
+sub clone_path {
+    my $self = shift;
+    my $path = shift;
+
+    return $self->meta->clone_instance($self, path => $path, @_);
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 

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 Dec 30 14:21:56 2008
@@ -21,8 +21,8 @@
     my $got = $path->get_metadata($self->field);
 
     # wow, offensive.. but powerful
-    my $faux_path = Path::Dispatcher::Path->new(path => $got);
-    return 0 unless $self->matcher->match($faux_path);
+    my $metadata_path = $path->clone_path($got);
+    return 0 unless $self->matcher->match($metadata_path);
 
     return 1, $path->path;
 }

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Under.pm	Tue Dec 30 14:21:56 2008
@@ -23,8 +23,7 @@
     my $prefix_match = $self->predicate->match($path)
         or return;
 
-    my $suffix = $prefix_match->leftover;
-    my $new_path = $path->meta->clone_instance($path, path => $suffix);
+    my $new_path = $path->clone_path($prefix_match->leftover);
 
     return grep { defined } map { $_->match($new_path) } $self->rules;
 }



More information about the Bps-public-commit mailing list