Commit | Line | Data |
2b376bd0 |
1 | use strictures (); |
8d732f30 |
2 | my $strictures_hints; |
2b376bd0 |
3 | BEGIN { |
4 | local $ENV{PERL_STRICTURES_EXTRA} = 0; |
5 | strictures->VERSION(1); strictures->import(); |
6 | # Find the hint value that 'use strictures 1' sets on this perl. |
7 | $strictures_hints = $^H; |
8 | } |
9 | use strictures 1; |
8d732f30 |
10 | |
11 | use Test::More; |
12 | use Eval::WithLexicals; |
9661a07c |
13 | use lib 't/lib'; |
8d732f30 |
14 | |
15 | my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => ''); |
16 | |
17 | is_deeply( |
18 | [ $eval->eval('$x = 1') ], |
19 | [ 1 ], |
20 | 'Basic non-strict eval ok' |
21 | ); |
22 | |
23 | is_deeply( |
24 | $eval->lexicals, { }, |
25 | 'Lexical not stored' |
26 | ); |
27 | |
28 | $eval->eval('use strictures 1'); |
29 | |
30 | { |
31 | local $SIG{__WARN__} = sub { }; |
32 | |
33 | ok !eval { $eval->eval('$x') }, 'Unable to use undeclared variable'; |
34 | like $@, qr/requires explicit package/, 'Correct message in $@'; |
35 | } |
36 | |
37 | is_deeply( |
38 | $eval->hints->{q{$^H}}, \$strictures_hints, |
39 | 'Hints are set per strictures' |
40 | ); |
41 | |
42 | is_deeply( |
43 | $eval->lexicals, { }, |
44 | 'Lexical not stored' |
45 | ); |
46 | |
47 | # Assumption about perl internals: sort pragma will set a key in %^H. |
9661a07c |
48 | $eval->eval(q{ { use hint_hash_pragma 'param' } }), |
49 | ok !exists $eval->hints->{q{%^H}}->{hint_hash_pragma}, |
8d732f30 |
50 | "Lexical pragma used below main scope not captured"; |
51 | |
9661a07c |
52 | $eval->eval(q{ use hint_hash_pragma 'param' }), |
53 | is $eval->hints->{q{%^H}}->{hint_hash_pragma}, 'param', |
8d732f30 |
54 | "Lexical pragma captured"; |
55 | |
56 | done_testing; |