4 use Test::More tests => 80;
16 __PACKAGE__->meta->add_attribute('bar');
24 __PACKAGE__->meta->superclasses('Foo');
26 __PACKAGE__->meta->add_attribute('baz');
34 __PACKAGE__->meta->superclasses('Bar');
36 __PACKAGE__->meta->add_attribute('bah');
41 my $original_metaclass_name = ref $meta;
43 $meta->make_immutable;
45 my $transformer = $meta->immutable_transformer;
46 isa_ok( $transformer, 'Class::MOP::Immutable',
47 '... transformer isa Class::MOP::Immutable' );
49 my $immutable_metaclass = $transformer->immutable_metaclass;
50 is( $transformer->metaclass, $meta,
51 '... transformer has correct metaclass' );
52 ok( $transformer->inlined_constructor,
53 '... transformer says it did inline the constructor' );
54 ok( $immutable_metaclass->is_anon_class,
55 '... immutable_metaclass is an anonymous class' );
57 #I don't understand why i need to ->meta here...
58 my $obj = $immutable_metaclass->name;
59 ok( !$obj->is_mutable, '... immutable_metaclass is not mutable' );
60 ok( $obj->is_immutable, '... immutable_metaclass is immutable' );
61 ok( !$obj->make_immutable,
62 '... immutable_metaclass make_mutable is noop' );
63 is( $obj->meta, $immutable_metaclass,
64 '... immutable_metaclass meta hack works' );
67 [ $immutable_metaclass->superclasses ],
68 [ $original_metaclass_name ],
69 '... immutable_metaclass superclasses are correct'
72 $immutable_metaclass->has_method('get_mutable_metaclass_name'),
73 'immutable metaclass has get_mutable_metaclass_name method'
80 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
82 ok( !$meta->is_mutable, '... our class is not mutable' );
83 ok( $meta->is_immutable, '... our class is immutable' );
85 my $transformer = $meta->immutable_transformer;
87 is( $transformer, $meta->immutable_transformer,
88 '... immutable transformer cache works' );
90 isa_ok( $meta, 'Class::MOP::Class' );
92 dies_ok { $meta->add_method() } '... exception thrown as expected';
93 dies_ok { $meta->alias_method() } '... exception thrown as expected';
94 dies_ok { $meta->remove_method() } '... exception thrown as expected';
96 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
97 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
99 dies_ok { $meta->add_package_symbol() }
100 '... exception thrown as expected';
101 dies_ok { $meta->remove_package_symbol() }
102 '... exception thrown as expected';
104 lives_ok { $meta->identifier() }
105 '... no exception for get_package_symbol special case';
109 @supers = $meta->superclasses;
111 '... got the superclasses okay';
113 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
114 '... but could not set the superclasses okay';
118 $meta_instance = $meta->get_meta_instance;
120 '... got the meta instance okay';
121 isa_ok( $meta_instance, 'Class::MOP::Instance' );
122 is( $meta_instance, $meta->get_meta_instance,
123 '... and we know it is cached' );
127 @cpl = $meta->class_precedence_list;
129 '... got the class precedence list okay';
133 '... we just have ourselves in the class precedence list'
138 @attributes = $meta->compute_all_applicable_attributes;
140 '... got the attribute list okay';
143 [ $meta->get_attribute('bar') ],
144 '... got the right list of attributes'
149 my $meta = Bar->meta;
150 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
152 ok( $meta->is_mutable, '... our class is mutable' );
153 ok( !$meta->is_immutable, '... our class is not immutable' );
156 $meta->make_immutable();
158 '... changed Bar to be immutable';
160 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
162 ok( !$meta->is_mutable, '... our class is no longer mutable' );
163 ok( $meta->is_immutable, '... our class is now immutable' );
165 isa_ok( $meta, 'Class::MOP::Class' );
167 dies_ok { $meta->add_method() } '... exception thrown as expected';
168 dies_ok { $meta->alias_method() } '... exception thrown as expected';
169 dies_ok { $meta->remove_method() } '... exception thrown as expected';
171 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
172 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
174 dies_ok { $meta->add_package_symbol() }
175 '... exception thrown as expected';
176 dies_ok { $meta->remove_package_symbol() }
177 '... exception thrown as expected';
181 @supers = $meta->superclasses;
183 '... got the superclasses okay';
185 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
186 '... but could not set the superclasses okay';
190 $meta_instance = $meta->get_meta_instance;
192 '... got the meta instance okay';
193 isa_ok( $meta_instance, 'Class::MOP::Instance' );
194 is( $meta_instance, $meta->get_meta_instance,
195 '... and we know it is cached' );
199 @cpl = $meta->class_precedence_list;
201 '... got the class precedence list okay';
205 '... we just have ourselves in the class precedence list'
210 @attributes = $meta->compute_all_applicable_attributes;
212 '... got the attribute list okay';
214 [ sort { $a->name cmp $b->name } @attributes ],
215 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
216 '... got the right list of attributes'
221 my $meta = Baz->meta;
222 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
224 ok( $meta->is_mutable, '... our class is mutable' );
225 ok( !$meta->is_immutable, '... our class is not immutable' );
228 $meta->make_immutable();
230 '... changed Baz to be immutable';
232 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
234 ok( !$meta->is_mutable, '... our class is no longer mutable' );
235 ok( $meta->is_immutable, '... our class is now immutable' );
237 isa_ok( $meta, 'Class::MOP::Class' );
239 dies_ok { $meta->add_method() } '... exception thrown as expected';
240 dies_ok { $meta->alias_method() } '... exception thrown as expected';
241 dies_ok { $meta->remove_method() } '... exception thrown as expected';
243 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
244 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
246 dies_ok { $meta->add_package_symbol() }
247 '... exception thrown as expected';
248 dies_ok { $meta->remove_package_symbol() }
249 '... exception thrown as expected';
253 @supers = $meta->superclasses;
255 '... got the superclasses okay';
257 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
258 '... but could not set the superclasses okay';
262 $meta_instance = $meta->get_meta_instance;
264 '... got the meta instance okay';
265 isa_ok( $meta_instance, 'Class::MOP::Instance' );
266 is( $meta_instance, $meta->get_meta_instance,
267 '... and we know it is cached' );
271 @cpl = $meta->class_precedence_list;
273 '... got the class precedence list okay';
276 [ 'Baz', 'Bar', 'Foo' ],
277 '... we just have ourselves in the class precedence list'
282 @attributes = $meta->compute_all_applicable_attributes;
284 '... got the attribute list okay';
286 [ sort { $a->name cmp $b->name } @attributes ],
288 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
289 Bar->meta->get_attribute('baz')
291 '... got the right list of attributes'