Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose Perl 5 global variables as %*PERL5
Fixes GH #69
  • Loading branch information
niner committed Jul 23, 2016
1 parent 5e3df66 commit de1dfb6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Inline/Perl5.pm6
Expand Up @@ -521,6 +521,12 @@ method global(Str $name) {
self.p5_to_p6(p5_get_global($!p5, $name))
}

PROCESS::<%PERL5> := class :: does Associative {
multi method AT-KEY($name) {
Inline::Perl5.default_perl5.global($name)
}
}.new;

class Perl6Callbacks {
has $.p5;
method create($package, $code) {
Expand Down
5 changes: 4 additions & 1 deletion t/globals.t
Expand Up @@ -5,12 +5,15 @@ my $p5 = Inline::Perl5.default_perl5;

try EVAL 'die "test\n"', :lang<Perl5>;
is $p5.global('$@'), "test\n";
is %*PERL5<$@>, "test\n";

EVAL '@a = (1, 2)', :lang<Perl5>;
is $p5.global('@a'), [1, 2];
is %*PERL5<@a>, [1, 2];

EVAL '%a = (a => 1)', :lang<Perl5>;
is-deeply $p5.global('%a'), {a => 1};
is $p5.global('%a'), {a => 1};
is %*PERL5<%a>, {a => 1};

done-testing;

Expand Down

0 comments on commit de1dfb6

Please sign in to comment.