10 BEGIN { $::EVALED{'one'} = 1 }
14 my $two = quote_sub q{
15 BEGIN { $::EVALED{'two'} = 1 }
17 } => { '$x' => \do { my $x = 0 } };
19 ok(!keys %EVALED, 'Nothing evaled yet');
21 my $u_one = unquote_sub $one;
24 [ sort keys %EVALED ], [ qw(one) ],
28 is($one->(), 42, 'One (quoted version)');
30 is($u_one->(), 42, 'One (unquoted version)');
32 is($two->(), 3, 'Two (quoted version)');
33 is(unquote_sub($two)->(), 4, 'Two (unquoted version)');
34 is($two->(), 5, 'Two (quoted version again)');
36 my $three = quote_sub 'Foo::three' => q{
38 die +(caller(0))[3] if @_ > 2;
40 } => { '$x' => \do { my $x = 'spoon' } };
42 is(Foo->three, 'spoon', 'get ok (named method)');
43 is(Foo->three('fork'), 'fork', 'set ok (named method)');
44 is(Foo->three, 'fork', 're-get ok (named method)');
46 exception { Foo->three(qw(full cutlery set)) }, qr/Foo::three/,
47 'exception contains correct name'
50 quote_sub 'Foo::four' => q{
54 my $quoted = quoted_from_sub(\&Foo::four);
55 like $quoted->[1], qr/return 5;/,
56 'can get quoted from installed sub';
58 my $quoted2 = quoted_from_sub(\&Foo::four);
59 is $quoted2->[1], undef,
60 "can't get quoted from installed sub after undefer";