Permalink
Browse files

[URI::Dispatcher] splat saves parameters

When matching '/hello/*' with '/hello/world', the params hash
is now made to contain C<splat => ['world']>.
  • Loading branch information...
1 parent 984ce68 commit a14e8f34f06c5793517d82e60a51dee275471d54 @masak committed Dec 4, 2010
Showing with 8 additions and 2 deletions.
  1. +6 −1 lib/URI/Dispatcher.pm
  2. +2 −1 t/uri-dispatcher/03-splat.t
@@ -24,7 +24,12 @@ class URI::Dispatcher {
$url.substr($index) ~~ / <-[/]>+ /;
my $value = ~$/;
$index += $value.chars;
- %names{$key} = $value;
+ if $key eq '*' {
+ %names<splat>.push($value);
+ }
+ else {
+ %names{$key} = $value;
+ }
}
if $url.substr($index) eq $remainder {
return { url => $url, %names };
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 1;
+plan 2;
use URI::Dispatcher;
@@ -14,4 +14,5 @@ use URI::Dispatcher;
);
ok $d.dispatch('/hello/world'), 'splat works';
+ is $name, 'world', '...and it saves the parameter';
}

0 comments on commit a14e8f3

Please sign in to comment.