Commit | Line | Data |
4d07fd95 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | |
62b5f5ed |
5 | use B::Utils; |
6 | |
4d07fd95 |
7 | BEGIN { |
8 | plan skip_all => "B::Generate required" unless eval { require B::Generate }; |
9 | plan 'no_plan'; |
10 | } |
11 | |
62b5f5ed |
12 | sub foo { |
4d07fd95 |
13 | B::SVOP->new("const", 0, 42); |
14 | } |
15 | |
62b5f5ed |
16 | sub gorch ($) { |
17 | my $meth = ( $_[0]->kids )[-1]->sv->object_2svref; |
18 | $$meth = "other"; |
19 | $_[0]; |
20 | } |
4d07fd95 |
21 | |
62b5f5ed |
22 | use Devel::BeginLift qw(foo gorch); |
4d07fd95 |
23 | |
62b5f5ed |
24 | sub bar { 7 + foo() } |
4d07fd95 |
25 | is( bar(), 49, "optree injected" ); |
26 | |
62b5f5ed |
27 | sub blah { foo(31) } |
28 | is(blah(), 42, "optree injected" );; |
29 | |
30 | sub meth { 3 } |
31 | |
32 | sub other { 42 } |
33 | |
34 | __END__ |
35 | |
36 | my $obj = bless {}; |
37 | sub oink { gorch $obj->meth; } |
38 | |
39 | is( oink(), 42, "modify method call"); |
40 | |
41 | my @args = ( 1 .. 3 ); |
42 | sub ploink { gorch $obj->meth(1, @args); } |
43 | is( ploink(), 42, "modify method call with args"); |
44 | |