File: generate.t

package info (click to toggle)
libdevel-beginlift-perl 0.001003-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 156 kB
  • ctags: 101
  • sloc: perl: 1,092; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use warnings;
use Test::More;

BEGIN {
    plan skip_all => "B::Generate required" unless eval { require B::Generate };
    plan skip_all => "B::Utils required" unless eval { require B::Utils };
    plan tests => 2;
}

sub foo {
    B::SVOP->new("const", 0, 42);
}

sub gorch ($) {
    my $meth = ( $_[0]->kids )[-1]->sv->object_2svref;
    $$meth = "other";
    $_[0];
}

use Devel::BeginLift qw(foo gorch);

sub bar { 7 + foo() }
is( bar(), 49, "optree injected" );

sub blah { foo(31) }
is(blah(), 42, "optree injected" );;

sub meth { 3 }

sub other { 42 }

__END__

my $obj = bless {};
sub oink { gorch $obj->meth; }

is( oink(), 42, "modify method call");

my @args = ( 1 .. 3 );
sub ploink { gorch $obj->meth(1, @args); }
is( ploink(), 42, "modify method call with args");