Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created November 6, 2010 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/665696 to your computer and use it in GitHub Desktop.
Save tadzik/665696 to your computer and use it in GitHub Desktop.
┌─[tadzik@yavin4]─[~/src/perl6]
└─[%]─> cat myapp.pl
#module PerlApp {
our %commands;
# our sub add_command ($name, $sub) {
# 'almost there'.say;
# %commands{$name} = $sub; # crashes here
# 'got it'.say;
# }
our multi trait_mod:<is>($sub, $cmd, :$command!) {
'adding a new handler'.say;
%commands{$cmd} = $sub; # does not work
'added'.say;
#add_command($cmd, $sub); # does not work either, see #6
}
sub run_app($name, *@args) {
%commands{$name}(@args);
}
#}
sub foo() is command('one') {
say "Hai, I'm command one!";
}
sub bar() is command('two') {
say "Hai, I'm command two!";
}
sub MAIN(*@args) {
run_app(@args);
}
┌─[tadzik@yavin4]─[~/src/perl6]
└─[%]─> perl6 myapp.pl
adding a new handler
===SORRY!===
Null PMC access in can()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment