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