This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Encode to CPAN version 2.78
[perl5.git] / t / mro / next_inanon.t
CommitLineData
e1a479c5
BB
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
5f5ae4a7 6require q(./test.pl); plan(tests => 2);
e1a479c5
BB
7
8=pod
9
10This tests the successful handling of a next::method call from within an
11anonymous 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
51is(B->foo, "B::foo => A::foo",
52 'method resolved inside anonymous sub');
53
54is(B->bar, "B::bar => A::bar",
55 'method resolved inside nested anonymous subs');
56
57