Commit | Line | Data |
67199842 |
1 | #!/usr/bin/perl |
fde8e43f |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
67199842 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
fde8e43f |
9 | use Test::More; |
67199842 |
10 | use Test::Exception; |
11 | |
12 | =pod |
13 | |
6cfa1e5e |
14 | Check for repeated inheritance causing |
15 | a method conflict (which is not really |
67199842 |
16 | a conflict) |
17 | |
18 | =cut |
19 | |
20 | { |
21 | package Role::Base; |
22 | use Mouse::Role; |
6cfa1e5e |
23 | |
67199842 |
24 | sub foo { 'Role::Base::foo' } |
6cfa1e5e |
25 | |
67199842 |
26 | package Role::Derived1; |
6cfa1e5e |
27 | use Mouse::Role; |
28 | |
67199842 |
29 | with 'Role::Base'; |
6cfa1e5e |
30 | |
67199842 |
31 | package Role::Derived2; |
6cfa1e5e |
32 | use Mouse::Role; |
67199842 |
33 | |
34 | with 'Role::Base'; |
6cfa1e5e |
35 | |
67199842 |
36 | package My::Test::Class1; |
6cfa1e5e |
37 | use Mouse; |
38 | |
67199842 |
39 | ::lives_ok { |
6cfa1e5e |
40 | with 'Role::Derived1', 'Role::Derived2'; |
67199842 |
41 | } '... roles composed okay (no conflicts)'; |
42 | } |
43 | |
44 | ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected'); |
45 | ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected'); |
46 | ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected'); |
47 | ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected'); |
48 | |
49 | is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method'); |
50 | |
51 | =pod |
52 | |
6cfa1e5e |
53 | Check for repeated inheritance causing |
54 | a method conflict with method modifiers |
67199842 |
55 | (which is not really a conflict) |
56 | |
57 | =cut |
58 | |
59 | { |
60 | package Role::Base2; |
61 | use Mouse::Role; |
6cfa1e5e |
62 | |
67199842 |
63 | override 'foo' => sub { super() . ' -> Role::Base::foo' }; |
6cfa1e5e |
64 | |
67199842 |
65 | package Role::Derived3; |
6cfa1e5e |
66 | use Mouse::Role; |
67 | |
67199842 |
68 | with 'Role::Base2'; |
6cfa1e5e |
69 | |
67199842 |
70 | package Role::Derived4; |
6cfa1e5e |
71 | use Mouse::Role; |
67199842 |
72 | |
73 | with 'Role::Base2'; |
74 | |
75 | package My::Test::Class2::Base; |
76 | use Mouse; |
6cfa1e5e |
77 | |
67199842 |
78 | sub foo { 'My::Test::Class2::Base' } |
6cfa1e5e |
79 | |
67199842 |
80 | package My::Test::Class2; |
6cfa1e5e |
81 | use Mouse; |
82 | |
83 | extends 'My::Test::Class2::Base'; |
84 | |
67199842 |
85 | ::lives_ok { |
6cfa1e5e |
86 | with 'Role::Derived3', 'Role::Derived4'; |
67199842 |
87 | } '... roles composed okay (no conflicts)'; |
88 | } |
89 | |
90 | ok(Role::Base2->meta->has_override_method_modifier('foo'), '... have the method foo as expected'); |
91 | ok(Role::Derived3->meta->has_override_method_modifier('foo'), '... have the method foo as expected'); |
92 | ok(Role::Derived4->meta->has_override_method_modifier('foo'), '... have the method foo as expected'); |
93 | ok(My::Test::Class2->meta->has_method('foo'), '... have the method foo as expected'); |
fde8e43f |
94 | isa_ok(My::Test::Class2->meta->get_method('foo'), 'Mouse::Meta::Method'); |
67199842 |
95 | ok(My::Test::Class2::Base->meta->has_method('foo'), '... have the method foo as expected'); |
fde8e43f |
96 | isa_ok(My::Test::Class2::Base->meta->get_method('foo'), 'Mouse::Meta::Method'); |
97 | |
67199842 |
98 | is(My::Test::Class2::Base->foo, 'My::Test::Class2::Base', '... got the right value from method'); |
99 | is(My::Test::Class2->foo, 'My::Test::Class2::Base -> Role::Base::foo', '... got the right value from method'); |
100 | |
101 | =pod |
102 | |
6cfa1e5e |
103 | Check for repeated inheritance of the |
104 | same code. There are no conflicts with |
67199842 |
105 | before/around/after method modifiers. |
106 | |
6cfa1e5e |
107 | This tests around, but should work the |
67199842 |
108 | same for before/afters as well |
109 | |
110 | =cut |
111 | |
112 | { |
113 | package Role::Base3; |
114 | use Mouse::Role; |
6cfa1e5e |
115 | |
67199842 |
116 | around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' }; |
6cfa1e5e |
117 | |
67199842 |
118 | package Role::Derived5; |
6cfa1e5e |
119 | use Mouse::Role; |
120 | |
67199842 |
121 | with 'Role::Base3'; |
6cfa1e5e |
122 | |
67199842 |
123 | package Role::Derived6; |
6cfa1e5e |
124 | use Mouse::Role; |
67199842 |
125 | |
126 | with 'Role::Base3'; |
127 | |
128 | package My::Test::Class3::Base; |
129 | use Mouse; |
6cfa1e5e |
130 | |
67199842 |
131 | sub foo { 'My::Test::Class3::Base' } |
6cfa1e5e |
132 | |
67199842 |
133 | package My::Test::Class3; |
6cfa1e5e |
134 | use Mouse; |
135 | |
136 | extends 'My::Test::Class3::Base'; |
137 | |
67199842 |
138 | ::lives_ok { |
6cfa1e5e |
139 | with 'Role::Derived5', 'Role::Derived6'; |
67199842 |
140 | } '... roles composed okay (no conflicts)'; |
141 | } |
142 | |
143 | ok(Role::Base3->meta->has_around_method_modifiers('foo'), '... have the method foo as expected'); |
144 | ok(Role::Derived5->meta->has_around_method_modifiers('foo'), '... have the method foo as expected'); |
145 | ok(Role::Derived6->meta->has_around_method_modifiers('foo'), '... have the method foo as expected'); |
146 | ok(My::Test::Class3->meta->has_method('foo'), '... have the method foo as expected'); |
fde8e43f |
147 | isa_ok(My::Test::Class3->meta->get_method('foo'), 'Mouse::Meta::Method'); |
67199842 |
148 | ok(My::Test::Class3::Base->meta->has_method('foo'), '... have the method foo as expected'); |
fde8e43f |
149 | isa_ok(My::Test::Class3::Base->meta->get_method('foo'), 'Mouse::Meta::Method'); |
150 | |
67199842 |
151 | is(My::Test::Class3::Base->foo, 'My::Test::Class3::Base', '... got the right value from method'); |
152 | is(My::Test::Class3->foo, 'Role::Base::foo(My::Test::Class3::Base)', '... got the right value from method'); |
153 | |
154 | =pod |
155 | |
6cfa1e5e |
156 | Check for repeated inheritance causing |
157 | a attr conflict (which is not really |
67199842 |
158 | a conflict) |
159 | |
160 | =cut |
161 | |
162 | { |
163 | package Role::Base4; |
164 | use Mouse::Role; |
6cfa1e5e |
165 | |
67199842 |
166 | has 'foo' => (is => 'ro', default => 'Role::Base::foo'); |
6cfa1e5e |
167 | |
67199842 |
168 | package Role::Derived7; |
6cfa1e5e |
169 | use Mouse::Role; |
170 | |
67199842 |
171 | with 'Role::Base4'; |
6cfa1e5e |
172 | |
67199842 |
173 | package Role::Derived8; |
6cfa1e5e |
174 | use Mouse::Role; |
67199842 |
175 | |
176 | with 'Role::Base4'; |
6cfa1e5e |
177 | |
67199842 |
178 | package My::Test::Class4; |
6cfa1e5e |
179 | use Mouse; |
180 | |
67199842 |
181 | ::lives_ok { |
6cfa1e5e |
182 | with 'Role::Derived7', 'Role::Derived8'; |
67199842 |
183 | } '... roles composed okay (no conflicts)'; |
184 | } |
185 | |
186 | ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected'); |
187 | ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected'); |
188 | ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected'); |
189 | ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected'); |
190 | |
191 | is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method'); |
fde8e43f |
192 | |
193 | done_testing; |