update changelog
[p5sagit/Devel-BeginLift.git] / t / generate.t
CommitLineData
4d07fd95 1use strict;
2use warnings;
3use Test::More;
4
5BEGIN {
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 11sub foo {
4d07fd95 12 B::SVOP->new("const", 0, 42);
13}
14
62b5f5ed 15sub gorch ($) {
16 my $meth = ( $_[0]->kids )[-1]->sv->object_2svref;
17 $$meth = "other";
18 $_[0];
19}
4d07fd95 20
62b5f5ed 21use Devel::BeginLift qw(foo gorch);
4d07fd95 22
62b5f5ed 23sub bar { 7 + foo() }
4d07fd95 24is( bar(), 49, "optree injected" );
25
62b5f5ed 26sub blah { foo(31) }
27is(blah(), 42, "optree injected" );;
28
29sub meth { 3 }
30
31sub other { 42 }
32
33__END__
34
35my $obj = bless {};
36sub oink { gorch $obj->meth; }
37
38is( oink(), 42, "modify method call");
39
40my @args = ( 1 .. 3 );
41sub ploink { gorch $obj->meth(1, @args); }
42is( ploink(), 42, "modify method call with args");
43