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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Moose::Util 'find_meta';
use Moose();
{
{
package Foo;
use Moose::Role;
excludes 'Bar';
}
{
package Bar;
use Moose::Role;
}
my $exception = exception {
Moose::Meta::Role::Application::ToRole->check_role_exclusions( Bar->meta, Foo->meta );
};
like(
$exception,
qr/\QConflict detected: Foo excludes role 'Bar'/,
'Role Foo excludes Role Bar');
isa_ok(
$exception,
"Moose::Exception::ConflictDetectedInCheckRoleExclusions",
'Role Foo excludes Role Bar');
is(
$exception->role_name,
"Foo",
'Role Foo excludes Role Bar');
is(
find_meta($exception->role_name),
Foo->meta,
'Role Foo excludes Role Bar');
is(
$exception->excluded_role_name,
"Bar",
'Role Foo excludes Role Bar');
is(
find_meta($exception->excluded_role_name),
Bar->meta,
'Role Foo excludes Role Bar');
}
{
{
package Foo2;
use Moose::Role;
excludes 'Bar3';
}
{
package Bar2;
use Moose::Role;
with 'Bar3';
}
{
package Bar3;
use Moose::Role;
}
my $exception = exception {
Moose::Meta::Role::Application::ToRole->check_role_exclusions( Foo2->meta, Bar2->meta );
};
like(
$exception,
qr/\QThe role Bar2 does the excluded role 'Bar3'/,
'Role Bar2 does Role Bar3');
isa_ok(
$exception,
"Moose::Exception::RoleDoesTheExcludedRole",
'Role Bar2 does Role Bar3');
is(
$exception->second_role_name,
"Foo2",
'Role Bar2 does Role Bar3');
is(
find_meta($exception->second_role_name),
Foo2->meta,
'Role Bar2 does Role Bar3');
is(
$exception->excluded_role_name,
"Bar3",
'Role Bar2 does Role Bar3');
is(
find_meta($exception->excluded_role_name),
Bar3->meta,
'Role Bar2 does Role Bar3');
is(
$exception->role_name,
"Bar2",
'Role Bar2 does Role Bar3');
is(
find_meta($exception->role_name),
Bar2->meta,
'Role Bar2 does Role Bar3');
}
{
{
package Foo4;
use Moose::Role;
has 'foo' => (
is => 'ro',
isa => 'Int'
);
}
{
package Bar4;
use Moose::Role;
has 'foo' => (
is => 'ro',
isa => 'Int'
);
}
my $exception = exception {
Moose::Meta::Role::Application::ToRole->apply_attributes( Foo4->meta, Bar4->meta );
};
like(
$exception,
qr/\QRole 'Foo4' has encountered an attribute conflict while being composed into 'Bar4'. This is a fatal error and cannot be disambiguated. The conflicting attribute is named 'foo'./,
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
isa_ok(
$exception,
"Moose::Exception::AttributeConflictInRoles",
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
is(
$exception->role_name,
"Foo4",
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
is(
find_meta($exception->role_name),
Foo4->meta,
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
is(
$exception->second_role_name,
"Bar4",
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
is(
find_meta($exception->second_role_name),
Bar4->meta,
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
is(
$exception->attribute_name,
'foo',
'Role Foo4 & Role Bar4 has one common attribute named "foo"');
}
{
{
package Foo5;
use Moose::Role;
sub foo5 { "foo" }
}
my $exception = exception {
{
package Bar5;
use Moose::Role;
with 'Foo5' => {
-alias => { foo5 => 'foo_in_bar' }
};
sub foo_in_bar { "test in foo" }
}
};
like(
$exception,
qr/\QCannot create a method alias if a local method of the same name exists/,
"Role Bar5 already has a method named foo_in_bar");
isa_ok(
$exception,
"Moose::Exception::CannotCreateMethodAliasLocalMethodIsPresent",
"Role Bar5 already has a method named foo_in_bar");
is(
$exception->role_name,
"Bar5",
"Role Bar5 already has a method named foo_in_bar");
is(
find_meta($exception->role_name),
Bar5->meta,
"Role Bar5 already has a method named foo_in_bar");
is(
$exception->role_being_applied_name,
"Foo5",
"Role Bar5 already has a method named foo_in_bar");
is(
find_meta($exception->role_being_applied_name),
Foo5->meta,
"Role Bar5 already has a method named foo_in_bar");
is(
$exception->aliased_method_name,
"foo_in_bar",
"Role Bar5 already has a method named foo_in_bar");
is(
$exception->method->name,
"foo5",
"Role Bar5 already has a method named foo_in_bar");
}
{
{
package Foo6;
use Moose::Role;
override foo6 => sub { "override foo6" };
}
my $exception = exception {
{
package Bar6;
use Moose::Role;
with 'Foo6';
sub foo6 { "test in foo6" }
}
};
like(
$exception,
qr/\QRole 'Foo6' has encountered an 'override' method conflict during composition (A local method of the same name as been found). This is a fatal error./,
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
isa_ok(
$exception,
"Moose::Exception::OverrideConflictInComposition",
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
is(
$exception->role_name,
"Bar6",
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
is(
find_meta($exception->role_name),
Bar6->meta,
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
is(
$exception->role_being_applied_name,
"Foo6",
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
is(
find_meta($exception->role_being_applied_name),
Foo6->meta,
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
is(
$exception->method_name,
"foo6",
"Role Foo6 is overriding a method named foo6, which is a local method in Bar6");
}
{
{
package Foo7;
use Moose::Role;
override foo7 => sub { "override foo7" };
}
my $exception = exception {
{
package Bar7;
use Moose::Role;
override foo7 => sub { "override foo7 in Bar7" };
with 'Foo7';
}
};
like(
$exception,
qr/\QRole 'Foo7' has encountered an 'override' method conflict during composition (Two 'override' methods of the same name encountered). This is a fatal error./,
"Roles Foo7 & Bar7, both have override foo7");
isa_ok(
$exception,
"Moose::Exception::OverrideConflictInComposition",
"Roles Foo7 & Bar7, both have override foo7");
is(
$exception->role_name,
"Bar7",
"Roles Foo7 & Bar7, both have override foo7");
is(
find_meta($exception->role_name),
Bar7->meta,
"Roles Foo7 & Bar7, both have override foo7");
is(
$exception->role_being_applied_name,
"Foo7",
"Roles Foo7 & Bar7, both have override foo7");
is(
find_meta($exception->role_being_applied_name),
Foo7->meta,
"Roles Foo7 & Bar7, both have override foo7");
is(
$exception->method_name,
"foo7",
"Roles Foo7 & Bar7, both have override foo7");
}
done_testing;
|