summaryrefslogtreecommitdiff
path: root/t/bugs/super_recursion.t
blob: b6d920f1617cad2ed91b047597ba445fc2c28e2d (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use strict;
use warnings;

use Test::More;

{
    package First;
    use Moose;

    sub foo {
        ::BAIL_OUT('First::foo called twice') if $main::seen{'First::foo'}++;
        return '1';
    }

    sub bar {
        ::BAIL_OUT('First::bar called twice') if $main::seen{'First::bar'}++;
        return '1';
    }

    sub baz {
        ::BAIL_OUT('First::baz called twice') if $main::seen{'First::baz'}++;
        return '1';
    }
}

{
    package Second;
    use Moose;
    extends qw(First);

    sub foo {
        ::BAIL_OUT('Second::foo called twice') if $main::seen{'Second::foo'}++;
        return '2' . super();
    }

    sub bar {
        ::BAIL_OUT('Second::bar called twice') if $main::seen{'Second::bar'}++;
        return '2' . ( super() || '' );
    }

    override baz => sub {
        ::BAIL_OUT('Second::baz called twice') if $main::seen{'Second::baz'}++;
        return '2' . super();
    };
}

{
    package Third;
    use Moose;
    extends qw(Second);

    sub foo { return '3' . ( super() || '' ) }

    override bar => sub {
        ::BAIL_OUT('Third::bar called twice') if $main::seen{'Third::bar'}++;
        return '3' . super();
    };

    override baz => sub {
        ::BAIL_OUT('Third::baz called twice') if $main::seen{'Third::baz'}++;
        return '3' . super();
    };
}

is( Third->new->foo, '3' );
is( Third->new->bar, '32' );
is( Third->new->baz, '321' );

done_testing;