Guest User

Untitled

a guest
Jun 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. ┌─[tadzik@yavin4]─[~/src/perl6]
  2. └─[%]─> cat myapp.pl
  3. #module PerlApp {
  4. our %commands;
  5.  
  6. # our sub add_command ($name, $sub) {
  7. # 'almost there'.say;
  8. # %commands{$name} = $sub; # crashes here
  9. # 'got it'.say;
  10. # }
  11. our multi trait_mod:<is>($sub, $cmd, :$command!) {
  12. 'adding a new handler'.say;
  13. %commands{$cmd} = $sub; # does not work
  14. 'added'.say;
  15. #add_command($cmd, $sub); # does not work either, see #6
  16. }
  17. sub run_app($name, *@args) {
  18. %commands{$name}(@args);
  19. }
  20. #}
  21.  
  22. sub foo() is command('one') {
  23. say "Hai, I'm command one!";
  24. }
  25.  
  26. sub bar() is command('two') {
  27. say "Hai, I'm command two!";
  28. }
  29.  
  30. sub MAIN(*@args) {
  31. run_app(@args);
  32. }
  33. ┌─[tadzik@yavin4]─[~/src/perl6]
  34. └─[%]─> perl6 myapp.pl
  35. adding a new handler
  36. ===SORRY!===
  37. Null PMC access in can()
Add Comment
Please, Sign In to add comment