-
-
Save moritz/2366919 to your computer and use it in GitHub Desktop.
Perl 6: dynamically generate exports in Rakudo
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
module A { | |
BEGIN { | |
my $name = 'foo'; | |
my $x = sub { say 'OH HAI from &foo' } but role { method name { $name } }; | |
trait_mod:<is>(:export, $x); | |
} | |
} |
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
$ ./perl6 -e 'use A; foo' | |
OH HAI from &foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, this still works! However, my version runs very slow on the latest rakudo. Is there a better mechanism?!