6 use Test::More tests => 144;
11 use_ok('Class::MOP::Class');
15 my $class = Class::MOP::Class->initialize('Foo');
16 is($class->meta, Class::MOP::Class->meta, '... instance and class both lead to the same meta');
19 my $meta = Class::MOP::Class->meta();
20 isa_ok($meta, 'Class::MOP::Class');
25 get_all_metaclasses get_all_metaclass_names get_all_metaclass_instances
27 initialize reinitialize create create_anon_class
29 instance_metaclass get_meta_instance
30 new_object clone_object
31 construct_instance construct_class_instance clone_instance
32 check_metaclass_compatability
36 attribute_metaclass method_metaclass
38 superclasses class_precedence_list
40 has_method get_method add_method remove_method alias_method
41 get_method_list compute_all_applicable_methods
42 find_all_methods_by_name find_next_method_by_name
44 add_before_method_modifier add_after_method_modifier add_around_method_modifier
46 has_attribute get_attribute add_attribute remove_attribute
47 get_attribute_list get_attribute_map compute_all_applicable_attributes find_attribute_by_name
49 add_package_variable get_package_variable has_package_variable remove_package_variable
52 is_deeply([ sort @methods ], [ sort $meta->get_method_list ], '... got the correct method list');
54 foreach my $method_name (@methods) {
55 ok($meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
58 is($meta->get_method($method_name),
59 \&{'Class::MOP::Class::' . $method_name},
60 '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name);
64 # check for imported functions which are not methods
66 foreach my $non_method_name (qw(
72 ok(!$meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')');
75 # check for the right attributes
80 '$:attribute_metaclass',
82 '$:instance_metaclass'
87 [ sort $meta->get_attribute_list ],
88 '... got the right list of attributes');
92 [ sort keys %{$meta->get_attribute_map} ],
93 '... got the right list of attributes');
95 foreach my $attribute_name (@attributes) {
96 ok($meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
97 isa_ok($meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
100 ## check the attributes themselves
102 ok($meta->get_attribute('$:package')->has_reader, '... Class::MOP::Class $:package has a reader');
103 is(ref($meta->get_attribute('$:package')->reader), 'HASH', '... Class::MOP::Class $:package\'s a reader is { name => sub { ... } }');
105 ok($meta->get_attribute('$:package')->has_init_arg, '... Class::MOP::Class $:package has a init_arg');
106 is($meta->get_attribute('$:package')->init_arg, ':package', '... Class::MOP::Class $:package\'s a init_arg is :package');
108 ok($meta->get_attribute('%:attributes')->has_reader, '... Class::MOP::Class %:attributes has a reader');
109 is(ref($meta->get_attribute('%:attributes')->reader),
111 '... Class::MOP::Class %:attributes\'s a reader is &get_attribute_map');
113 ok($meta->get_attribute('%:attributes')->has_init_arg, '... Class::MOP::Class %:attributes has a init_arg');
114 is($meta->get_attribute('%:attributes')->init_arg,
116 '... Class::MOP::Class %:attributes\'s a init_arg is :attributes');
118 ok($meta->get_attribute('%:attributes')->has_default, '... Class::MOP::Class %:attributes has a default');
119 is_deeply($meta->get_attribute('%:attributes')->default,
121 '... Class::MOP::Class %:attributes\'s a default of {}');
123 ok($meta->get_attribute('$:attribute_metaclass')->has_reader, '... Class::MOP::Class $:attribute_metaclass has a reader');
124 is($meta->get_attribute('$:attribute_metaclass')->reader,
125 'attribute_metaclass',
126 '... Class::MOP::Class $:attribute_metaclass\'s a reader is &attribute_metaclass');
128 ok($meta->get_attribute('$:attribute_metaclass')->has_init_arg, '... Class::MOP::Class $:attribute_metaclass has a init_arg');
129 is($meta->get_attribute('$:attribute_metaclass')->init_arg,
130 ':attribute_metaclass',
131 '... Class::MOP::Class $:attribute_metaclass\'s a init_arg is :attribute_metaclass');
133 ok($meta->get_attribute('$:attribute_metaclass')->has_default, '... Class::MOP::Class $:attribute_metaclass has a default');
134 is($meta->get_attribute('$:attribute_metaclass')->default,
135 'Class::MOP::Attribute',
136 '... Class::MOP::Class $:attribute_metaclass\'s a default is Class::MOP:::Attribute');
138 ok($meta->get_attribute('$:method_metaclass')->has_reader, '... Class::MOP::Class $:method_metaclass has a reader');
139 is($meta->get_attribute('$:method_metaclass')->reader,
141 '... Class::MOP::Class $:method_metaclass\'s a reader is &method_metaclass');
143 ok($meta->get_attribute('$:method_metaclass')->has_init_arg, '... Class::MOP::Class $:method_metaclass has a init_arg');
144 is($meta->get_attribute('$:method_metaclass')->init_arg,
146 '... Class::MOP::Class $:method_metaclass\'s init_arg is :method_metaclass');
148 ok($meta->get_attribute('$:method_metaclass')->has_default, '... Class::MOP::Class $:method_metaclass has a default');
149 is($meta->get_attribute('$:method_metaclass')->default,
150 'Class::MOP::Method',
151 '... Class::MOP::Class $:method_metaclass\'s a default is Class::MOP:::Method');
153 # check the values of some of the methods
155 is($meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
156 is($meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
158 ok($meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)');
159 is(${$meta->get_package_variable('$VERSION')},
160 $Class::MOP::Class::VERSION,
161 '... Class::MOP::Class->get_package_variable($VERSION)');
164 [ $meta->superclasses ],
166 '... Class::MOP::Class->superclasses == []');
169 [ $meta->class_precedence_list ],
170 [ 'Class::MOP::Class' ],
171 '... Class::MOP::Class->class_precedence_list == []');
173 is($meta->attribute_metaclass, 'Class::MOP::Attribute', '... got the right value for attribute_metaclass');
174 is($meta->method_metaclass, 'Class::MOP::Method', '... got the right value for method_metaclass');