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