File: 33_next_method_used_with_NEXT.t

package info (click to toggle)
libclass-c3-perl 0.35-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 476; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;

use Test::More;

BEGIN {
    eval "use NEXT";
    plan skip_all => "NEXT required for this test" if $@;
    plan tests => 4;
}

{
    package Foo;
    use strict;
    use warnings;
    use Class::C3;

    sub foo { 'Foo::foo' }

    package Fuz;
    use strict;
    use warnings;
    use Class::C3;
    BEGIN { our @ISA = ('Foo'); }

    sub foo { 'Fuz::foo => ' . (shift)->next::method }

    package Bar;
    use strict;
    use warnings;
    use Class::C3;
    BEGIN { our @ISA = ('Foo'); }

    sub foo { 'Bar::foo => ' . (shift)->next::method }

    package Baz;
    use strict;
    use warnings;
    require NEXT; # load this as late as possible so we can catch the test skip

    BEGIN { our @ISA = ('Bar', 'Fuz'); }

    sub foo { 'Baz::foo => ' . (shift)->NEXT::foo }
}

Class::C3::initialize();

is(Foo->foo, 'Foo::foo', '... got the right value from Foo->foo');
is(Fuz->foo, 'Fuz::foo => Foo::foo', '... got the right value from Fuz->foo');
is(Bar->foo, 'Bar::foo => Foo::foo', '... got the right value from Bar->foo');

is(Baz->foo, 'Baz::foo => Bar::foo => Fuz::foo => Foo::foo', '... got the right value using NEXT in a subclass of a C3 class');