update changelog
[p5sagit/Devel-BeginLift.git] / t / generate.t
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 };
7     plan skip_all => "B::Utils required" unless eval { require B::Utils };
8     plan tests => 2;
9 }
10
11 sub foo {
12     B::SVOP->new("const", 0, 42);
13 }
14
15 sub gorch ($) {
16     my $meth = ( $_[0]->kids )[-1]->sv->object_2svref;
17     $$meth = "other";
18     $_[0];
19 }
20
21 use Devel::BeginLift qw(foo gorch);
22
23 sub bar { 7 + foo() }
24 is( bar(), 49, "optree injected" );
25
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