This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Import version.pm 0.9914 from CPAN
[perl5.git] / t / mro / next_inanon.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 require q(./test.pl); plan(tests => 2);
7
8 =pod
9
10 This tests the successful handling of a next::method call from within an
11 anonymous subroutine.
12
13 =cut
14
15 {
16     package A;
17     use mro 'c3'; 
18
19     sub foo {
20       return 'A::foo';
21     }
22
23     sub bar {
24       return 'A::bar';
25     }
26 }
27
28 {
29     package B;
30     use base 'A';
31     use mro 'c3'; 
32     
33     sub foo {
34       my $code = sub {
35         return 'B::foo => ' . (shift)->next::method();
36       };
37       return (shift)->$code;
38     }
39
40     sub bar {
41       my $code1 = sub {
42         my $code2 = sub {
43           return 'B::bar => ' . (shift)->next::method();
44         };
45         return (shift)->$code2;
46       };
47       return (shift)->$code1;
48     }
49 }
50
51 is(B->foo, "B::foo => A::foo",
52    'method resolved inside anonymous sub');
53
54 is(B->bar, "B::bar => A::bar",
55    'method resolved inside nested anonymous subs');
56
57