Skip to content

Instantly share code, notes, and snippets.

@t3hk0d3
Created September 23, 2018 04:03
Show Gist options
  • Save t3hk0d3/b2210f33d7a2d3e0b5fe3d581c564e6d to your computer and use it in GitHub Desktop.
Save t3hk0d3/b2210f33d7a2d3e0b5fe3d581c564e6d to your computer and use it in GitHub Desktop.
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