File: next_goto.t

package info (click to toggle)
perl 5.20.2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 88,360 kB
  • sloc: perl: 555,131; ansic: 213,934; sh: 38,120; pascal: 8,783; cpp: 3,895; makefile: 2,392; xml: 2,325; yacc: 1,741
file content (35 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use strict;
use warnings;

require q(./test.pl); plan(tests => 4);

use mro;

{
    package Proxy;
    our @ISA = qw//;
    sub next_proxy { goto &next::method }
    sub maybe_proxy { goto &maybe::next::method }
    sub can_proxy { goto &next::can }

    package TBase;
    our @ISA = qw//;
    sub foo { 42 }
    sub bar { 24 }
    # baz doesn't exist intentionally
    sub quux { 242 }

    package TTop;
    our @ISA = qw/TBase/;
    sub foo { shift->Proxy::next_proxy() }
    sub bar { shift->Proxy::maybe_proxy() }
    sub baz { shift->Proxy::maybe_proxy() }
    sub quux { shift->Proxy::can_proxy()->() }
}

is(TTop->foo, 42, 'proxy next::method via goto');
is(TTop->bar, 24, 'proxy maybe::next::method via goto');
ok(!TTop->baz, 'proxy maybe::next::method via goto with no method');
is(TTop->quux, 242, 'proxy next::can via goto');