6 use Test::More tests => 2 * (4 + 3) * 4;
11 sub add { $_[0] + $_[1] }
12 sub call ($$$) { my $x = \&dummy; $_[0]->($_[1], $_[2]) }
13 sub foo { call(\&add, $_[0], 1); }
14 sub bar { my $y = \&call; $y->(\&add, $_[0], 1); }
17 my ($brd, $coderef, $yfunc, $yref, $nfunc, $nref, $l) = @_;
18 my $code = $brd->coderef2text($coderef);
20 like($code, qr/\b(?<!\\&)$_\b/, "expansion at level $l contains the function $_");
23 like($code, qr/\b(?<=\\&)$_\b/, "expansion at level $l contains the ref $_");
26 unlike($code, qr/\b(?<!\\&)$_\b/, "expansion at level $l does not contain the function $_");
29 unlike($code, qr/\b(?<=\\&)$_\b/, "expansion at level $l does not contain the ref $_");
31 $code = eval 'sub ' . $code;
32 is($@, '', "result compiles at level $l");
33 is_deeply( [ defined $code, ref $code ], [ 1, 'CODE' ], "result compiles to a code reference at level $l");
34 is($code->(2), $coderef->(2), "result compiles to the good thing at level $l");
37 my $br_args = '-sCi0v1';
39 my $brd = B::RecDeparse->new(deparse => $br_args, level => -1);
40 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], -1;
41 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], -1;
43 $brd = B::RecDeparse->new(deparse => $br_args, level => 0);
44 which $brd, \&foo, [ qw<call> ], [ qw<add> ], [ qw<add> ], [ qw<dummy> ], 0;
45 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add> ], [ qw<dummy> ], 0;
47 $brd = B::RecDeparse->new(deparse => $br_args, level => 1);
48 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], 1;
49 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], 1;
51 $brd = B::RecDeparse->new(deparse => $br_args, level => 2);
52 which $brd, \&foo, [ ], [ qw<add dummy> ], [ qw<add call> ], [ ], 2;
53 which $brd, \&bar, [ ], [ qw<add call> ], [ qw<add call> ], [ ], 2;