Created
September 23, 2018 04:03
-
-
Save t3hk0d3/b2210f33d7a2d3e0b5fe3d581c564e6d to your computer and use it in GitHub Desktop.
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
package Test { | |
use Keyword::Declare; | |
my $vars = {}; | |
keyword let (Str $name, Block $block) { | |
$name =~ s/^("|')(.*)("|')$/$2/; | |
"my sub $name { \$vars->{$name} //= do $block }" | |
} | |
let 'foo' { | |
int(rand 10); | |
} | |
sub boo { | |
print "Run 1 = " . foo() . "\n"; | |
print "Run 2 = " . foo() . "\n"; | |
$vars = {}; | |
print "Run 3 = " . foo() . "\n"; | |
print "Run 4 = " . foo() . "\n"; | |
} | |
}; | |
Test::boo('doo!'); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment