our $VERSION = '1.002000'; # 1.2.0
$VERSION = eval $VERSION;
-# Used localised
-our($hints, %hints);
-
has hints => (
is => 'rw',
default => quote_sub q{ {} },
);
-has _first_eval => (
- is => 'rw',
- default => quote_sub q{ 1 },
-);
-
around eval => sub {
my $orig = shift;
my($self) = @_;
my @ret = $orig->(@_);
$self->hints({ Eval::WithLexicals::Cage::capture_hints() });
+ $self->prelude(
+ join '', q[ BEGIN { ],
+ _capture_unroll_global('$Eval::WithLexicals::Cage::hints', $self->hints, 2),
+ q[ } ],
+ );
@ret;
};
);
}
-sub setup_code {
- my($self) = @_;
- # Only run the prelude on the first eval, hints will be set after
- # that.
- if($self->_first_eval) {
- $self->_first_eval(0);
- return $self->prelude;
- } else {
- # Seems we can't use the technique of passing via @_ for code in a BEGIN
- # block
- return q[ BEGIN { ],
- _capture_unroll_global('$Eval::WithLexicals::Cage::hints', $self->hints, 2),
- q[ } ],
- }
-};
-
around capture_code => sub {
my $orig = shift;
my($self) = @_;
( q{ sub Eval::WithLexicals::Cage::capture_hints {
- no warnings 'closure';
- my($hints, %hints);
- BEGIN { $hints = $^H; %hints = %^H; }
- return q{$^H} => \$hints, q{%^H} => \%hints;
+ my ($hints, %hints, $warn_bits);
+ BEGIN {
+ no warnings 'closure';
+ $hints = $^H;
+ %hints = %^H;
+ $warn_bits = ${^WARNING_BITS};
+ }
+ return (
+ q{$^H} => \$hints,
+ q{%^H} => \%hints,
+ q{${^WARNING_BITS}} => \$warn_bits,
+ );
} },
$orig->(@_) )
};