6 use Test::More tests => 117;
11 use_ok('Class::MOP::Class');
14 my $meta = Class::MOP::Class->meta();
15 isa_ok($meta, 'Class::MOP::Class');
22 new_object clone_object
23 construct_instance construct_class_instance clone_instance
24 check_metaclass_compatability
28 attribute_metaclass method_metaclass
30 superclasses class_precedence_list
32 has_method get_method add_method remove_method alias_method
33 get_method_list compute_all_applicable_methods find_all_methods_by_name
35 has_attribute get_attribute add_attribute remove_attribute
36 get_attribute_list get_attribute_map compute_all_applicable_attributes
38 add_package_variable get_package_variable has_package_variable remove_package_variable
41 is_deeply([ sort @methods ], [ sort $meta->get_method_list ], '... got the correct method list');
43 foreach my $method_name (@methods) {
44 ok($meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
47 is($meta->get_method($method_name),
48 \&{'Class::MOP::Class::' . $method_name},
49 '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name);
53 # check for imported functions which are not methods
55 foreach my $non_method_name (qw(
61 ok(!$meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')');
64 # check for the right attributes
66 my @attributes = ('$:package', '%:attributes', '$:attribute_metaclass', '$:method_metaclass');
70 [ sort $meta->get_attribute_list ],
71 '... got the right list of attributes');
75 [ sort keys %{$meta->get_attribute_map} ],
76 '... got the right list of attributes');
78 foreach my $attribute_name (@attributes) {
79 ok($meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
80 isa_ok($meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
83 ## check the attributes themselves
85 ok($meta->get_attribute('$:package')->has_reader, '... Class::MOP::Class $:package has a reader');
86 is($meta->get_attribute('$:package')->reader, 'name', '... Class::MOP::Class $:package\'s a reader is &name');
88 ok($meta->get_attribute('$:package')->has_init_arg, '... Class::MOP::Class $:package has a init_arg');
89 is($meta->get_attribute('$:package')->init_arg, ':package', '... Class::MOP::Class $:package\'s a init_arg is :package');
91 ok($meta->get_attribute('%:attributes')->has_reader, '... Class::MOP::Class %:attributes has a reader');
92 is($meta->get_attribute('%:attributes')->reader,
94 '... Class::MOP::Class %:attributes\'s a reader is &get_attribute_map');
96 ok($meta->get_attribute('%:attributes')->has_init_arg, '... Class::MOP::Class %:attributes has a init_arg');
97 is($meta->get_attribute('%:attributes')->init_arg,
99 '... Class::MOP::Class %:attributes\'s a init_arg is :attributes');
101 ok($meta->get_attribute('%:attributes')->has_default, '... Class::MOP::Class %:attributes has a default');
102 is_deeply($meta->get_attribute('%:attributes')->default,
104 '... Class::MOP::Class %:attributes\'s a default of {}');
106 ok($meta->get_attribute('$:attribute_metaclass')->has_reader, '... Class::MOP::Class $:attribute_metaclass has a reader');
107 is($meta->get_attribute('$:attribute_metaclass')->reader,
108 'attribute_metaclass',
109 '... Class::MOP::Class $:attribute_metaclass\'s a reader is &attribute_metaclass');
111 ok($meta->get_attribute('$:attribute_metaclass')->has_init_arg, '... Class::MOP::Class $:attribute_metaclass has a init_arg');
112 is($meta->get_attribute('$:attribute_metaclass')->init_arg,
113 ':attribute_metaclass',
114 '... Class::MOP::Class $:attribute_metaclass\'s a init_arg is :attribute_metaclass');
116 ok($meta->get_attribute('$:attribute_metaclass')->has_default, '... Class::MOP::Class $:attribute_metaclass has a default');
117 is($meta->get_attribute('$:attribute_metaclass')->default,
118 'Class::MOP::Attribute',
119 '... Class::MOP::Class $:attribute_metaclass\'s a default is Class::MOP:::Attribute');
121 ok($meta->get_attribute('$:method_metaclass')->has_reader, '... Class::MOP::Class $:method_metaclass has a reader');
122 is($meta->get_attribute('$:method_metaclass')->reader,
124 '... Class::MOP::Class $:method_metaclass\'s a reader is &method_metaclass');
126 ok($meta->get_attribute('$:method_metaclass')->has_init_arg, '... Class::MOP::Class $:method_metaclass has a init_arg');
127 is($meta->get_attribute('$:method_metaclass')->init_arg,
129 '... Class::MOP::Class $:method_metaclass\'s init_arg is :method_metaclass');
131 ok($meta->get_attribute('$:method_metaclass')->has_default, '... Class::MOP::Class $:method_metaclass has a default');
132 is($meta->get_attribute('$:method_metaclass')->default,
133 'Class::MOP::Method',
134 '... Class::MOP::Class $:method_metaclass\'s a default is Class::MOP:::Method');
136 # check the values of some of the methods
138 is($meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
139 is($meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
141 ok($meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)');
142 is(${$meta->get_package_variable('$VERSION')},
143 $Class::MOP::Class::VERSION,
144 '... Class::MOP::Class->get_package_variable($VERSION)');
147 [ $meta->superclasses ],
149 '... Class::MOP::Class->superclasses == []');
152 [ $meta->class_precedence_list ],
153 [ 'Class::MOP::Class' ],
154 '... Class::MOP::Class->class_precedence_list == []');
156 is($meta->attribute_metaclass, 'Class::MOP::Attribute', '... got the right value for attribute_metaclass');
157 is($meta->method_metaclass, 'Class::MOP::Method', '... got the right value for method_metaclass');