Commit | Line | Data |
a5eca695 |
1 | use strict; |
2 | use warnings; |
3 | |
86a4d873 |
4 | use Test::More; |
a5eca695 |
5 | use Test::Exception; |
6 | |
efd3d14c |
7 | use Class::MOP; |
8 | use Class::MOP::Class; |
9 | use Class::MOP::Package; |
10 | use Class::MOP::Module; |
a5eca695 |
11 | |
013b1897 |
12 | { |
13 | my $class = Class::MOP::Class->initialize('Foo'); |
14 | is($class->meta, Class::MOP::Class->meta, '... instance and class both lead to the same meta'); |
15 | } |
16 | |
6d5355c3 |
17 | my $class_mop_class_meta = Class::MOP::Class->meta(); |
18 | isa_ok($class_mop_class_meta, 'Class::MOP::Class'); |
a5eca695 |
19 | |
6d5355c3 |
20 | my $class_mop_package_meta = Class::MOP::Package->meta(); |
21 | isa_ok($class_mop_package_meta, 'Class::MOP::Package'); |
22 | |
23 | my $class_mop_module_meta = Class::MOP::Module->meta(); |
24 | isa_ok($class_mop_module_meta, 'Class::MOP::Module'); |
25 | |
26 | my @class_mop_package_methods = qw( |
6c2f6b5c |
27 | _new |
6d5355c3 |
28 | |
a19fcb5b |
29 | initialize reinitialize |
6d5355c3 |
30 | |
31 | name |
a5e51f0b |
32 | namespace |
0ac992ee |
33 | |
34 | add_package_symbol get_package_symbol has_package_symbol remove_package_symbol |
ae234dc6 |
35 | list_all_package_symbols get_all_package_symbols remove_package_glob |
0ac992ee |
36 | |
b1ff395f |
37 | method_metaclass wrapped_method_metaclass |
38 | |
4eb970b2 |
39 | _method_map |
40 | _code_is_mine |
b1ff395f |
41 | has_method get_method add_method remove_method wrap_method_body |
241646a3 |
42 | get_method_list _full_method_map |
b1ff395f |
43 | |
a5e51f0b |
44 | _deconstruct_variable_name |
b409c969 |
45 | |
46 | get_method_map |
6d5355c3 |
47 | ); |
48 | |
49 | my @class_mop_module_methods = qw( |
6c2f6b5c |
50 | _new |
7f436b8c |
51 | |
89f66023 |
52 | _instantiate_module |
53 | |
4edd0667 |
54 | version authority identifier create |
6d5355c3 |
55 | ); |
56 | |
57 | my @class_mop_class_methods = qw( |
6c2f6b5c |
58 | _new |
0ac992ee |
59 | |
cc67d48a |
60 | is_pristine |
61 | |
a19fcb5b |
62 | initialize create |
86a4d873 |
63 | |
715adbb7 |
64 | update_package_cache_flag |
e0e4674a |
65 | reset_package_cache_flag |
0ac992ee |
66 | |
b9d9fc0b |
67 | create_anon_class is_anon_class |
0ac992ee |
68 | |
27e95ba5 |
69 | instance_metaclass get_meta_instance |
70 | create_meta_instance _create_meta_instance |
7b31baf4 |
71 | new_object clone_object |
d69fb6b3 |
72 | construct_instance _construct_instance |
3c0ad733 |
73 | construct_class_instance _construct_class_instance |
d379f552 |
74 | clone_instance _clone_instance |
9f363af3 |
75 | rebless_instance rebless_instance_away |
11a8a2c1 |
76 | check_metaclass_compatibility _check_metaclass_compatibility |
0ac992ee |
77 | |
c3f935e1 |
78 | add_meta_instance_dependencies remove_meta_instance_dependencies update_meta_instance_dependencies |
da5680be |
79 | add_dependent_meta_instance remove_dependent_meta_instance |
caab0eaa |
80 | invalidate_meta_instances invalidate_meta_instance |
81 | |
b1ff395f |
82 | attribute_metaclass |
0ac992ee |
83 | |
462ed2c0 |
84 | superclasses subclasses direct_subclasses class_precedence_list |
b53f14fa |
85 | linearized_isa _superclasses_updated |
0ac992ee |
86 | |
b1ff395f |
87 | alias_method get_all_method_names get_all_methods compute_all_applicable_methods |
0ac992ee |
88 | find_method_by_name find_all_methods_by_name find_next_method_by_name |
89 | |
90 | add_before_method_modifier add_after_method_modifier add_around_method_modifier |
ee5e71d4 |
91 | |
552e3d24 |
92 | has_attribute get_attribute add_attribute remove_attribute |
b1aaf0dc |
93 | get_attribute_list _attribute_map get_all_attributes compute_all_applicable_attributes find_attribute_by_name |
94 | |
95 | get_attribute_map |
0ac992ee |
96 | |
44d6ea77 |
97 | is_mutable is_immutable make_mutable make_immutable |
f5d08022 |
98 | _initialize_immutable _install_inlined_code _inlined_methods |
99 | _add_inlined_method _inline_accessors _inline_constructor |
100 | _inline_destructor _immutable_options _rebless_as_immutable |
101 | _rebless_as_mutable _remove_inlined_code |
102 | |
e1c7a1b7 |
103 | _immutable_metaclass |
28443f51 |
104 | immutable_trait immutable_options |
105 | constructor_name constructor_class destructor_class |
f5d08022 |
106 | |
77e5fce4 |
107 | DESTROY |
7f436b8c |
108 | ); |
0ac992ee |
109 | |
110 | # check the class ... |
111 | |
c0ae440b |
112 | is_deeply([ sort $class_mop_class_meta->get_method_list ], [ sort @class_mop_class_methods ], '... got the correct method list for class'); |
7b31baf4 |
113 | |
0586121e |
114 | foreach my $method_name (sort @class_mop_class_methods) { |
6d5355c3 |
115 | ok($class_mop_class_meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')'); |
a5eca695 |
116 | { |
117 | no strict 'refs'; |
0ac992ee |
118 | is($class_mop_class_meta->get_method($method_name)->body, |
a5eca695 |
119 | \&{'Class::MOP::Class::' . $method_name}, |
0ac992ee |
120 | '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name); |
a5eca695 |
121 | } |
122 | } |
123 | |
6d5355c3 |
124 | ## check the package .... |
125 | |
c0ae440b |
126 | is_deeply([ sort $class_mop_package_meta->get_method_list ], [ sort @class_mop_package_methods ], '... got the correct method list for package'); |
6d5355c3 |
127 | |
0586121e |
128 | foreach my $method_name (sort @class_mop_package_methods) { |
6d5355c3 |
129 | ok($class_mop_package_meta->has_method($method_name), '... Class::MOP::Package->has_method(' . $method_name . ')'); |
130 | { |
131 | no strict 'refs'; |
0ac992ee |
132 | is($class_mop_package_meta->get_method($method_name)->body, |
6d5355c3 |
133 | \&{'Class::MOP::Package::' . $method_name}, |
0ac992ee |
134 | '... Class::MOP::Package->get_method(' . $method_name . ') == &Class::MOP::Package::' . $method_name); |
6d5355c3 |
135 | } |
136 | } |
137 | |
7f436b8c |
138 | ## check the module .... |
139 | |
c0ae440b |
140 | is_deeply([ sort $class_mop_module_meta->get_method_list ], [ sort @class_mop_module_methods ], '... got the correct method list for module'); |
7f436b8c |
141 | |
0586121e |
142 | foreach my $method_name (sort @class_mop_module_methods) { |
7f436b8c |
143 | ok($class_mop_module_meta->has_method($method_name), '... Class::MOP::Module->has_method(' . $method_name . ')'); |
144 | { |
145 | no strict 'refs'; |
0ac992ee |
146 | is($class_mop_module_meta->get_method($method_name)->body, |
7f436b8c |
147 | \&{'Class::MOP::Module::' . $method_name}, |
0ac992ee |
148 | '... Class::MOP::Module->get_method(' . $method_name . ') == &Class::MOP::Module::' . $method_name); |
7f436b8c |
149 | } |
150 | } |
151 | |
152 | |
7b31baf4 |
153 | # check for imported functions which are not methods |
154 | |
2eb717d5 |
155 | foreach my $non_method_name (qw( |
156 | confess |
9b522fc4 |
157 | blessed |
2eb717d5 |
158 | subname |
159 | svref_2object |
160 | )) { |
0ac992ee |
161 | ok(!$class_mop_class_meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')'); |
2eb717d5 |
162 | } |
163 | |
7b31baf4 |
164 | # check for the right attributes |
165 | |
6d5355c3 |
166 | my @class_mop_package_attributes = ( |
8683db0e |
167 | 'package', |
168 | 'namespace', |
b1ff395f |
169 | 'method_metaclass', |
170 | 'wrapped_method_metaclass', |
bcef1f7c |
171 | '_methods', |
6d5355c3 |
172 | ); |
173 | |
174 | my @class_mop_module_attributes = ( |
8683db0e |
175 | 'version', |
176 | 'authority' |
6d5355c3 |
177 | ); |
178 | |
179 | my @class_mop_class_attributes = ( |
8683db0e |
180 | 'superclasses', |
8683db0e |
181 | 'attributes', |
182 | 'attribute_metaclass', |
44d6ea77 |
183 | 'instance_metaclass', |
f5d08022 |
184 | 'immutable_trait', |
185 | 'constructor_name', |
186 | 'constructor_class', |
187 | 'destructor_class', |
2bab2be6 |
188 | ); |
7b31baf4 |
189 | |
6d5355c3 |
190 | # check class |
191 | |
7b31baf4 |
192 | is_deeply( |
6d5355c3 |
193 | [ sort $class_mop_class_meta->get_attribute_list ], |
c0ae440b |
194 | [ sort @class_mop_class_attributes ], |
195 | '... got the right list of attributes' |
196 | ); |
0ac992ee |
197 | |
7b31baf4 |
198 | is_deeply( |
b1aaf0dc |
199 | [ sort keys %{$class_mop_class_meta->_attribute_map} ], |
c0ae440b |
200 | [ sort @class_mop_class_attributes ], |
0ac992ee |
201 | '... got the right list of attributes'); |
7b31baf4 |
202 | |
0586121e |
203 | foreach my $attribute_name (sort @class_mop_class_attributes) { |
0ac992ee |
204 | ok($class_mop_class_meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')'); |
205 | isa_ok($class_mop_class_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); |
6d5355c3 |
206 | } |
207 | |
7f436b8c |
208 | # check module |
6d5355c3 |
209 | |
210 | is_deeply( |
6d5355c3 |
211 | [ sort $class_mop_package_meta->get_attribute_list ], |
c0ae440b |
212 | [ sort @class_mop_package_attributes ], |
6d5355c3 |
213 | '... got the right list of attributes'); |
0ac992ee |
214 | |
6d5355c3 |
215 | is_deeply( |
b1aaf0dc |
216 | [ sort keys %{$class_mop_package_meta->_attribute_map} ], |
c0ae440b |
217 | [ sort @class_mop_package_attributes ], |
0ac992ee |
218 | '... got the right list of attributes'); |
6d5355c3 |
219 | |
0586121e |
220 | foreach my $attribute_name (sort @class_mop_package_attributes) { |
0ac992ee |
221 | ok($class_mop_package_meta->has_attribute($attribute_name), '... Class::MOP::Package->has_attribute(' . $attribute_name . ')'); |
222 | isa_ok($class_mop_package_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); |
727919c5 |
223 | } |
224 | |
0ac992ee |
225 | # check package |
7f436b8c |
226 | |
227 | is_deeply( |
7f436b8c |
228 | [ sort $class_mop_module_meta->get_attribute_list ], |
c0ae440b |
229 | [ sort @class_mop_module_attributes ], |
7f436b8c |
230 | '... got the right list of attributes'); |
0ac992ee |
231 | |
7f436b8c |
232 | is_deeply( |
b1aaf0dc |
233 | [ sort keys %{$class_mop_module_meta->_attribute_map} ], |
c0ae440b |
234 | [ sort @class_mop_module_attributes ], |
0ac992ee |
235 | '... got the right list of attributes'); |
7f436b8c |
236 | |
0586121e |
237 | foreach my $attribute_name (sort @class_mop_module_attributes) { |
0ac992ee |
238 | ok($class_mop_module_meta->has_attribute($attribute_name), '... Class::MOP::Module->has_attribute(' . $attribute_name . ')'); |
239 | isa_ok($class_mop_module_meta->get_attribute($attribute_name), 'Class::MOP::Attribute'); |
7f436b8c |
240 | } |
241 | |
7b31baf4 |
242 | ## check the attributes themselves |
243 | |
6d5355c3 |
244 | # ... package |
245 | |
8683db0e |
246 | ok($class_mop_package_meta->get_attribute('package')->has_reader, '... Class::MOP::Class package has a reader'); |
247 | is(ref($class_mop_package_meta->get_attribute('package')->reader), 'HASH', '... Class::MOP::Class package\'s a reader is { name => sub { ... } }'); |
6d5355c3 |
248 | |
8683db0e |
249 | ok($class_mop_package_meta->get_attribute('package')->has_init_arg, '... Class::MOP::Class package has a init_arg'); |
250 | is($class_mop_package_meta->get_attribute('package')->init_arg, 'package', '... Class::MOP::Class package\'s a init_arg is package'); |
7b31baf4 |
251 | |
b1ff395f |
252 | ok($class_mop_package_meta->get_attribute('method_metaclass')->has_reader, '... Class::MOP::Package method_metaclass has a reader'); |
253 | is_deeply($class_mop_package_meta->get_attribute('method_metaclass')->reader, |
254 | { 'method_metaclass' => \&Class::MOP::Package::method_metaclass }, |
255 | '... Class::MOP::Package method_metaclass\'s a reader is &method_metaclass'); |
256 | |
257 | ok($class_mop_package_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Package method_metaclass has a init_arg'); |
258 | is($class_mop_package_meta->get_attribute('method_metaclass')->init_arg, |
259 | 'method_metaclass', |
260 | '... Class::MOP::Package method_metaclass\'s init_arg is method_metaclass'); |
261 | |
262 | ok($class_mop_package_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default'); |
263 | is($class_mop_package_meta->get_attribute('method_metaclass')->default, |
264 | 'Class::MOP::Method', |
265 | '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); |
266 | |
267 | ok($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->has_reader, '... Class::MOP::Package wrapped_method_metaclass has a reader'); |
268 | is_deeply($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->reader, |
269 | { 'wrapped_method_metaclass' => \&Class::MOP::Package::wrapped_method_metaclass }, |
270 | '... Class::MOP::Package wrapped_method_metaclass\'s a reader is &wrapped_method_metaclass'); |
271 | |
272 | ok($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Package wrapped_method_metaclass has a init_arg'); |
273 | is($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->init_arg, |
274 | 'wrapped_method_metaclass', |
275 | '... Class::MOP::Package wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass'); |
276 | |
277 | ok($class_mop_package_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default'); |
278 | is($class_mop_package_meta->get_attribute('method_metaclass')->default, |
279 | 'Class::MOP::Method', |
280 | '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); |
281 | |
282 | |
6d5355c3 |
283 | # ... class |
7b31baf4 |
284 | |
8683db0e |
285 | ok($class_mop_class_meta->get_attribute('attributes')->has_reader, '... Class::MOP::Class attributes has a reader'); |
286 | is_deeply($class_mop_class_meta->get_attribute('attributes')->reader, |
b1aaf0dc |
287 | { '_attribute_map' => \&Class::MOP::Class::_attribute_map }, |
288 | '... Class::MOP::Class attributes\'s a reader is &_attribute_map'); |
0ac992ee |
289 | |
8683db0e |
290 | ok($class_mop_class_meta->get_attribute('attributes')->has_init_arg, '... Class::MOP::Class attributes has a init_arg'); |
291 | is($class_mop_class_meta->get_attribute('attributes')->init_arg, |
0ac992ee |
292 | 'attributes', |
8683db0e |
293 | '... Class::MOP::Class attributes\'s a init_arg is attributes'); |
0ac992ee |
294 | |
8683db0e |
295 | ok($class_mop_class_meta->get_attribute('attributes')->has_default, '... Class::MOP::Class attributes has a default'); |
296 | is_deeply($class_mop_class_meta->get_attribute('attributes')->default('Foo'), |
0ac992ee |
297 | {}, |
8683db0e |
298 | '... Class::MOP::Class attributes\'s a default of {}'); |
7b31baf4 |
299 | |
8683db0e |
300 | ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_reader, '... Class::MOP::Class attribute_metaclass has a reader'); |
301 | is_deeply($class_mop_class_meta->get_attribute('attribute_metaclass')->reader, |
0ac992ee |
302 | { 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass }, |
8683db0e |
303 | '... Class::MOP::Class attribute_metaclass\'s a reader is &attribute_metaclass'); |
0ac992ee |
304 | |
8683db0e |
305 | ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_init_arg, '... Class::MOP::Class attribute_metaclass has a init_arg'); |
306 | is($class_mop_class_meta->get_attribute('attribute_metaclass')->init_arg, |
0ac992ee |
307 | 'attribute_metaclass', |
8683db0e |
308 | '... Class::MOP::Class attribute_metaclass\'s a init_arg is attribute_metaclass'); |
0ac992ee |
309 | |
8683db0e |
310 | ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_default, '... Class::MOP::Class attribute_metaclass has a default'); |
311 | is($class_mop_class_meta->get_attribute('attribute_metaclass')->default, |
0ac992ee |
312 | 'Class::MOP::Attribute', |
8683db0e |
313 | '... Class::MOP::Class attribute_metaclass\'s a default is Class::MOP:::Attribute'); |
0ac992ee |
314 | |
7b31baf4 |
315 | # check the values of some of the methods |
316 | |
6d5355c3 |
317 | is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name'); |
318 | is($class_mop_class_meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version'); |
a5eca695 |
319 | |
58d75218 |
320 | ok($class_mop_class_meta->has_package_symbol('$VERSION'), '... Class::MOP::Class->has_package_symbol($VERSION)'); |
0ac992ee |
321 | is(${$class_mop_class_meta->get_package_symbol('$VERSION')}, |
322 | $Class::MOP::Class::VERSION, |
58d75218 |
323 | '... Class::MOP::Class->get_package_symbol($VERSION)'); |
7b31baf4 |
324 | |
a5eca695 |
325 | is_deeply( |
0ac992ee |
326 | [ $class_mop_class_meta->superclasses ], |
327 | [ qw/Class::MOP::Module/ ], |
2243a22b |
328 | '... Class::MOP::Class->superclasses == [ Class::MOP::Module ]'); |
0ac992ee |
329 | |
a5eca695 |
330 | is_deeply( |
0ac992ee |
331 | [ $class_mop_class_meta->class_precedence_list ], |
2243a22b |
332 | [ qw/ |
333 | Class::MOP::Class |
334 | Class::MOP::Module |
0ac992ee |
335 | Class::MOP::Package |
336 | Class::MOP::Object |
337 | / ], |
2243a22b |
338 | '... Class::MOP::Class->class_precedence_list == [ Class::MOP::Class Class::MOP::Module Class::MOP::Package ]'); |
a5eca695 |
339 | |
6d5355c3 |
340 | is($class_mop_class_meta->attribute_metaclass, 'Class::MOP::Attribute', '... got the right value for attribute_metaclass'); |
341 | is($class_mop_class_meta->method_metaclass, 'Class::MOP::Method', '... got the right value for method_metaclass'); |
342 | is($class_mop_class_meta->instance_metaclass, 'Class::MOP::Instance', '... got the right value for instance_metaclass'); |
7b31baf4 |
343 | |
86a4d873 |
344 | done_testing; |