Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ┌─[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()
Add Comment
Please, Sign In to add comment