;sub Eval::WithLexicals::Cage::pad_capture { }
BEGIN { Eval::WithLexicals::Util::capture_list() }
sub Eval::WithLexicals::Cage::grab_captures {
- no warnings 'closure'; no strict 'refs';
- package Eval::WithLexicals::Cage;!;
+ no warnings 'closure'; no strict 'vars';
+ package Eval::WithLexicals::VarScope;!;
$self->_eval_do(\$current_code, $self->lexicals);
my @ret;
my $ctx = $self->context;
}
$self->lexicals({
%{$self->lexicals},
- %{Eval::WithLexicals::Cage::grab_captures()}
+ %{$self->_grab_captures},
});
@ret;
}
+sub _grab_captures {
+ my ($self) = @_;
+ my $cap = Eval::WithLexicals::Cage::grab_captures();
+ foreach my $key (keys %$cap) {
+ my ($sigil, $name) = $key =~ /^(.)(.+)$/;
+ my $var_scope_name = $sigil.'Eval::WithLexicals::VarScope::'.$name;
+ if ($cap->{$key} eq eval "\\${var_scope_name}") {
+ delete $cap->{$key};
+ }
+ }
+ $cap;
+}
+
sub _eval_do {
my ($self, $text_ref) = @_;
local @INC = (sub {
'Inner scope plus lexical ok'
);
+is_deeply(
+ [ $eval->eval('{ my $y = 0 }; $x') ],
+ [ 1 ],
+ 'Inner scope and other lexical ok'
+);
+
done_testing;