Permalink
Browse files

[URI::Dispatcher] implemented splat

  • Loading branch information...
1 parent cc3e1f0 commit 984ce680d28a891cae5870338028c4f8fa53433c @masak committed Dec 4, 2010
Showing with 22 additions and 3 deletions.
  1. +5 −3 lib/URI/Dispatcher.pm
  2. +17 −0 t/uri-dispatcher/03-splat.t
View
@@ -8,11 +8,13 @@ class URI::Dispatcher {
}
sub binds(Str $matcher, Str $url) {
- if $matcher ~~ / ':' \w+ / {
+ my $params_regex = / [':' (\w+) || ('*')] /;
+
+ if $matcher ~~ $params_regex {
my $remainder = $matcher;
my $index = 0;
- my %names;
- while $remainder ~~ / ':' (\w+) / {
+ my %names = splat => [];
+ while $remainder ~~ $params_regex {
my $key = $0;
my $constant_part = $remainder.substr(0, $/.from);
return False
@@ -0,0 +1,17 @@
+use v6;
+
+use Test;
+
+plan 1;
+
+use URI::Dispatcher;
+
+{
+ my $name;
+
+ my $d = URI::Dispatcher.new(
+ '/hello/*' => { $name = .<splat>[0] // 'not set' }
+ );
+
+ ok $d.dispatch('/hello/world'), 'splat works';
+}

0 comments on commit 984ce68

Please sign in to comment.