9 use Class::MOP::Package;
10 use Class::MOP::Module;
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');
17 my $class_mop_class_meta = Class::MOP::Class->meta();
18 isa_ok($class_mop_class_meta, 'Class::MOP::Class');
20 my $class_mop_package_meta = Class::MOP::Package->meta();
21 isa_ok($class_mop_package_meta, 'Class::MOP::Package');
23 my $class_mop_module_meta = Class::MOP::Module->meta();
24 isa_ok($class_mop_module_meta, 'Class::MOP::Module');
26 my @class_mop_package_methods = qw(
29 initialize reinitialize
34 add_package_symbol get_package_symbol has_package_symbol
35 remove_package_symbol get_or_add_package_symbol
36 list_all_package_symbols get_all_package_symbols remove_package_glob
43 my @class_mop_module_methods = qw(
48 version authority identifier create
51 my @class_mop_class_methods = qw(
56 initialize reinitialize create
58 create_anon_class is_anon_class free_anon_class
60 instance_metaclass get_meta_instance
61 _inline_create_instance
62 _inline_rebless_instance
63 _inline_get_mop_slot _inline_set_mop_slot _inline_clear_mop_slot
64 create_meta_instance _create_meta_instance
65 new_object clone_object
66 _inline_new_object _inline_default_value _inline_preserve_weak_metaclasses
67 _inline_slot_initializer _inline_extra_init _inline_fallback_constructor
68 _inline_generate_instance _inline_params _inline_slot_initializers
69 _inline_init_attr_from_constructor _inline_init_attr_from_default
70 _generate_fallback_constructor
71 construct_instance _construct_instance
72 construct_class_instance _construct_class_instance
73 clone_instance _clone_instance
74 rebless_instance rebless_instance_back rebless_instance_away
75 _force_rebless_instance _fixup_attributes_after_rebless
76 check_metaclass_compatibility _check_metaclass_compatibility
77 _check_class_metaclass_compatibility _check_single_metaclass_compatibility
78 _class_metaclass_is_compatible _single_metaclass_is_compatible
79 _fix_metaclass_incompatibility _fix_class_metaclass_incompatibility
80 _fix_single_metaclass_incompatibility _base_metaclasses
81 _can_fix_metaclass_incompatibility
82 _class_metaclass_can_be_made_compatible
83 _single_metaclass_can_be_made_compatible
85 _remove_generated_metaobjects
86 _restore_metaobjects_from
88 add_meta_instance_dependencies remove_meta_instance_dependencies update_meta_instance_dependencies
89 add_dependent_meta_instance remove_dependent_meta_instance
90 invalidate_meta_instances invalidate_meta_instance
92 superclasses subclasses direct_subclasses class_precedence_list
93 linearized_isa _superclasses_updated _superclass_metas
95 alias_method get_all_method_names get_all_methods compute_all_applicable_methods
96 find_method_by_name find_all_methods_by_name find_next_method_by_name
98 add_before_method_modifier add_after_method_modifier add_around_method_modifier
103 find_attribute_by_name
106 compute_all_applicable_attributes
109 is_mutable is_immutable make_mutable make_immutable
110 _initialize_immutable _install_inlined_code _inlined_methods
111 _add_inlined_method _inline_accessors _inline_constructor
112 _inline_destructor _immutable_options _real_ref_name
113 _rebless_as_immutable _rebless_as_mutable _remove_inlined_code
116 immutable_trait immutable_options
117 constructor_name constructor_class destructor_class
122 # check the class ...
124 is_deeply([ sort $class_mop_class_meta->get_method_list ], [ sort @class_mop_class_methods ], '... got the correct method list for class');
126 foreach my $method_name (sort @class_mop_class_methods) {
127 ok($class_mop_class_meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
130 is($class_mop_class_meta->get_method($method_name)->body,
131 \&{'Class::MOP::Class::' . $method_name},
132 '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name);
136 ## check the package ....
138 is_deeply([ sort $class_mop_package_meta->get_method_list ], [ sort @class_mop_package_methods ], '... got the correct method list for package');
140 foreach my $method_name (sort @class_mop_package_methods) {
141 ok($class_mop_package_meta->has_method($method_name), '... Class::MOP::Package->has_method(' . $method_name . ')');
144 is($class_mop_package_meta->get_method($method_name)->body,
145 \&{'Class::MOP::Package::' . $method_name},
146 '... Class::MOP::Package->get_method(' . $method_name . ') == &Class::MOP::Package::' . $method_name);
150 ## check the module ....
152 is_deeply([ sort $class_mop_module_meta->get_method_list ], [ sort @class_mop_module_methods ], '... got the correct method list for module');
154 foreach my $method_name (sort @class_mop_module_methods) {
155 ok($class_mop_module_meta->has_method($method_name), '... Class::MOP::Module->has_method(' . $method_name . ')');
158 is($class_mop_module_meta->get_method($method_name)->body,
159 \&{'Class::MOP::Module::' . $method_name},
160 '... Class::MOP::Module->get_method(' . $method_name . ') == &Class::MOP::Module::' . $method_name);
165 # check for imported functions which are not methods
167 foreach my $non_method_name (qw(
173 ok(!$class_mop_class_meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')');
176 # check for the right attributes
178 my @class_mop_package_attributes = (
183 my @class_mop_module_attributes = (
188 my @class_mop_class_attributes = (
190 'instance_metaclass',
200 [ sort $class_mop_class_meta->get_attribute_list ],
201 [ sort @class_mop_class_attributes ],
202 '... got the right list of attributes'
206 [ sort keys %{$class_mop_class_meta->_attribute_map} ],
207 [ sort @class_mop_class_attributes ],
208 '... got the right list of attributes');
210 foreach my $attribute_name (sort @class_mop_class_attributes) {
211 ok($class_mop_class_meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
212 isa_ok($class_mop_class_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
218 [ sort $class_mop_package_meta->get_attribute_list ],
219 [ sort @class_mop_package_attributes ],
220 '... got the right list of attributes');
223 [ sort keys %{$class_mop_package_meta->_attribute_map} ],
224 [ sort @class_mop_package_attributes ],
225 '... got the right list of attributes');
227 foreach my $attribute_name (sort @class_mop_package_attributes) {
228 ok($class_mop_package_meta->has_attribute($attribute_name), '... Class::MOP::Package->has_attribute(' . $attribute_name . ')');
229 isa_ok($class_mop_package_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
235 [ sort $class_mop_module_meta->get_attribute_list ],
236 [ sort @class_mop_module_attributes ],
237 '... got the right list of attributes');
240 [ sort keys %{$class_mop_module_meta->_attribute_map} ],
241 [ sort @class_mop_module_attributes ],
242 '... got the right list of attributes');
244 foreach my $attribute_name (sort @class_mop_module_attributes) {
245 ok($class_mop_module_meta->has_attribute($attribute_name), '... Class::MOP::Module->has_attribute(' . $attribute_name . ')');
246 isa_ok($class_mop_module_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
249 ## check the attributes themselves
253 ok($class_mop_package_meta->get_attribute('package')->has_reader, '... Class::MOP::Class package has a reader');
254 is(ref($class_mop_package_meta->get_attribute('package')->reader), 'HASH', '... Class::MOP::Class package\'s a reader is { name => sub { ... } }');
256 ok($class_mop_package_meta->get_attribute('package')->has_init_arg, '... Class::MOP::Class package has a init_arg');
257 is($class_mop_package_meta->get_attribute('package')->init_arg, 'package', '... Class::MOP::Class package\'s a init_arg is package');
259 # ... class, but inherited from HasMethods
260 ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_reader, '... Class::MOP::Class method_metaclass has a reader');
261 is_deeply($class_mop_class_meta->find_attribute_by_name('method_metaclass')->reader,
262 { 'method_metaclass' => \&Class::MOP::Mixin::HasMethods::method_metaclass },
263 '... Class::MOP::Class method_metaclass\'s a reader is &method_metaclass');
265 ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_init_arg, '... Class::MOP::Class method_metaclass has a init_arg');
266 is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->init_arg,
268 '... Class::MOP::Class method_metaclass\'s init_arg is method_metaclass');
270 ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default');
271 is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->default,
272 'Class::MOP::Method',
273 '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method');
275 ok($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->has_reader, '... Class::MOP::Class wrapped_method_metaclass has a reader');
276 is_deeply($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->reader,
277 { 'wrapped_method_metaclass' => \&Class::MOP::Mixin::HasMethods::wrapped_method_metaclass },
278 '... Class::MOP::Class wrapped_method_metaclass\'s a reader is &wrapped_method_metaclass');
280 ok($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Class wrapped_method_metaclass has a init_arg');
281 is($class_mop_class_meta->find_attribute_by_name('wrapped_method_metaclass')->init_arg,
282 'wrapped_method_metaclass',
283 '... Class::MOP::Class wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass');
285 ok($class_mop_class_meta->find_attribute_by_name('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default');
286 is($class_mop_class_meta->find_attribute_by_name('method_metaclass')->default,
287 'Class::MOP::Method',
288 '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method');
291 # ... class, but inherited from HasAttributes
293 ok($class_mop_class_meta->find_attribute_by_name('attributes')->has_reader, '... Class::MOP::Class attributes has a reader');
294 is_deeply($class_mop_class_meta->find_attribute_by_name('attributes')->reader,
295 { '_attribute_map' => \&Class::MOP::Mixin::HasAttributes::_attribute_map },
296 '... Class::MOP::Class attributes\'s a reader is &_attribute_map');
298 ok($class_mop_class_meta->find_attribute_by_name('attributes')->has_init_arg, '... Class::MOP::Class attributes has a init_arg');
299 is($class_mop_class_meta->find_attribute_by_name('attributes')->init_arg,
301 '... Class::MOP::Class attributes\'s a init_arg is attributes');
303 ok($class_mop_class_meta->find_attribute_by_name('attributes')->has_default, '... Class::MOP::Class attributes has a default');
304 is_deeply($class_mop_class_meta->find_attribute_by_name('attributes')->default('Foo'),
306 '... Class::MOP::Class attributes\'s a default of {}');
308 ok($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->has_reader, '... Class::MOP::Class attribute_metaclass has a reader');
309 is_deeply($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->reader,
310 { 'attribute_metaclass' => \&Class::MOP::Mixin::HasAttributes::attribute_metaclass },
311 '... Class::MOP::Class attribute_metaclass\'s a reader is &attribute_metaclass');
313 ok($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->has_init_arg, '... Class::MOP::Class attribute_metaclass has a init_arg');
314 is($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->init_arg,
315 'attribute_metaclass',
316 '... Class::MOP::Class attribute_metaclass\'s a init_arg is attribute_metaclass');
318 ok($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->has_default, '... Class::MOP::Class attribute_metaclass has a default');
319 is($class_mop_class_meta->find_attribute_by_name('attribute_metaclass')->default,
320 'Class::MOP::Attribute',
321 '... Class::MOP::Class attribute_metaclass\'s a default is Class::MOP:::Attribute');
323 # check the values of some of the methods
325 is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
326 is($class_mop_class_meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
328 ok($class_mop_class_meta->has_package_symbol('$VERSION'), '... Class::MOP::Class->has_package_symbol($VERSION)');
329 is(${$class_mop_class_meta->get_package_symbol('$VERSION')},
330 $Class::MOP::Class::VERSION,
331 '... Class::MOP::Class->get_package_symbol($VERSION)');
334 [ $class_mop_class_meta->superclasses ],
335 [ qw/Class::MOP::Module Class::MOP::Mixin::HasAttributes Class::MOP::Mixin::HasMethods/ ],
336 '... Class::MOP::Class->superclasses == [ Class::MOP::Module ]');
339 [ $class_mop_class_meta->class_precedence_list ],
345 Class::MOP::Mixin::HasAttributes
347 Class::MOP::Mixin::HasMethods
350 '... Class::MOP::Class->class_precedence_list == [ Class::MOP::Class Class::MOP::Module Class::MOP::Package ]');
352 is($class_mop_class_meta->attribute_metaclass, 'Class::MOP::Attribute', '... got the right value for attribute_metaclass');
353 is($class_mop_class_meta->method_metaclass, 'Class::MOP::Method', '... got the right value for method_metaclass');
354 is($class_mop_class_meta->instance_metaclass, 'Class::MOP::Instance', '... got the right value for instance_metaclass');