Commit | Line | Data |
086c223b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
f650b4b2 |
4 | use Test::More tests => 11; |
69ac1dcf |
5 | use Test::Exception; |
086c223b |
6 | |
7 | do { |
8 | package Role; |
9 | use Mouse::Role; |
10 | |
69ac1dcf |
11 | has 'attr' => ( |
12 | default => 'Role', |
13 | ); |
086c223b |
14 | |
15 | no Mouse::Role; |
16 | }; |
17 | |
69ac1dcf |
18 | is_deeply(Role->meta->get_attribute('attr'), {default => 'Role'}); |
19 | |
086c223b |
20 | do { |
21 | package Class; |
22 | use Mouse; |
23 | with 'Role'; |
24 | |
25 | no Mouse; |
26 | }; |
27 | |
28 | ok(Class->meta->has_attribute('attr'), "role application added the attribute"); |
69ac1dcf |
29 | is(Class->meta->get_attribute('attr')->default, 'Role'); |
30 | |
31 | do { |
32 | package Role2; |
33 | use Mouse::Role; |
34 | |
35 | has 'attr' => ( |
36 | default => 'Role2', |
37 | ); |
38 | |
39 | no Mouse::Role; |
40 | }; |
41 | |
42 | lives_ok { |
43 | package Class2; |
44 | use Mouse; |
45 | with 'Role'; |
46 | with 'Role2'; |
47 | }; |
48 | |
0ba3591e |
49 | is(Class2->meta->get_attribute('attr')->default, 'Role'); |
086c223b |
50 | |
f650b4b2 |
51 | lives_ok { |
52 | package Class3; |
53 | use Mouse; |
54 | |
55 | with 'Role'; |
56 | |
57 | has attr => ( |
58 | default => 'Class3', |
59 | ); |
60 | }; |
61 | |
62 | is(Class3->meta->get_attribute('attr')->default, 'Class3'); |
63 | |
64 | lives_ok { |
65 | package Class::Parent; |
66 | use Mouse; |
67 | |
68 | has attr => ( |
69 | default => 'Class::Parent', |
70 | ); |
71 | }; |
72 | |
73 | is(Class::Parent->meta->get_attribute('attr')->default, 'Class::Parent', 'local class wins over the role'); |
74 | |
75 | lives_ok { |
76 | package Class::Child; |
77 | use Mouse; |
78 | |
79 | extends 'Class::Parent'; |
80 | |
81 | with 'Role'; |
82 | }; |
83 | |
84 | is(Class::Child->meta->get_attribute('attr')->default, 'Role', 'role wins over the parent method'); |