summaryrefslogtreecommitdiff
path: root/t/roles/role_composition_conflict_detection.t
blob: d2b693ad2b636e3cb226c948ada79d10912f8ad1 (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
use strict;
use warnings;

use Test::More;
use Moose::Util qw( find_meta );

{
    package RoleA;
    use Moose::Role;

    sub foo { 42 }
}

{
    package RoleB;
    use Moose::Role;

    with 'RoleA';
}

{
    package RoleC;
    use Moose::Role;

    sub foo { 84 }
}

{
    my $composite
        = Moose::Meta::Role->combine( map { [ find_meta($_) => {} ] }
            qw( RoleA RoleB RoleC ) );
    ok( $composite->requires_method('foo'), 'Composite of [ABC] requires a foo method' );
    ok( ! $composite->has_method('foo'), 'Composite of [ABC] does not also have a foo method' );
}

{
    my $composite
        = Moose::Meta::Role->combine( map { [ find_meta($_) => {} ] }
            qw( RoleA RoleC RoleB ) );
    ok( $composite->requires_method('foo'), 'Composite of [ACB] requires a foo method' );
    ok( ! $composite->has_method('foo'), 'Composite of [ACB] does not also have a foo method' );
}

done_testing;