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