1use strict;
2use warnings;
3
4use Test::More;
5use Test::Fatal;
6
7use Moose::Meta::Role::Application::RoleSummation;
8use Moose::Meta::Role::Composite;
9
10{
11    package Role::Foo;
12    use Moose::Role;
13
14    package Role::Bar;
15    use Moose::Role;
16
17    package Role::Baz;
18    use Moose::Role;
19
20    package Role::Gorch;
21    use Moose::Role;
22}
23
24{
25    my $c = Moose::Meta::Role::Composite->new(
26        roles => [
27            Role::Foo->meta,
28            Role::Bar->meta,
29            Role::Baz->meta,
30        ]
31    );
32    isa_ok($c, 'Moose::Meta::Role::Composite');
33
34    is($c->name, 'Role::Foo|Role::Bar|Role::Baz', '... got the composite role name');
35
36    is_deeply($c->get_roles, [
37        Role::Foo->meta,
38        Role::Bar->meta,
39        Role::Baz->meta,
40    ], '... got the right roles');
41
42    ok($c->does_role($_), '... our composite does the role ' . $_)
43        for qw(
44            Role::Foo
45            Role::Bar
46            Role::Baz
47        );
48
49    is( exception {
50        Moose::Meta::Role::Application::RoleSummation->new->apply($c);
51    }, undef, '... this composed okay' );
52
53    ok(!$c->is_anon, '... composite is not anonymous');
54
55    ##... now nest 'em
56    {
57        my $c2 = Moose::Meta::Role::Composite->new(
58            roles => [
59                $c,
60                Role::Gorch->meta,
61            ]
62        );
63        isa_ok($c2, 'Moose::Meta::Role::Composite');
64
65        is($c2->name, 'Role::Foo|Role::Bar|Role::Baz|Role::Gorch', '... got the composite role name');
66
67        is_deeply($c2->get_roles, [
68            $c,
69            Role::Gorch->meta,
70        ], '... got the right roles');
71
72        ok($c2->does_role($_), '... our composite does the role ' . $_)
73            for qw(
74                Role::Foo
75                Role::Bar
76                Role::Baz
77                Role::Gorch
78            );
79
80        ok(!$c2->is_anon, '... composite is not anonymous');
81    }
82}
83
84done_testing;
85