File: caller.t

package info (click to toggle)
libperinci-sub-util-perl 0.472-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 885; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (4)
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
44
45
46
47
48
49
50
51
52
53
54
55
#!perl

use 5.010;
use strict;
use warnings;

BEGIN {
    use Test::More 0.96;
    use Perinci::Sub::Util qw(caller);
    eval "use Perinci::Sub::Wrapper qw(wrap_sub)";
    plan skip_all => 'Perinci::Sub::Wrapper needed for this test' if $@;
}

our %SPEC;

$SPEC{foo} = {
    v => 1.1,
};
sub foo {
    [200, "OK",
     [[caller(0)], [caller(1)], [caller(2)]]];
}

$SPEC{bar} = {
    v => 1.1,
};
sub bar {
    foow();
}

my $res = wrap_sub(sub=>\&foo, meta=>$SPEC{foo});
die "Can't wrap: $res->[0] - $res->[1]" unless $res->[0] == 200;
*foow = $res->[2]{sub};

$res = bar();
my $c0 = $res->[2][0];
my $c1 = $res->[2][1];
my $c2 = $res->[2][2];
is("$c0->[0]:$c0->[2]", "main:28");
is("$c1->[0]:$c1->[2]", "main:35");
ok(!@$c2);

$res = wrap_sub(sub=>\&foo, meta=>$SPEC{foo}, trap=>0);
die "Can't wrap: $res->[0] - $res->[1]" unless $res->[0] == 200;
{ no warnings 'redefine'; *foow = $res->[2]{sub}; }

$res = bar();
$c0 = $res->[2][0];
$c1 = $res->[2][1];
$c2 = $res->[2][2];
is("$c0->[0]:$c0->[2]", "main:28");
is("$c1->[0]:$c1->[2]", "main:47");
ok(!@$c2);

done_testing();