Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. unit module TestImports;
  2.  
  3. sub bar is export { say "bar sub" }
  4. sub baz is export { say "baz sub" }
  5. my $var = 'He heu hey';
  6. my $aar = 'He heu hey';
  7. my $vaa = 'He heu hey';
  8. my $kar = 'He heu hey';
  9. my $vor = 'He heu hey';
  10. constant A = 333;
  11.  
  12. constant TOTITOTO = "patchamama";
  13. constant INTER = "jfklDJ";
  14. constant WANDER = "whoou";
  15. constant WANDER_FULL = "whoou";
  16. constant WANDER3FULL = "whoou";
  17. constant COLOR_A = 24;
  18. constant COLOR_B = 80;
  19. constant COLOR_C = 80;
  20. constant COLOR_D = 80;
  21. constant APPART is export(:AP) = 174;
  22. constant COLOR_E is export(:SPECIAL)= 80;
  23. constant COLOR_F = 80;
  24. constant COLOR_G = 80;
  25. constant COLOR_H = 80;
  26. constant COLOR_I = 80;
  27.  
  28. my package EXPORT::MYTAG {
  29.  
  30. my %excluded = EXPORT::.grep( *.key.grep( none /^ : ( ALL || DEFAULT || MYTAG ) $ /));
  31. say '%excluded : ' ~ %excluded.raku;
  32. my %all_in_tag_AP := EXPORT::AP::;
  33. say '%all_in_tag_AP => ' ~ %all_in_tag_AP.raku;
  34. #
  35. for %excluded.kv -> $k,$v {
  36. say $k ~ ' => ' ~ $v.raku;
  37. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! HERE COMES THE QUESTION: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  38. #How to interpolate in order to get yet exported symbols, tried:
  39. #my %key_value_sym = ::GLOBAL::EXPORT::($k)::; # Fails! but WHY.
  40. }
  41.  
  42. my %to_put_into_MYTAG = TestImports::.grep(*.key.match(/^ ( <[A..Z 3_]>+ ) $ /));
  43. for %to_put_into_MYTAG {
  44. next if .key eq 'EXPORT'; #Must avoid EXPORT key
  45. next if .key eq 'APPART'; #Must avoid yet exported tagged APPART
  46. next if .key eq 'COLOR_E'; #Must avoid yet exported tagged COLOR_E
  47. OUR::{.key} := .value;
  48. }
  49. #but the problem is `APPART` AND `COLOR_E` should be genericly avoided
  50. #beeing collected by the precedent loop.
  51. }
  52.  
  53. class Thing is export {
  54. method foo() {
  55. say "Inside foo method";
  56. say "CONSTANT A is : " ~ A;
  57. #say "MYCONSTANT : " ~ EXPORT::colors::MYCONSTANT;
  58. }
  59. }
  60.  
  61. #Now here is Main script testimport.raku
  62.  
  63. #!/bin/env raku
  64. #use TestImports :DEFAULT , <TOTITOTO INTER WANDER>, :AP :colors;
  65. #use TestImports <MTAG> ;
  66. use TestImports :DEFAULT, :MYTAG ,:AP, :SPECIAL ;
  67.  
  68. #Everything works!
  69. say TOTITOTO;
  70. say INTER;
  71. say WANDER;
  72. say WANDER_FULL;
  73. say WANDER3FULL;
  74. say APPART;
  75. say TestImports::A;
  76.  
  77. say COLOR_E;
  78. say COLOR_F;
  79.  
  80. #say COLOR_INTER;
  81. bar();
  82. baz();
  83.  
  84. Thing.new.foo;
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement