1 package Eval::WithLexicals::Role::LexicalHints;
13 default => sub { {} },
20 local *Eval::WithLexicals::Cage::capture_hints;
21 local $Eval::WithLexicals::Cage::hints = { %{$self->hints} };
23 my @ret = $orig->(@_);
25 $self->hints({ Eval::WithLexicals::Cage::capture_hints() });
30 # XXX: Sub::Quote::capture_unroll without 'my'
32 sub _capture_unroll_global {
33 my ($from, $captures, $indent) = @_;
38 or die "capture key should start with \@, \% or \$: $_";
39 (' ' x $indent).qq{${_} = ${1}{${from}->{${\B::perlstring $_}}};\n};
44 around setup_code => sub {
47 # Only run the prelude on the first eval, hints will be set after
49 if($self->first_eval) {
51 return $self->prelude, $orig->(@_);
53 # Seems we can't use the technique of passing via @_ for code in a BEGIN block
54 return q[ BEGIN { ], _capture_unroll_global('$Eval::WithLexicals::Cage::hints', $self->hints, 2), q[ } ],
59 around capture_code => sub {
63 ( q{ sub Eval::WithLexicals::Cage::capture_hints {
64 no warnings 'closure';
66 BEGIN { $hints = $^H; %hints = %^H; }
67 return q{$^H} => \$hints, q{%^H} => \%hints;