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 dies_ok { $meta->add_method() } '... exception thrown as expected';
87 dies_ok { $meta->alias_method() } '... exception thrown as expected';
88 dies_ok { $meta->remove_method() } '... exception thrown as expected';
90 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
91 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
93 dies_ok { $meta->add_package_symbol() }
94 '... exception thrown as expected';
95 dies_ok { $meta->remove_package_symbol() }
96 '... exception thrown as expected';
98 lives_ok { $meta->identifier() }
99 '... no exception for get_package_symbol special case';
103 @supers = $meta->superclasses;
105 '... got the superclasses okay';
107 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
108 '... but could not set the superclasses okay';
112 $meta_instance = $meta->get_meta_instance;
114 '... got the meta instance okay';
115 isa_ok( $meta_instance, 'Class::MOP::Instance' );
116 is( $meta_instance, $meta->get_meta_instance,
117 '... and we know it is cached' );
121 @cpl = $meta->class_precedence_list;
123 '... got the class precedence list okay';
127 '... we just have ourselves in the class precedence list'
132 @attributes = $meta->get_all_attributes;
134 '... got the attribute list okay';
137 [ $meta->get_attribute('bar') ],
138 '... got the right list of attributes'
143 my $meta = Bar->meta;
144 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
146 ok( $meta->is_mutable, '... our class is mutable' );
147 ok( !$meta->is_immutable, '... our class is not immutable' );
150 $meta->make_immutable();
152 '... changed Bar to be immutable';
154 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
156 ok( !$meta->is_mutable, '... our class is no longer mutable' );
157 ok( $meta->is_immutable, '... our class is now immutable' );
159 isa_ok( $meta, 'Class::MOP::Class' );
161 dies_ok { $meta->add_method() } '... exception thrown as expected';
162 dies_ok { $meta->alias_method() } '... exception thrown as expected';
163 dies_ok { $meta->remove_method() } '... exception thrown as expected';
165 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
166 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
168 dies_ok { $meta->add_package_symbol() }
169 '... exception thrown as expected';
170 dies_ok { $meta->remove_package_symbol() }
171 '... exception thrown as expected';
175 @supers = $meta->superclasses;
177 '... got the superclasses okay';
179 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
180 '... but could not set the superclasses okay';
184 $meta_instance = $meta->get_meta_instance;
186 '... got the meta instance okay';
187 isa_ok( $meta_instance, 'Class::MOP::Instance' );
188 is( $meta_instance, $meta->get_meta_instance,
189 '... and we know it is cached' );
193 @cpl = $meta->class_precedence_list;
195 '... got the class precedence list okay';
199 '... we just have ourselves in the class precedence list'
204 @attributes = $meta->get_all_attributes;
206 '... got the attribute list okay';
208 [ sort { $a->name cmp $b->name } @attributes ],
209 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
210 '... got the right list of attributes'
215 my $meta = Baz->meta;
216 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
218 ok( $meta->is_mutable, '... our class is mutable' );
219 ok( !$meta->is_immutable, '... our class is not immutable' );
222 $meta->make_immutable();
224 '... changed Baz to be immutable';
226 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
228 ok( !$meta->is_mutable, '... our class is no longer mutable' );
229 ok( $meta->is_immutable, '... our class is now immutable' );
231 isa_ok( $meta, 'Class::MOP::Class' );
233 dies_ok { $meta->add_method() } '... exception thrown as expected';
234 dies_ok { $meta->alias_method() } '... exception thrown as expected';
235 dies_ok { $meta->remove_method() } '... exception thrown as expected';
237 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
238 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
240 dies_ok { $meta->add_package_symbol() }
241 '... exception thrown as expected';
242 dies_ok { $meta->remove_package_symbol() }
243 '... exception thrown as expected';
247 @supers = $meta->superclasses;
249 '... got the superclasses okay';
251 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
252 '... but could not set the superclasses okay';
256 $meta_instance = $meta->get_meta_instance;
258 '... got the meta instance okay';
259 isa_ok( $meta_instance, 'Class::MOP::Instance' );
260 is( $meta_instance, $meta->get_meta_instance,
261 '... and we know it is cached' );
265 @cpl = $meta->class_precedence_list;
267 '... got the class precedence list okay';
270 [ 'Baz', 'Bar', 'Foo' ],
271 '... we just have ourselves in the class precedence list'
276 @attributes = $meta->get_all_attributes;
278 '... got the attribute list okay';
280 [ sort { $a->name cmp $b->name } @attributes ],
282 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
283 Bar->meta->get_attribute('baz')
285 '... got the right list of attributes'
289 # This test probably needs to go last since it will muck up the Foo class
291 my $meta = Foo->meta;
294 $meta->make_immutable(
295 inline_accessors => 0,
296 inline_constructor => 0,
297 constructor_name => 'newer',
301 { $meta->immutable_options },
303 inline_accessors => 0,
304 inline_constructor => 0,
305 inline_destructor => 0,
307 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
308 constructor_name => 'newer',
309 constructor_class => 'Class::MOP::Method::Constructor',
310 destructor_class => undef,
312 'custom immutable_options are returned by immutable_options accessor'