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

Shawn Moore sartak at bestpractical.com
Wed Jun 23 10:59:31 EDT 2010


The branch, master has been updated
       via  93548a3de60ff0ce42a22c31d48669762c901b12 (commit)
      from  e0bc61977f0364ce4191597bba6a65805388c5af (commit)

Summary of changes:
 lib/Path/Dispatcher/Match.pm |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit 93548a3de60ff0ce42a22c31d48669762c901b12
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Jun 23 11:00:02 2010 -0400

    Use glob assignment instead of regex matching for populating $1 etc
    
        chromatic++

diff --git a/lib/Path/Dispatcher/Match.pm b/lib/Path/Dispatcher/Match.pm
index 3552d64..af1e3de 100644
--- a/lib/Path/Dispatcher/Match.pm
+++ b/lib/Path/Dispatcher/Match.pm
@@ -52,20 +52,11 @@ 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 { defined($_) ? "(\Q$_\E)" : "(wontmatch)?" } @_;
-    my $str = join '', map { defined($_) ? $_         : ""             } @_;
-
-    # we need to check length because Perl's annoying gotcha of the empty regex
-    # actually being an alias for whatever the previously used regex was
-    # (useful last decade when qr// hadn't been invented)
-    # we need to do the match anyway, because we have to clear the number vars
-    ($str, $re) = ("x", "x") if length($str) == 0;
-
-    $str =~ qr{^$re$}
-        or die "Unable to match '$str' against a copy of itself ($re)!";
+    # populate $1, $2, etc for the duration of $code
+    # it'd be nice if we could use "local" but it seems to break tests
+    my $i = 0;
+    no strict 'refs';
+    *{ ++$i } = \$_ for @_;
 
     $code->();
 }

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



More information about the Bps-public-commit mailing list