6 use Test::More tests => 2 * (4 + 3) * 4;
12 strict->unimport('vars') if "$]" >= 5.021;
15 sub add { $_[0] + $_[1] }
16 sub call ($$$) { my $x = \&dummy; $_[0]->($_[1], $_[2]) }
17 sub foo { call(\&add, $_[0], 1); }
18 sub bar { my $y = \&call; $y->(\&add, $_[0], 1); }
22 my ($brd, $coderef, $yfunc, $yref, $nfunc, $nref, $l) = @_;
23 my $code = $brd->coderef2text($coderef);
25 like($code, qr/\b(?<!\\&)$_\b/, "expansion at level $l contains the function $_");
28 like($code, qr/\b(?<=\\&)$_\b/, "expansion at level $l contains the ref $_");
31 unlike($code, qr/\b(?<!\\&)$_\b/, "expansion at level $l does not contain the function $_");
34 unlike($code, qr/\b(?<=\\&)$_\b/, "expansion at level $l does not contain the ref $_");
36 $code = eval 'sub ' . $code;
37 is($@, '', "result compiles at level $l");
38 is_deeply( [ defined $code, ref $code ], [ 1, 'CODE' ], "result compiles to a code reference at level $l");
39 is($code->(2), $coderef->(2), "result compiles to the good thing at level $l");
42 my $bd_args = '-sCi0v1';
44 my $brd = B::RecDeparse->new(deparse => $bd_args, level => -1);
45 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], -1;
46 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], -1;
48 $brd = B::RecDeparse->new(deparse => $bd_args, level => 0);
49 which $brd, \&foo, [ qw<call> ], [ qw<add> ], [ qw<add> ], [ qw<dummy> ], 0;
50 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add> ], [ qw<dummy> ], 0;
52 $brd = B::RecDeparse->new(deparse => $bd_args, level => 1);
53 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], 1;
54 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], 1;
56 $brd = B::RecDeparse->new(deparse => $bd_args, level => 2);
57 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], 2;
58 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], 2;