3 use Eval::WithLexicals;
7 use get_strictures_hints qw($strictures_hints $strictures_warn);
9 my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => '');
12 [ $eval->eval('$x = 1') ],
14 'Basic non-strict eval ok'
22 $eval->eval('use strictures 1');
25 local $SIG{__WARN__} = sub { };
27 ok !eval { $eval->eval('${"x"}') }, 'Unable to use undeclared variable';
28 like $@, qr/Can't use string .* as a SCALAR ref/,
29 'Correct message in $@';
33 ${$eval->hints->{q{$^H}}}, $strictures_hints,
34 'Hints are set per strictures'
38 (unpack "H*", ${ $eval->hints->{'${^WARNING_BITS}'} }),
39 (unpack "H*", $strictures_warn),
40 'Warning bits are set per strictures'
44 [ $_ => $warnings::Bits{$_} ],
45 [ "fatal $_" => $warnings::DeadBits{$_} ],
52 [ missing => $strictures_warn ],
53 [ extra => ${ $eval->hints->{'${^WARNING_BITS}'} } ],
55 my $bits = $check->[1];
56 $info{$check->[0]} = {
57 map { ($bits & $_->[1]) =~ /[^\0]/ ? ( $_->[0] => 1 ) : () }
63 my @extra = keys %{$info{extra}};
64 my @missing = keys %{$info{missing}};
65 delete @{$info{missing}}{ @extra };
66 delete @{$info{extra}}{ @missing };
69 for my $type (qw(missing extra)) {
70 my @found = grep $info{$type}{$_}, map $_->[0], @cats;
83 # Assumption about perl internals: sort pragma will set a key in %^H.
84 $eval->eval(q{ { use hint_hash_pragma 'param' } }),
85 ok !exists $eval->hints->{q{%^H}}->{hint_hash_pragma},
86 "Lexical pragma used below main scope not captured";
88 $eval->eval(q{ use hint_hash_pragma 'param' }),
89 is $eval->hints->{q{%^H}}->{hint_hash_pragma}, 'param',
90 "Lexical pragma captured";
92 $eval->eval('my $x = 1');
94 $eval->lexicals->{'$x'}, \1,
95 'Lexical captured when preserving hints',