Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 024_role_composition_methods.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 19;
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
16 sub foo { 'Role::Foo::foo' }
17
67199842 18 package Role::Bar;
19 use Mouse::Role;
20
21 sub bar { 'Role::Bar::bar' }
6cfa1e5e 22
67199842 23 package Role::FooConflict;
6cfa1e5e 24 use Mouse::Role;
25
26 sub foo { 'Role::FooConflict::foo' }
27
67199842 28 package Role::BarConflict;
29 use Mouse::Role;
6cfa1e5e 30
67199842 31 sub bar { 'Role::BarConflict::bar' }
6cfa1e5e 32
67199842 33 package Role::AnotherFooConflict;
6cfa1e5e 34 use Mouse::Role;
67199842 35 with 'Role::FooConflict';
36
37 sub baz { 'Role::AnotherFooConflict::baz' }
38}
39
40# test simple attributes
41{
42 my $c = Mouse::Meta::Role::Composite->new(
43 roles => [
44 Role::Foo->meta,
45 Role::Bar->meta,
46 ]
47 );
48 isa_ok($c, 'Mouse::Meta::Role::Composite');
49
6cfa1e5e 50 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
51
67199842 52 lives_ok {
53 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 54 } '... this succeeds as expected';
55
67199842 56 is_deeply(
57 [ sort $c->get_method_list ],
58 [ 'bar', 'foo' ],
59 '... got the right list of methods'
60 );
61}
62
63# test simple conflict
64{
65 my $c = Mouse::Meta::Role::Composite->new(
66 roles => [
67 Role::Foo->meta,
68 Role::FooConflict->meta,
69 ]
70 );
71 isa_ok($c, 'Mouse::Meta::Role::Composite');
72
6cfa1e5e 73 is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name');
74
67199842 75 lives_ok {
76 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 77 } '... this succeeds as expected';
78
67199842 79 is_deeply(
80 [ sort $c->get_method_list ],
81 [],
82 '... got the right list of methods'
6cfa1e5e 83 );
84
67199842 85 is_deeply(
86 [ sort $c->get_required_method_list ],
87 [ 'foo' ],
88 '... got the right list of required methods'
6cfa1e5e 89 );
67199842 90}
91
92# test complex conflict
93{
94 my $c = Mouse::Meta::Role::Composite->new(
95 roles => [
96 Role::Foo->meta,
6cfa1e5e 97 Role::Bar->meta,
67199842 98 Role::FooConflict->meta,
6cfa1e5e 99 Role::BarConflict->meta,
67199842 100 ]
101 );
102 isa_ok($c, 'Mouse::Meta::Role::Composite');
103
6cfa1e5e 104 is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name');
67199842 105
106 lives_ok {
107 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
108 } '... this succeeds as expected';
109
110 is_deeply(
111 [ sort $c->get_method_list ],
112 [],
113 '... got the right list of methods'
6cfa1e5e 114 );
115
67199842 116 is_deeply(
117 [ sort $c->get_required_method_list ],
118 [ 'bar', 'foo' ],
119 '... got the right list of required methods'
6cfa1e5e 120 );
67199842 121}
122
123# test simple conflict
124{
125 my $c = Mouse::Meta::Role::Composite->new(
126 roles => [
127 Role::Foo->meta,
128 Role::AnotherFooConflict->meta,
129 ]
130 );
131 isa_ok($c, 'Mouse::Meta::Role::Composite');
132
6cfa1e5e 133 is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name');
134
67199842 135 lives_ok {
136 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 137 } '... this succeeds as expected';
138
67199842 139 is_deeply(
140 [ sort $c->get_method_list ],
141 [ 'baz' ],
142 '... got the right list of methods'
6cfa1e5e 143 );
144
67199842 145 is_deeply(
146 [ sort $c->get_required_method_list ],
147 [ 'foo' ],
148 '... got the right list of required methods'
6cfa1e5e 149 );
67199842 150}
151