Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 020_role_composite.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 14;
7use Test::Exception;
8
9use Mouse::Meta::Role::Application::RoleSummation;
10use Mouse::Meta::Role::Composite;
11
12{
13 package Role::Foo;
14 use Mouse::Role;
6cfa1e5e 15
67199842 16 package Role::Bar;
17 use Mouse::Role;
18
19 package Role::Baz;
6cfa1e5e 20 use Mouse::Role;
21
67199842 22 package Role::Gorch;
6cfa1e5e 23 use Mouse::Role;
67199842 24}
25
26{
27 my $c = Mouse::Meta::Role::Composite->new(
28 roles => [
29 Role::Foo->meta,
30 Role::Bar->meta,
6cfa1e5e 31 Role::Baz->meta,
67199842 32 ]
33 );
34 isa_ok($c, 'Mouse::Meta::Role::Composite');
35
36 is($c->name, 'Role::Foo|Role::Bar|Role::Baz', '... got the composite role name');
37
38 is_deeply($c->get_roles, [
39 Role::Foo->meta,
40 Role::Bar->meta,
6cfa1e5e 41 Role::Baz->meta,
67199842 42 ], '... got the right roles');
6cfa1e5e 43
67199842 44 ok($c->does_role($_), '... our composite does the role ' . $_)
45 for qw(
46 Role::Foo
47 Role::Bar
6cfa1e5e 48 Role::Baz
67199842 49 );
6cfa1e5e 50
67199842 51 lives_ok {
52 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 53 } '... this composed okay';
54
67199842 55 ##... now nest 'em
6cfa1e5e 56 {
67199842 57 my $c2 = Mouse::Meta::Role::Composite->new(
58 roles => [
59 $c,
60 Role::Gorch->meta,
61 ]
62 );
63 isa_ok($c2, 'Mouse::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,
6cfa1e5e 69 Role::Gorch->meta,
67199842 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
6cfa1e5e 76 Role::Baz
77 Role::Gorch
78 );
67199842 79 }
80}