xref: /openbsd-src/gnu/usr.bin/perl/t/mro/next_goto.t (revision 850e275390052b330d93020bf619a739a3c277ac)
1*850e2753Smillert#!/usr/bin/perl
2*850e2753Smillert
3*850e2753Smillertuse strict;
4*850e2753Smillertuse warnings;
5*850e2753Smillert
6*850e2753Smillertrequire q(./test.pl); plan(tests => 4);
7*850e2753Smillert
8*850e2753Smillertuse mro;
9*850e2753Smillert
10*850e2753Smillert{
11*850e2753Smillert    package Proxy;
12*850e2753Smillert    our @ISA = qw//;
13*850e2753Smillert    sub next_proxy { goto &next::method }
14*850e2753Smillert    sub maybe_proxy { goto &maybe::next::method }
15*850e2753Smillert    sub can_proxy { goto &next::can }
16*850e2753Smillert
17*850e2753Smillert    package TBase;
18*850e2753Smillert    our @ISA = qw//;
19*850e2753Smillert    sub foo { 42 }
20*850e2753Smillert    sub bar { 24 }
21*850e2753Smillert    # baz doesn't exist intentionally
22*850e2753Smillert    sub quux { 242 }
23*850e2753Smillert
24*850e2753Smillert    package TTop;
25*850e2753Smillert    our @ISA = qw/TBase/;
26*850e2753Smillert    sub foo { shift->Proxy::next_proxy() }
27*850e2753Smillert    sub bar { shift->Proxy::maybe_proxy() }
28*850e2753Smillert    sub baz { shift->Proxy::maybe_proxy() }
29*850e2753Smillert    sub quux { shift->Proxy::can_proxy()->() }
30*850e2753Smillert}
31*850e2753Smillert
32*850e2753Smillertis(TTop->foo, 42, 'proxy next::method via goto');
33*850e2753Smillertis(TTop->bar, 24, 'proxy maybe::next::method via goto');
34*850e2753Smillertok(!TTop->baz, 'proxy maybe::next::method via goto with no method');
35*850e2753Smillertis(TTop->quux, 242, 'proxy next::can via goto');
36