6 use Test::Requires 'Test::Output';
11 my $source = 'BEGIN { warn "foo\n" } sub { $foo * 2 }';
22 } "foo\n", "BEGIN was run";
24 is($code->(), 30, "got the right sub");
29 $code2 = eval_closure(
35 } '', "BEGIN was not run twice";
37 is($code2->(), 16, "got the right sub");
41 my $source = 'BEGIN { warn "bar\n" } sub { $bar * 2 }';
53 } "bar\n", "BEGIN was run";
55 is($code->(), 120, "got the right sub");
59 { local $TODO = "description breaks memoization";
61 $code2 = eval_closure(
68 } '', "BEGIN was not run twice";
71 is($code2->(), 46, "got the right sub");
75 my $source = 'BEGIN { warn "baz\n" } sub { Carp::confess "baz" }';
81 description => 'first',
83 } "baz\n", "BEGIN was run";
85 like(exception { $code->() }, qr/baz at first line 1/,
86 "got the right description");
89 { local $TODO = "description breaks memoization";
91 $code2 = eval_closure(
93 description => 'second',
95 } '', "BEGIN was not run twice";
98 like(exception { $code2->() }, qr/baz at second line 1/,
99 "got the right description");