Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[URI::Dispatcher] call callback

Actual matching is performed on the URI now, and the callback is called.
  • Loading branch information...
commit dceea22b5732a6255c9eadb638ba51228465dccc 1 parent 6250115
@masak authored
Showing with 20 additions and 2 deletions.
  1. +16 −1 lib/URI/Dispatcher.pm
  2. +4 −1 t/uri-dispatcher/01-literal.t
View
17 lib/URI/Dispatcher.pm
@@ -1,7 +1,22 @@
use v6;
class URI::Dispatcher {
+ has @.rules;
+
+ method new(*@rules) {
+ self.bless(self.CREATE, :@rules);
+ }
+
method dispatch($url) {
- return True;
+ for @.rules -> $rule {
+ my ($matcher, &callback) = $rule.key, $rule.value;
+
+ if $matcher eq $url {
+ callback();
+ return True;
+ }
+
+ return False;
+ }
}
}
View
5 t/uri-dispatcher/01-literal.t
@@ -5,9 +5,12 @@ use Test;
use URI::Dispatcher;
{
+ my $callback_called = False;
+
my $d = URI::Dispatcher.new(
- '/' => {}
+ '/' => { $callback_called = True }
);
ok $d.dispatch('/'), 'can dispatch on provided literal URL';
+ ok $callback_called, 'the provided callback was called';
}
Please sign in to comment.
Something went wrong with that request. Please try again.