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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Moose();
{
{
package Foo1;
use Moose::Role;
excludes 'Bar1';
}
{
package Bar1;
use Moose::Role;
}
my $exception = exception {
package CompositeRole;
use Moose::Role;
with 'Foo1', 'Bar1';
};
like(
$exception,
qr/\QConflict detected: Role Foo1 excludes role 'Bar1'/,
"role Foo1 excludes role Bar1");
isa_ok(
$exception,
"Moose::Exception::RoleExclusionConflict",
"role Foo1 excludes role Bar1");
is(
$exception->role_name,
"Bar1",
"role Foo1 excludes role Bar1");
is_deeply(
$exception->roles,
["Foo1"],
"role Foo1 excludes role Bar1");
{
package Baz1;
use Moose::Role;
excludes 'Bar1';
}
$exception = exception {
package CompositeRole1;
use Moose::Role;
with 'Foo1', 'Bar1', 'Baz1';
};
like(
$exception,
qr/\QConflict detected: Roles Foo1, Baz1 exclude role 'Bar1'/,
"role Foo1 & Baz1 exclude role Bar1");
isa_ok(
$exception,
"Moose::Exception::RoleExclusionConflict",
"role Foo1 & Baz1 exclude role Bar1");
is(
$exception->role_name,
"Bar1",
"role Foo1 & Baz1 exclude role Bar1");
is_deeply(
$exception->roles,
["Foo1", 'Baz1'],
"role Foo1 & Baz1 exclude role Bar1");
}
{
{
package Foo2;
use Moose::Role;
has 'foo' => ( isa => 'Int' );
}
{
package Bar2;
use Moose::Role;
has 'foo' => ( isa => 'Int' );
}
my $exception = exception {
package CompositeRole2;
use Moose::Role;
with 'Foo2', 'Bar2';
};
like(
$exception,
qr/\QWe have encountered an attribute conflict with 'foo' during role composition. This attribute is defined in both Foo2 and Bar2. This is a fatal error and cannot be disambiguated./,
"role Foo2 & Bar2, both have an attribute named foo");
isa_ok(
$exception,
"Moose::Exception::AttributeConflictInSummation",
"role Foo2 & Bar2, both have an attribute named foo");
is(
$exception->role_name,
"Foo2",
"role Foo2 & Bar2, both have an attribute named foo");
is(
$exception->second_role_name,
"Bar2",
"role Foo2 & Bar2, both have an attribute named foo");
is(
$exception->attribute_name,
"foo",
"role Foo2 & Bar2, both have an attribute named foo");
}
{
{
package Foo3;
use Moose::Role;
sub foo {}
}
{
package Bar3;
use Moose::Role;
override 'foo' => sub {}
}
my $exception = exception {
package CompositeRole3;
use Moose::Role;
with 'Foo3', 'Bar3';
};
like(
$exception,
qr/\QRole 'Foo3|Bar3' has encountered an 'override' method conflict during composition (A local method of the same name has been found). This is a fatal error./,
"role Foo3 has a local method 'foo' & role Bar3 is overriding that same method");
isa_ok(
$exception,
"Moose::Exception::OverrideConflictInSummation",
"role Foo3 has a local method 'foo' & role Bar3 is overriding that same method");
my @role_names = $exception->role_names;
my $role_names = join "|", @role_names;
is(
$role_names,
"Foo3|Bar3",
"role Foo3 has a local method 'foo' & role Bar3 is overriding that same method");
is(
$exception->method_name,
"foo",
"role Foo3 has a local method 'foo' & role Bar3 is overriding that same method");
}
{
{
package Foo4;
use Moose::Role;
override 'foo' => sub {};
}
{
package Bar4;
use Moose::Role;
override 'foo' => sub {};
}
my $exception = exception {
package CompositeRole4;
use Moose::Role;
with 'Foo4', 'Bar4';
};
like(
$exception,
qr/\QWe have encountered an 'override' method conflict during composition (Two 'override' methods of the same name encountered). This is a fatal error./,
"role Foo4 & Bar4, both are overriding the same method 'foo'");
isa_ok(
$exception,
"Moose::Exception::OverrideConflictInSummation",
"role Foo4 & Bar4, both are overriding the same method 'foo'");
my @role_names = $exception->role_names;
my $role_names = join "|", @role_names;
is(
$role_names,
"Foo4|Bar4",
"role Foo4 & Bar4, both are overriding the same method 'foo'");
is(
$exception->method_name,
"foo",
"role Foo4 & Bar4, both are overriding the same method 'foo'");
}
done_testing;
|