Commit | Line | Data |
b099a649 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
b099a649 |
7 | |
8 | BEGIN { |
9 | use_ok('Moose::Util', ':all'); |
10 | } |
11 | |
12 | { |
13 | package Foo; |
14 | use Moose::Role; |
15 | } |
16 | |
17 | { |
18 | package Bar; |
19 | use Moose::Role; |
20 | } |
21 | |
22 | { |
23 | package Quux; |
24 | use Moose; |
25 | } |
26 | |
27 | is_deeply( |
28 | Quux->meta->roles, |
29 | [], |
30 | "no roles yet", |
31 | ); |
32 | |
33 | Foo->meta->apply(Quux->meta); |
34 | |
35 | is_deeply( |
36 | Quux->meta->roles, |
37 | [ Foo->meta ], |
38 | "applied Foo", |
39 | ); |
40 | |
41 | Foo->meta->apply(Quux->meta); |
42 | Bar->meta->apply(Quux->meta); |
43 | is_deeply( |
44 | Quux->meta->roles, |
45 | [ Foo->meta, Foo->meta, Bar->meta ], |
46 | "duplicated Foo", |
47 | ); |
48 | |
49 | is(does_role('Quux', 'Foo'), 1, "Quux does Foo"); |
50 | is(does_role('Quux', 'Bar'), 1, "Quux does Bar"); |
51 | ensure_all_roles('Quux', qw(Foo Bar)); |
52 | is_deeply( |
53 | Quux->meta->roles, |
54 | [ Foo->meta, Foo->meta, Bar->meta ], |
55 | "unchanged, since all roles are already applied", |
56 | ); |
57 | |
58 | my $obj = Quux->new; |
59 | ensure_all_roles($obj, qw(Foo Bar)); |
60 | is_deeply( |
61 | $obj->meta->roles, |
62 | [ Foo->meta, Foo->meta, Bar->meta ], |
63 | "unchanged, since all roles are already applied", |
64 | ); |
a28e50e4 |
65 | |
66 | done_testing; |