Created
November 6, 2010 20:31
-
-
Save tadzik/665696 to your computer and use it in GitHub Desktop.
This file contains 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
┌─[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