Example:
~ $ re.pl
$ { my $abc = 10 ; $abc }
10
$ $abc
10
$
Is this a documented gotcha?
This appears to be a bug in Lexical::Persistence, which Devel::REPL uses to manage the lexical environment persisting across multiple evals.
Here's a demonstration of the bug without Devel::REPL. This code incorrectly produces the value of $abc, 10, even though it's in an inner scope.
use strict;
use warnings;
use Lexical::Persistence;
my $environment = Lexical::Persistence->new;
$environment->call(sub {
my $foo = shift;
{ my $abc = 10 };
return $foo;
});
print $environment->get_context('_')->{'$abc'};
I've reported a bug against the module, we'll see what happens!
It's also worth noting that Matt Trout (the primary author of Devel::REPL)'s new lexical persistence module, Eval::WithLexicals does not suffer from this problem:
use strict;
use warnings;
use Eval::WithLexicals;
my $environment = Eval::WithLexicals->new;
print $environment->eval('{ my $abc = 10 ; $abc }'), "\n";
print $environment->eval('$abc'), "\n";
produces 10 as expected, then the second eval throws the expected Global symbol "$abc" requires explicit package name error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With