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;
44 { $meta->immutable_options }, {},
45 'immutable_options is empty before a class is made_immutable'
48 $meta->make_immutable;
50 my $immutable_metaclass = $meta->_immutable_metaclass->meta;
52 my $immutable_class_name = $immutable_metaclass->name;
54 ok( !$immutable_class_name->is_mutable, '... immutable_metaclass is not mutable' );
55 ok( $immutable_class_name->is_immutable, '... immutable_metaclass is immutable' );
56 is( $immutable_class_name->meta, $immutable_metaclass,
57 '... immutable_metaclass meta hack works' );
60 { $meta->immutable_options },
62 inline_accessors => 1,
63 inline_constructor => 1,
64 inline_destructor => 0,
66 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
67 constructor_name => 'new',
68 constructor_class => 'Class::MOP::Method::Constructor',
69 destructor_class => undef,
71 'immutable_options is empty before a class is made_immutable'
74 isa_ok( $meta, "Class::MOP::Class" );
79 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
81 ok( !$meta->is_mutable, '... our class is not mutable' );
82 ok( $meta->is_immutable, '... our class is immutable' );
84 isa_ok( $meta, 'Class::MOP::Class' );
86 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
87 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
88 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
90 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
91 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
93 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
94 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
96 is( exception { $meta->identifier() }, undef, '... no exception for get_package_symbol special case' );
100 @supers = $meta->superclasses;
101 }, undef, '... got the superclasses okay' );
103 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
107 $meta_instance = $meta->get_meta_instance;
108 }, undef, '... got the meta instance okay' );
109 isa_ok( $meta_instance, 'Class::MOP::Instance' );
110 is( $meta_instance, $meta->get_meta_instance,
111 '... and we know it is cached' );
115 @cpl = $meta->class_precedence_list;
116 }, undef, '... got the class precedence list okay' );
120 '... we just have ourselves in the class precedence list'
125 @attributes = $meta->get_all_attributes;
126 }, undef, '... got the attribute list okay' );
129 [ $meta->get_attribute('bar') ],
130 '... got the right list of attributes'
135 my $meta = Bar->meta;
136 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
138 ok( $meta->is_mutable, '... our class is mutable' );
139 ok( !$meta->is_immutable, '... our class is not immutable' );
142 $meta->make_immutable();
143 }, undef, '... changed Bar to be immutable' );
145 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
147 ok( !$meta->is_mutable, '... our class is no longer mutable' );
148 ok( $meta->is_immutable, '... our class is now immutable' );
150 isa_ok( $meta, 'Class::MOP::Class' );
152 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
153 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
154 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
156 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
157 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
159 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
160 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
164 @supers = $meta->superclasses;
165 }, undef, '... got the superclasses okay' );
167 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
171 $meta_instance = $meta->get_meta_instance;
172 }, undef, '... got the meta instance okay' );
173 isa_ok( $meta_instance, 'Class::MOP::Instance' );
174 is( $meta_instance, $meta->get_meta_instance,
175 '... and we know it is cached' );
179 @cpl = $meta->class_precedence_list;
180 }, undef, '... got the class precedence list okay' );
184 '... we just have ourselves in the class precedence list'
189 @attributes = $meta->get_all_attributes;
190 }, undef, '... got the attribute list okay' );
192 [ sort { $a->name cmp $b->name } @attributes ],
193 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
194 '... got the right list of attributes'
199 my $meta = Baz->meta;
200 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
202 ok( $meta->is_mutable, '... our class is mutable' );
203 ok( !$meta->is_immutable, '... our class is not immutable' );
206 $meta->make_immutable();
207 }, undef, '... changed Baz to be immutable' );
209 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
211 ok( !$meta->is_mutable, '... our class is no longer mutable' );
212 ok( $meta->is_immutable, '... our class is now immutable' );
214 isa_ok( $meta, 'Class::MOP::Class' );
216 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
217 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
218 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
220 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
221 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
223 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
224 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
228 @supers = $meta->superclasses;
229 }, undef, '... got the superclasses okay' );
231 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
235 $meta_instance = $meta->get_meta_instance;
236 }, undef, '... got the meta instance okay' );
237 isa_ok( $meta_instance, 'Class::MOP::Instance' );
238 is( $meta_instance, $meta->get_meta_instance,
239 '... and we know it is cached' );
243 @cpl = $meta->class_precedence_list;
244 }, undef, '... got the class precedence list okay' );
247 [ 'Baz', 'Bar', 'Foo' ],
248 '... we just have ourselves in the class precedence list'
253 @attributes = $meta->get_all_attributes;
254 }, undef, '... got the attribute list okay' );
256 [ sort { $a->name cmp $b->name } @attributes ],
258 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
259 Bar->meta->get_attribute('baz')
261 '... got the right list of attributes'
265 # This test probably needs to go last since it will muck up the Foo class
267 my $meta = Foo->meta;
270 $meta->make_immutable(
271 inline_accessors => 0,
272 inline_constructor => 0,
273 constructor_name => 'newer',
277 { $meta->immutable_options },
279 inline_accessors => 0,
280 inline_constructor => 0,
281 inline_destructor => 0,
283 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
284 constructor_name => 'newer',
285 constructor_class => 'Class::MOP::Method::Constructor',
286 destructor_class => undef,
288 'custom immutable_options are returned by immutable_options accessor'