Skip to content

Instantly share code, notes, and snippets.

@s1n
Created May 17, 2009 17:24
Show Gist options
  • Save s1n/113062 to your computer and use it in GitHub Desktop.
Save s1n/113062 to your computer and use it in GitHub Desktop.
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