10 use Test::Requires 'PadWalker';
14 my $env = { '$foo' => \$foo };
16 my $code = eval_closure(
17 source => 'sub { push @$foo, @_ }',
20 is_deeply(scalar(PadWalker::closed_over($code)), $env,
21 "closed over the right things");
27 my $env = { '$foo' => \$bar, '$bar' => \$foo };
29 my $code = eval_closure(
30 source => 'sub { push @$foo, @_; $bar->{foo} = \@_ }',
33 is_deeply(scalar(PadWalker::closed_over($code)), $env,
34 "closed over the right things");
39 my $c = eval_closure(source => 'sub { }');
40 my $b = B::svref_2object($c);
42 while ($b->isa('B::CV')) {
46 my @visible_in_outer_scope
49 grep { $_->isa('B::PV') }
50 map { $_->PADLIST->ARRAYelt(0)->ARRAY }
53 # test to ensure we don't inadvertently screw up this test by rearranging
54 # code. if the scope that encloses the eval ends up not declaring $e, then
56 ok(scalar(grep { $_ eq '$e' } @visible_in_outer_scope),
57 "visible list is sane");
59 for my $outer_scope_pad_entry (@visible_in_outer_scope) {
63 source => "sub { $outer_scope_pad_entry }",
66 qr/Global symbol "\Q$outer_scope_pad_entry/,
67 "we don't close over $outer_scope_pad_entry"