1 package Eval::WithLexicals::WithHintPersistence;
5 our $VERSION = '1.001000'; # 1.1.0
6 $VERSION = eval $VERSION;
13 default => quote_sub q{ {} },
18 default => quote_sub q{ 1 },
25 local *Eval::WithLexicals::Cage::capture_hints;
26 local $Eval::WithLexicals::Cage::hints = { %{$self->hints} };
28 my @ret = $orig->(@_);
30 $self->hints({ Eval::WithLexicals::Cage::capture_hints() });
35 # XXX: Sub::Quote::capture_unroll without 'my'
37 sub _capture_unroll_global {
38 my ($from, $captures, $indent) = @_;
43 or die "capture key should start with \@, \% or \$: $_";
44 (' ' x $indent).qq{${_} = ${1}{${from}->{${\B::perlstring $_}}};\n};
49 around setup_code => sub {
50 shift; # we bypass orig, i.e. using role as normal inheritance.
52 # Only run the prelude on the first eval, hints will be set after
54 if($self->_first_eval) {
55 $self->_first_eval(0);
56 return $self->prelude;
58 # Seems we can't use the technique of passing via @_ for code in a BEGIN
61 _capture_unroll_global('$Eval::WithLexicals::Cage::hints', $self->hints, 2),
66 around capture_code => sub {
70 ( q{ sub Eval::WithLexicals::Cage::capture_hints {
71 no warnings 'closure';
73 BEGIN { $hints = $^H; %hints = %^H; }
74 return q{$^H} => \$hints, q{%^H} => \%hints;
81 Eval::WithLexicals::WithHintPersistence - Persist compile hints between evals
85 use Eval::WithLexicals;
87 my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new;
91 Persist pragams and other compile hints between evals (for example the
92 L<strict> and L<warnings> flags in effect).
94 Saves and restores the C<$^H> and C<%^H> variables.
102 Returns the internal hints hash, keys are C<$^H> and C<%^H> for the hint bits
103 and hint hash respectively.