Created
May 17, 2009 17:24
-
-
Save s1n/113062 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 foo_command { | |
} | |
module FooDispatch { | |
my @commands; | |
multi trait_auxiliary:<is>(foo_command $trait, $block, $arg) is export { | |
@commands.push({:command($arg[0]), :block($block)}); | |
} | |
sub dispatch(Str $line) is export { | |
for @commands -> $item { | |
if $line ~~ $item<command> { | |
my $ret = $item<block>($line); | |
return $ret; | |
} | |
} | |
warn "Could not dispatch {$line}"; | |
} | |
sub foo() is foo_command(/^foo/) { | |
say "Foo invoked"; | |
} | |
} | |
dispatch("foo"); | |
# vim:ft=perl6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment