Commit | Line | Data |
3967e628 |
1 | BEGIN { print "1..10\n"; $^P |= 0x210 } |
16c23894 |
2 | |
16c23894 |
3 | use Sub::Name; |
4 | |
5 | my $x = subname foo => sub { (caller 0)[3] }; |
3967e628 |
6 | my $line = __LINE__ - 1; |
7 | my $file = __FILE__; |
8 | my $anon = $DB::sub{"main::__ANON__[${file}:${line}]"}; |
9 | |
16c23894 |
10 | print $x->() eq "main::foo" ? "ok 1\n" : "not ok 1\n"; |
11 | |
12 | |
13 | package Blork; |
14 | |
15 | use Sub::Name; |
16 | |
17 | subname " Bar!", $x; |
18 | print $x->() eq "Blork:: Bar!" ? "ok 2\n" : "not ok 2\n"; |
19 | |
20 | subname "Foo::Bar::Baz", $x; |
21 | print $x->() eq "Foo::Bar::Baz" ? "ok 3\n" : "not ok 3\n"; |
22 | |
bbd01306 |
23 | subname "subname (dynamic $_)", \&subname for 1 .. 3; |
24 | |
25 | for (4 .. 5) { |
26 | subname "Dynamic $_", $x; |
27 | print $x->() eq "Blork::Dynamic $_" ? "ok $_\n" : "not ok $_\n"; |
28 | } |
16c23894 |
29 | |
3967e628 |
30 | print $DB::sub{"main::foo"} eq $anon ? "ok 6\n" : "not ok 6\n"; |
31 | |
32 | for (4 .. 5) { |
33 | print $DB::sub{"Blork::Dynamic $_"} eq $anon ? "ok ".($_+3)."\n" : "not ok ".($_+3)."\n"; |
34 | } |
35 | |
36 | my $i = 9; |
37 | for ("Blork:: Bar!", "Foo::Bar::Baz") { |
38 | print $DB::sub{$_} eq $anon ? "ok $i\n" : "not ok $_ \n"; |
39 | $i++; |
40 | } |
41 | |
16c23894 |
42 | # vim: ft=perl |