[Bps-public-commit] r14896 - in Path-Dispatcher/trunk: lib/Path/Dispatcher lib/Path/Dispatcher/Dispatch

sartak at bestpractical.com sartak at bestpractical.com
Thu Aug 7 13:50:43 EDT 2008


Author: sartak
Date: Thu Aug  7 13:50:43 2008
New Revision: 14896

Modified:
   Path-Dispatcher/trunk/   (props changed)
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch.pm
   Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm

Log:
 r68940 at onn:  sartak | 2008-08-07 13:50:39 -0400
 Move the "invoke match" logic into match where it belongs (and now can be subclassed to do interesting things)


Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch.pm	Thu Aug  7 13:50:43 2008
@@ -49,16 +49,7 @@
     eval {
         local $SIG{__DIE__} = 'DEFAULT';
         for my $match ($self->matches) {
-            # if we need to set $1, $2..
-            if ($match->set_number_vars) {
-                $self->run_with_number_vars(
-                    sub { $match->rule->run(@args) },
-                    @{ $match->result },
-                );
-            }
-            else {
-                $match->rule->run(@args);
-            }
+            $match->run(@args);
         }
     };
 
@@ -67,21 +58,6 @@
     return;
 }
 
-sub run_with_number_vars {
-    my $self = shift;
-    my $code = shift;
-
-    # we don't have direct write access to $1 and friends, so we have to
-    # do this little hack. the only way we can update $1 is by matching
-    # against a regex (5.10 fixes that)..
-    my $re = join '', map { "(\Q$_\E)" } @_;
-    my $str = join '', @_;
-    $str =~ $re
-        or die "Unable to match '$str' against a copy of itself!";
-
-    $code->();
-}
-
 __PACKAGE__->meta->make_immutable;
 no Moose;
 

Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm	(original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Dispatch/Match.pm	Thu Aug  7 13:50:43 2008
@@ -25,6 +25,36 @@
     default => sub { ref(shift->result) eq 'ARRAY' },
 );
 
+sub run {
+    my $self = shift;
+    my @args = @_;
+
+    if ($self->set_number_vars) {
+        $self->run_with_number_vars(
+            sub { $self->rule->run(@args) },
+            @{ $self->result },
+        );
+    }
+    else {
+        $self->rule->run(@args);
+    }
+}
+
+sub run_with_number_vars {
+    my $self = shift;
+    my $code = shift;
+
+    # we don't have direct write access to $1 and friends, so we have to
+    # do this little hack. the only way we can update $1 is by matching
+    # against a regex (5.10 fixes that)..
+    my $re = join '', map { "(\Q$_\E)" } @_;
+    my $str = join '', @_;
+    $str =~ $re
+        or die "Unable to match '$str' against a copy of itself!";
+
+    $code->();
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 



More information about the Bps-public-commit mailing list