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;
49 my $line = __LINE__ - 1;
51 my $immutable_metaclass = $meta->_immutable_metaclass->meta;
53 my $immutable_class_name = $immutable_metaclass->name;
55 ok( !$immutable_class_name->is_mutable, '... immutable_metaclass is not mutable' );
56 ok( $immutable_class_name->is_immutable, '... immutable_metaclass is immutable' );
57 is( $immutable_class_name->meta, $immutable_metaclass,
58 '... immutable_metaclass meta hack works' );
61 { $meta->immutable_options },
63 inline_accessors => 1,
64 inline_constructor => 1,
65 inline_destructor => 0,
67 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
68 constructor_name => 'new',
69 constructor_class => 'Class::MOP::Method::Constructor',
70 destructor_class => undef,
74 'immutable_options is empty before a class is made_immutable'
77 isa_ok( $meta, "Class::MOP::Class" );
82 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
84 ok( !$meta->is_mutable, '... our class is not mutable' );
85 ok( $meta->is_immutable, '... our class is immutable' );
87 isa_ok( $meta, 'Class::MOP::Class' );
89 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
90 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
91 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
93 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
94 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
96 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
97 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
99 is( exception { $meta->identifier() }, undef, '... no exception for get_package_symbol special case' );
103 @supers = $meta->superclasses;
104 }, undef, '... got the superclasses okay' );
106 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
110 $meta_instance = $meta->get_meta_instance;
111 }, undef, '... got the meta instance okay' );
112 isa_ok( $meta_instance, 'Class::MOP::Instance' );
113 is( $meta_instance, $meta->get_meta_instance,
114 '... and we know it is cached' );
118 @cpl = $meta->class_precedence_list;
119 }, undef, '... got the class precedence list okay' );
123 '... we just have ourselves in the class precedence list'
128 @attributes = $meta->get_all_attributes;
129 }, undef, '... got the attribute list okay' );
132 [ $meta->get_attribute('bar') ],
133 '... got the right list of attributes'
138 my $meta = Bar->meta;
139 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
141 ok( $meta->is_mutable, '... our class is mutable' );
142 ok( !$meta->is_immutable, '... our class is not immutable' );
145 $meta->make_immutable();
146 }, undef, '... changed Bar to be immutable' );
148 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
150 ok( !$meta->is_mutable, '... our class is no longer mutable' );
151 ok( $meta->is_immutable, '... our class is now immutable' );
153 isa_ok( $meta, 'Class::MOP::Class' );
155 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
156 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
157 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
159 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
160 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
162 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
163 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
167 @supers = $meta->superclasses;
168 }, undef, '... got the superclasses okay' );
170 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
174 $meta_instance = $meta->get_meta_instance;
175 }, undef, '... got the meta instance okay' );
176 isa_ok( $meta_instance, 'Class::MOP::Instance' );
177 is( $meta_instance, $meta->get_meta_instance,
178 '... and we know it is cached' );
182 @cpl = $meta->class_precedence_list;
183 }, undef, '... got the class precedence list okay' );
187 '... we just have ourselves in the class precedence list'
192 @attributes = $meta->get_all_attributes;
193 }, undef, '... got the attribute list okay' );
195 [ sort { $a->name cmp $b->name } @attributes ],
196 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
197 '... got the right list of attributes'
202 my $meta = Baz->meta;
203 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
205 ok( $meta->is_mutable, '... our class is mutable' );
206 ok( !$meta->is_immutable, '... our class is not immutable' );
209 $meta->make_immutable();
210 }, undef, '... changed Baz to be immutable' );
212 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
214 ok( !$meta->is_mutable, '... our class is no longer mutable' );
215 ok( $meta->is_immutable, '... our class is now immutable' );
217 isa_ok( $meta, 'Class::MOP::Class' );
219 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
220 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
221 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
223 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
224 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
226 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
227 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
231 @supers = $meta->superclasses;
232 }, undef, '... got the superclasses okay' );
234 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
238 $meta_instance = $meta->get_meta_instance;
239 }, undef, '... got the meta instance okay' );
240 isa_ok( $meta_instance, 'Class::MOP::Instance' );
241 is( $meta_instance, $meta->get_meta_instance,
242 '... and we know it is cached' );
246 @cpl = $meta->class_precedence_list;
247 }, undef, '... got the class precedence list okay' );
250 [ 'Baz', 'Bar', 'Foo' ],
251 '... we just have ourselves in the class precedence list'
256 @attributes = $meta->get_all_attributes;
257 }, undef, '... got the attribute list okay' );
259 [ sort { $a->name cmp $b->name } @attributes ],
261 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
262 Bar->meta->get_attribute('baz')
264 '... got the right list of attributes'
268 # This test probably needs to go last since it will muck up the Foo class
270 my $meta = Foo->meta;
273 $meta->make_immutable(
274 inline_accessors => 0,
275 inline_constructor => 0,
276 constructor_name => 'newer',
278 my $line = __LINE__ - 5;
281 { $meta->immutable_options },
283 inline_accessors => 0,
284 inline_constructor => 0,
285 inline_destructor => 0,
287 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
288 constructor_name => 'newer',
289 constructor_class => 'Class::MOP::Method::Constructor',
290 destructor_class => undef,
294 'custom immutable_options are returned by immutable_options accessor'