Created
May 14, 2009 11:55
-
-
Save jnthn/111625 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
role handler { | |
} | |
module LolDispatch { | |
my @routes; | |
multi trait_auxiliary:<is>(handler $trait, Block $block, $arg) is export { | |
@routes.push({:route($arg[0]), :block($block)}); | |
} | |
sub dispatch($r) is export { | |
for @routes -> $item{ | |
if $r ~~ $item<route> { | |
my $ret = $item<block>($r,$/); | |
return $ret; | |
} | |
} | |
warn "Could not dispatch $r"; | |
} | |
} |
This file contains hidden or 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
use LolDispatch; | |
sub foo($request, $match) is handler(/wtf/) { | |
say 'dispatched to foo'; | |
say $match.perl; | |
} | |
sub item($request, $match) is handler(/^\/item\/(\d+)/) { | |
say 'dispatched to item'; | |
say $match.perl; | |
} | |
my $request = '/item/12345'; | |
dispatch($request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment