Commit | Line | Data |
d3b7b05c |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
4d0e6f3d |
5 | use if $ENV{AUTHOR_TESTING}, 'Test::Warnings'; |
d3b7b05c |
6 | BEGIN { |
7 | if ("$]" < 5.018) { |
8 | plan 'skip_all' => 'lexical subs not supported on this perl'; |
9 | } |
10 | } |
11 | |
652bff51 |
12 | BEGIN { |
13 | if ("$]" < 5.020) { |
14 | plan 'skip_all' => 'lexical subs unreliable on this perl'; |
15 | } |
16 | } |
17 | |
d3b7b05c |
18 | use feature 'lexical_subs'; |
19 | no warnings 'experimental::lexical_subs'; |
20 | |
21 | use Sub::Name; |
22 | |
23 | local $TODO = "lexical subs unnameable until perl 5.22" |
24 | unless "$]" >= 5.022; |
25 | |
26 | my $foo = sub { (caller 0)[3] }; |
27 | |
28 | my sub foo { (caller 0)[3] } |
29 | |
30 | subname 'main::foo2' => \&foo; |
31 | is foo(), 'main::foo2', 'lexical subs can be named'; |
32 | |
33 | my $x = 3; |
34 | my sub bar { (caller 0)[$x] } |
35 | subname 'main::bar2' => \&bar; |
36 | is bar(), 'main::bar2', 'lexical closure subs can be named'; |
37 | |
38 | done_testing; |