Created
October 11, 2012 09:29
-
-
Save ktat/3871233 to your computer and use it in GitHub Desktop.
patch for regexp parentheses problem of Router::Simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Router/Simple/Route.pm b/lib/Router/Simple/Route.pm | |
index 6c5ba4a..09103cc 100644 | |
--- a/lib/Router/Simple/Route.pm | |
+++ b/lib/Router/Simple/Route.pm | |
@@ -41,6 +41,7 @@ sub new { | |
$row->{_regexp_capture} = 1; | |
$pattern; | |
} else { | |
+ my $n = -1; | |
$pattern =~ s! | |
\{((?:\{[0-9,]+\}|[^{}]+)+)\} | # /blog/{year:\d{4}} | |
:([A-Za-z0-9_]+) | # /blog/:year | |
@@ -50,13 +51,16 @@ sub new { | |
if ($1) { | |
my ($name, $pattern) = split /:/, $1, 2; | |
push @capture, $name; | |
- $pattern ? "($pattern)" : "([^/]+)"; | |
+ $n++; | |
+ $pattern ? "(?<match_$n>$pattern)" : "(?<match_$n>[^/]+)"; | |
} elsif ($2) { | |
push @capture, $2; | |
- "([^/]+)"; | |
+ $n++; | |
+ "(?<match_$n>[^/]+)"; | |
} elsif ($3) { | |
push @capture, '__splat__'; | |
- "(.+)"; | |
+ $n++; | |
+ "(?<match_$n>.+)"; | |
} else { | |
quotemeta($4); | |
} | |
@@ -91,9 +95,9 @@ sub match { | |
} else { | |
for my $i (0..@{$self->{capture}}-1) { | |
if ($self->{capture}->[$i] eq '__splat__') { | |
- push @splat, $captured[$i]; | |
+ push @splat, @{$-{'match_' . $i}}; | |
} else { | |
- $args{$self->{capture}->[$i]} = $captured[$i]; | |
+ $args{$self->{capture}->[$i]} = $+{'match_' . $i}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment