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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
=pod
Check for repeated inheritance causing
a method conflict (which is not really
a conflict)
=cut
{
package Role::Base;
use Moose::Role;
sub foo { 'Role::Base::foo' }
package Role::Derived1;
use Moose::Role;
with 'Role::Base';
package Role::Derived2;
use Moose::Role;
with 'Role::Base';
package My::Test::Class1;
use Moose;
::is( ::exception {
with 'Role::Derived1', 'Role::Derived2';
}, undef, '... roles composed okay (no conflicts)' );
}
ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
=pod
Check for repeated inheritance causing
a method conflict with method modifiers
(which is not really a conflict)
=cut
{
package Role::Base2;
use Moose::Role;
override 'foo' => sub { super() . ' -> Role::Base::foo' };
package Role::Derived3;
use Moose::Role;
with 'Role::Base2';
package Role::Derived4;
use Moose::Role;
with 'Role::Base2';
package My::Test::Class2::Base;
use Moose;
sub foo { 'My::Test::Class2::Base' }
package My::Test::Class2;
use Moose;
extends 'My::Test::Class2::Base';
::is( ::exception {
with 'Role::Derived3', 'Role::Derived4';
}, undef, '... roles composed okay (no conflicts)' );
}
ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected');
ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected');
isa_ok(My::Test::Class2->meta->get_method('foo'), 'Moose::Meta::Method::Overridden');
ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected');
isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Class::MOP::Method');
is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method');
is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method');
=pod
Check for repeated inheritance of the
same code. There are no conflicts with
before/around/after method modifiers.
This tests around, but should work the
same for before/afters as well
=cut
{
package Role::Base3;
use Moose::Role;
around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
package Role::Derived5;
use Moose::Role;
with 'Role::Base3';
package Role::Derived6;
use Moose::Role;
with 'Role::Base3';
package My::Test::Class3::Base;
use Moose;
sub foo { 'My::Test::Class3::Base' }
package My::Test::Class3;
use Moose;
extends 'My::Test::Class3::Base';
::is( ::exception {
with 'Role::Derived5', 'Role::Derived6';
}, undef, '... roles composed okay (no conflicts)' );
}
ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected');
ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected');
isa_ok(My::Test::Class3->meta->get_method('foo'), 'Class::MOP::Method::Wrapped');
ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected');
isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Class::MOP::Method');
is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method');
is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method');
=pod
Check for repeated inheritance causing
a attr conflict (which is not really
a conflict)
=cut
{
package Role::Base4;
use Moose::Role;
has 'foo' => (is => 'ro', default => 'Role::Base::foo');
package Role::Derived7;
use Moose::Role;
with 'Role::Base4';
package Role::Derived8;
use Moose::Role;
with 'Role::Base4';
package My::Test::Class4;
use Moose;
::is( ::exception {
with 'Role::Derived7', 'Role::Derived8';
}, undef, '... roles composed okay (no conflicts)' );
}
ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');
done_testing;
|