9 use Test::Requires 'PadWalker';
13 my $env = { '$foo' => \$foo };
15 my $code = eval_closure(
16 source => 'sub { push @$foo, @_ }',
19 is_deeply(scalar(PadWalker::closed_over($code)), $env,
20 "closed over the right things");
26 my $env = { '$foo' => \$bar, '$bar' => \$foo };
28 my $code = eval_closure(
29 source => 'sub { push @$foo, @_; $bar->{foo} = \@_ }',
32 is_deeply(scalar(PadWalker::closed_over($code)), $env,
33 "closed over the right things");
38 my $env = { '$foo' => \$foo };
41 my $code = eval_closure(
42 source => 'sub { push @$foo, @_; return $__captures }',
45 } qr/Global symbol "\$__captures/, "we don't close over \$__captures";
48 # it'd be nice if we could test that closing over other things wasn't possible,
49 # but perl's optimizer gets in the way of that