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

sartak at bestpractical.com sartak at bestpractical.com
Tue Dec 30 14:20:16 EST 2008


Author: sartak
Date: Tue Dec 30 14:20:15 2008
New Revision: 17438

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Path.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
   Path-Dispatcher/trunk/t/007-coderef-matcher.t

Log:
 r78056 at onn:  sartak | 2008-12-29 23:33:18 -0500
 Stringify Path::Dispatcher::Path into the path, so that wise users can call methods on it to get metadata etc


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Match.pm	Tue Dec 30 14:20:15 2008
@@ -45,7 +45,7 @@
     my $self = shift;
     my @args = @_;
 
-    local $_ = $self->path->path;
+    local $_ = $self->path;
 
     if ($self->set_number_vars) {
         return $self->run_with_number_vars(

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:20:15 2008
@@ -3,6 +3,8 @@
 use Moose;
 use MooseX::AttributeHelpers;
 
+use overload q{""} => sub { shift->path };
+
 has path => (
     is        => 'rw',
     isa       => 'Str',

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm	Tue Dec 30 14:20:15 2008
@@ -81,7 +81,7 @@
            && $level < $args{level};
 
     my $match = $args{match};
-    my $path  = $match ? $match->path->path : $args{path}->path;
+    my $path  = $match ? $match->path : $args{path};
 
     # name
     my $trace = '';

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/CodeRef.pm	Tue Dec 30 14:20:15 2008
@@ -13,7 +13,7 @@
     my $self = shift;
     my $path = shift;
 
-    local $_ = $path->path;
+    local $_ = $path;
     return $self->matcher->($path);
 }
 

Modified: Path-Dispatcher/trunk/t/007-coderef-matcher.t
==============================================================================
--- Path-Dispatcher/trunk/t/007-coderef-matcher.t	(original)
+++ Path-Dispatcher/trunk/t/007-coderef-matcher.t	Tue Dec 30 14:20:15 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
 use Path::Dispatcher;
 
 my (@matches, @calls);
@@ -19,3 +19,6 @@
 is_deeply([splice @matches], ['foobar']);
 is_deeply([splice @calls], [ [] ]);
 
+$dispatcher->run('other');
+is($matches[0]->path, 'other');
+



More information about the Bps-public-commit mailing list