Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. my %exports;
  2. multi sub EXPORT(*@names) {
  3. my %imports;
  4. for @names -> $name {
  5. unless %exports{$name}:exists {
  6. die("Unknown name for export: '$name'");
  7. }
  8. %imports{ $name} := %exports{ $name}
  9. }
  10. return %imports;
  11. }
  12.  
  13. unit module TestImports;
  14.  
  15. sub bar is export { say "bar sub" }
  16. sub baz is export { say "baz sub" }
  17. my $var = 'He heu hey';
  18. my $aar = 'He heu hey';
  19. my $vaa = 'He heu hey';
  20. my $kar = 'He heu hey';
  21. my $vor = 'He heu hey';
  22. constant TOTITOTO = "patchamama";
  23. constant INTER = "jfklDJ";
  24. constant WANDER = "whoou";
  25. constant WANDER_FULL = "whoou";
  26. constant WANDER3FULL = "whoou";
  27. constant APPART is export(:AP) = 174;
  28.  
  29. %exports = MY::.grep(*.key.match(/^ ( <[A..Z 3_]>+ ) $ /));
  30.  
  31. #Use the line commended instead to export subs + constants.
  32. #%exports = MY::.grep(*.key.match(/^ ( <[A .. Z]>+ || <[&]> <[a .. z]>+ ) $ /));
  33.  
  34. class Thing is export {
  35. method foo() {
  36. say "Inside foo method";
  37. }
  38. }
  39.  
  40. #MAIN script: testImports.raku
  41. #!/bin/env raku
  42. use TestImports :DEFAULT , <TOTITOTO INTER WANDER>, :AP;
  43.  
  44. #Everything works!
  45. say TOTITOTO;
  46. say INTER;
  47. say WANDER;
  48. bar();
  49. baz();
  50.  
  51. Thing.new.foo;
  52.  
  53. say APPART;
  54.  
  55. #TODO: How to do the same with a TAG? so that some constants&|subs&|etc... behave like APPART constant.
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement