Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created August 4, 2014 09:42
Show Gist options
  • Save lizmat/65d9e44743dffca1157c to your computer and use it in GitHub Desktop.
Save lizmat/65d9e44743dffca1157c to your computer and use it in GitHub Desktop.
Exporting dynamic variables delayed until runtime?
# ./Foo.pm
my sub EXPORT(*@a) {
say "in EXPORT";
( '$*FOO' => ++state $ ).hash;
}
============== works as expected
$ perl6 -I. -e 'use Foo; say $*FOO; { use Foo; say $*FOO }; say $*FOO'
in EXPORT
in EXPORT
1
2
1
============== but not at compile time
$ perl6 -I. -e 'use Foo; BEGIN say $*FOO; { use Foo; BEGIN say $*FOO }; BEGIN say $*FOO'
in EXPORT
===SORRY!===
Dynamic variable $*FOO not found
============== unless we set up stuff at compile time, but then we get the wrong value
BEGIN PROCESS::<$FOO>=0; use Foo; BEGIN say $*FOO; { use Foo; BEGIN say $*FOO }; BEGIN say $*FOO'
in EXPORT
0
in EXPORT
0
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment