Commit | Line | Data |
a0e934a6 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
5 | |
6 | use Eval::Closure; |
7 | |
794dc9df |
8 | { |
9 | my $code = eval_closure( |
10 | source => 'no strict "refs"; sub { keys %{__PACKAGE__ . "::"} }', |
11 | ); |
a0e934a6 |
12 | |
794dc9df |
13 | # defining the sub { } creates __ANON__, calling 'no strict' creates BEGIN |
14 | my @stash_keys = grep { $_ ne '__ANON__' && $_ ne 'BEGIN' } $code->(); |
a0e934a6 |
15 | |
794dc9df |
16 | is_deeply([@stash_keys], [], "compiled in an empty package"); |
17 | } |
18 | |
19 | { |
20 | # the more common case where you'd run into this is imported subs |
21 | # for instance, Bread::Board::as vs Moose::Util::TypeConstraints::as |
22 | my $c1 = eval_closure( |
23 | source => 'no strict "vars"; sub { ++$foo }', |
24 | ); |
25 | my $c2 = eval_closure( |
26 | source => 'no strict "vars"; sub { --$foo }', |
27 | ); |
28 | is($c1->(), 1); |
29 | is($c1->(), 2); |
30 | is($c2->(), -1); |
31 | is($c2->(), -2); |
32 | } |
a0e934a6 |
33 | |
34 | done_testing; |