Is this a valid Perl6 script?
use v6.c;
my @a;
my $b;
my %c;
sub EXPORT(+@a) {
dd @a;
{
a => &TheTest::a
}
}
unit package TheTest;
our sub a {
say 1;
}
our sub b {
say "b";
}
our sub c {
say 3.14159;
}
Because when I run it, I get the following:
$ perl6 -I. -e 'use TheTest; a'
[]
===SORRY!===
Cannot find method 'package_at_key': no method cache and no .^find_method
If it is not valid P6, what am I doing wrong?
Oddly enough, these invocations will not generate that error:
$ perl6 -I. -e 'use TheTest <a b>; a'
$ perl6 -I. -e 'use TheTest <a>.list; a'
Thanks!
UPDATED -- PART DEAX!
I have updated the module above to the following:
use v6.c;
our @fa = ();
our $b;
our %c;
BEGIN {
say "BEGIN";
@fa = ^10;
dd @fa;
say "BEGIN--END";
}
sub EXPORT(+@a) {
dd @fa;
{
'&aa' => ::('&TheTest::aa'),
'&bb' => ::('&TheTest::bb')
}
}
module TheTest {
our sub aa {
say 1;
}
our sub bb {
say "b";
}
our sub cc {
say 3.14159;
}
}
And when I run it, I get something very unexpected:
$ perl6 -I. -e 'use TheTest; bb'
Array @fa = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
BEGIN
BEGIN--END
Array @fa = []
b
And, if I run it again with no changes, I get this:
$ perl6 -I. -e 'use TheTest; bb'
Array @fa = []
b
Which, as it turns out, is the proper behavior, since the BEGIN block is only executed at compile time. I will need to rethink this use case, because the real code still has this problem and it's tied to require() in a sub EXPORT(), but not just any require.