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