6 use Test::More tests => 124;
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');
27 new_object clone_object
28 construct_instance construct_class_instance clone_instance
29 check_metaclass_compatability
33 attribute_metaclass method_metaclass
35 superclasses class_precedence_list
37 has_method get_method add_method remove_method alias_method
38 get_method_list compute_all_applicable_methods find_all_methods_by_name
40 add_before_method_modifier add_after_method_modifier add_around_method_modifier
42 has_attribute get_attribute add_attribute remove_attribute
43 get_attribute_list get_attribute_map compute_all_applicable_attributes
45 add_package_variable get_package_variable has_package_variable remove_package_variable
48 is_deeply([ sort @methods ], [ sort $meta->get_method_list ], '... got the correct method list');
50 foreach my $method_name (@methods) {
51 ok($meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
54 is($meta->get_method($method_name),
55 \&{'Class::MOP::Class::' . $method_name},
56 '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name);
60 # check for imported functions which are not methods
62 foreach my $non_method_name (qw(
68 ok(!$meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')');
71 # check for the right attributes
73 my @attributes = ('$:package', '%:attributes', '$:attribute_metaclass', '$:method_metaclass');
77 [ sort $meta->get_attribute_list ],
78 '... got the right list of attributes');
82 [ sort keys %{$meta->get_attribute_map} ],
83 '... got the right list of attributes');
85 foreach my $attribute_name (@attributes) {
86 ok($meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
87 isa_ok($meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
90 ## check the attributes themselves
92 ok($meta->get_attribute('$:package')->has_reader, '... Class::MOP::Class $:package has a reader');
93 is($meta->get_attribute('$:package')->reader, 'name', '... Class::MOP::Class $:package\'s a reader is &name');
95 ok($meta->get_attribute('$:package')->has_init_arg, '... Class::MOP::Class $:package has a init_arg');
96 is($meta->get_attribute('$:package')->init_arg, ':package', '... Class::MOP::Class $:package\'s a init_arg is :package');
98 ok($meta->get_attribute('%:attributes')->has_reader, '... Class::MOP::Class %:attributes has a reader');
99 is($meta->get_attribute('%:attributes')->reader,
101 '... Class::MOP::Class %:attributes\'s a reader is &get_attribute_map');
103 ok($meta->get_attribute('%:attributes')->has_init_arg, '... Class::MOP::Class %:attributes has a init_arg');
104 is($meta->get_attribute('%:attributes')->init_arg,
106 '... Class::MOP::Class %:attributes\'s a init_arg is :attributes');
108 ok($meta->get_attribute('%:attributes')->has_default, '... Class::MOP::Class %:attributes has a default');
109 is_deeply($meta->get_attribute('%:attributes')->default,
111 '... Class::MOP::Class %:attributes\'s a default of {}');
113 ok($meta->get_attribute('$:attribute_metaclass')->has_reader, '... Class::MOP::Class $:attribute_metaclass has a reader');
114 is($meta->get_attribute('$:attribute_metaclass')->reader,
115 'attribute_metaclass',
116 '... Class::MOP::Class $:attribute_metaclass\'s a reader is &attribute_metaclass');
118 ok($meta->get_attribute('$:attribute_metaclass')->has_init_arg, '... Class::MOP::Class $:attribute_metaclass has a init_arg');
119 is($meta->get_attribute('$:attribute_metaclass')->init_arg,
120 ':attribute_metaclass',
121 '... Class::MOP::Class $:attribute_metaclass\'s a init_arg is :attribute_metaclass');
123 ok($meta->get_attribute('$:attribute_metaclass')->has_default, '... Class::MOP::Class $:attribute_metaclass has a default');
124 is($meta->get_attribute('$:attribute_metaclass')->default,
125 'Class::MOP::Attribute',
126 '... Class::MOP::Class $:attribute_metaclass\'s a default is Class::MOP:::Attribute');
128 ok($meta->get_attribute('$:method_metaclass')->has_reader, '... Class::MOP::Class $:method_metaclass has a reader');
129 is($meta->get_attribute('$:method_metaclass')->reader,
131 '... Class::MOP::Class $:method_metaclass\'s a reader is &method_metaclass');
133 ok($meta->get_attribute('$:method_metaclass')->has_init_arg, '... Class::MOP::Class $:method_metaclass has a init_arg');
134 is($meta->get_attribute('$:method_metaclass')->init_arg,
136 '... Class::MOP::Class $:method_metaclass\'s init_arg is :method_metaclass');
138 ok($meta->get_attribute('$:method_metaclass')->has_default, '... Class::MOP::Class $:method_metaclass has a default');
139 is($meta->get_attribute('$:method_metaclass')->default,
140 'Class::MOP::Method',
141 '... Class::MOP::Class $:method_metaclass\'s a default is Class::MOP:::Method');
143 # check the values of some of the methods
145 is($meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
146 is($meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
148 ok($meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)');
149 is(${$meta->get_package_variable('$VERSION')},
150 $Class::MOP::Class::VERSION,
151 '... Class::MOP::Class->get_package_variable($VERSION)');
154 [ $meta->superclasses ],
156 '... Class::MOP::Class->superclasses == []');
159 [ $meta->class_precedence_list ],
160 [ 'Class::MOP::Class' ],
161 '... Class::MOP::Class->class_precedence_list == []');
163 is($meta->attribute_metaclass, 'Class::MOP::Attribute', '... got the right value for attribute_metaclass');
164 is($meta->method_metaclass, 'Class::MOP::Method', '... got the right value for method_metaclass');