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 ok( $meta->make_immutable, 'make_immutable returns true' );
49 my $line = __LINE__ - 1;
51 ok( $meta->make_immutable, 'make_immutable still returns true' );
53 my $immutable_metaclass = $meta->_immutable_metaclass->meta;
55 my $immutable_class_name = $immutable_metaclass->name;
57 ok( !$immutable_class_name->is_mutable, '... immutable_metaclass is not mutable' );
58 ok( $immutable_class_name->is_immutable, '... immutable_metaclass is immutable' );
59 is( $immutable_class_name->meta, $immutable_metaclass,
60 '... immutable_metaclass meta hack works' );
63 { $meta->immutable_options },
65 inline_accessors => 1,
66 inline_constructor => 1,
67 inline_destructor => 0,
69 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
70 constructor_name => 'new',
71 constructor_class => 'Class::MOP::Method::Constructor',
72 destructor_class => undef,
76 'immutable_options is empty before a class is made_immutable'
79 isa_ok( $meta, "Class::MOP::Class" );
84 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
86 ok( !$meta->is_mutable, '... our class is not mutable' );
87 ok( $meta->is_immutable, '... our class is immutable' );
89 isa_ok( $meta, 'Class::MOP::Class' );
91 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
92 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
93 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
95 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
96 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
98 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
99 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
101 is( exception { $meta->identifier() }, undef, '... no exception for get_package_symbol special case' );
105 @supers = $meta->superclasses;
106 }, undef, '... got the superclasses okay' );
108 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
112 $meta_instance = $meta->get_meta_instance;
113 }, undef, '... got the meta instance okay' );
114 isa_ok( $meta_instance, 'Class::MOP::Instance' );
115 is( $meta_instance, $meta->get_meta_instance,
116 '... and we know it is cached' );
120 @cpl = $meta->class_precedence_list;
121 }, undef, '... got the class precedence list okay' );
125 '... we just have ourselves in the class precedence list'
130 @attributes = $meta->get_all_attributes;
131 }, undef, '... got the attribute list okay' );
134 [ $meta->get_attribute('bar') ],
135 '... got the right list of attributes'
140 my $meta = Bar->meta;
141 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
143 ok( $meta->is_mutable, '... our class is mutable' );
144 ok( !$meta->is_immutable, '... our class is not immutable' );
147 $meta->make_immutable();
148 }, undef, '... changed Bar to be immutable' );
150 ok( $meta->make_immutable, '... make immutable returns true' );
152 ok( !$meta->is_mutable, '... our class is no longer mutable' );
153 ok( $meta->is_immutable, '... our class is now immutable' );
155 isa_ok( $meta, 'Class::MOP::Class' );
157 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
158 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
159 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
161 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
162 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
164 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
165 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
169 @supers = $meta->superclasses;
170 }, undef, '... got the superclasses okay' );
172 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
176 $meta_instance = $meta->get_meta_instance;
177 }, undef, '... got the meta instance okay' );
178 isa_ok( $meta_instance, 'Class::MOP::Instance' );
179 is( $meta_instance, $meta->get_meta_instance,
180 '... and we know it is cached' );
184 @cpl = $meta->class_precedence_list;
185 }, undef, '... got the class precedence list okay' );
189 '... we just have ourselves in the class precedence list'
194 @attributes = $meta->get_all_attributes;
195 }, undef, '... got the attribute list okay' );
197 [ sort { $a->name cmp $b->name } @attributes ],
198 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
199 '... got the right list of attributes'
204 my $meta = Baz->meta;
205 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
207 ok( $meta->is_mutable, '... our class is mutable' );
208 ok( !$meta->is_immutable, '... our class is not immutable' );
211 $meta->make_immutable();
212 }, undef, '... changed Baz to be immutable' );
214 ok( $meta->make_immutable, '... make immutable returns true' );
216 ok( !$meta->is_mutable, '... our class is no longer mutable' );
217 ok( $meta->is_immutable, '... our class is now immutable' );
219 isa_ok( $meta, 'Class::MOP::Class' );
221 isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
222 isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
223 isnt( exception { $meta->remove_method() }, undef, '... exception thrown as expected' );
225 isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
226 isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
228 isnt( exception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
229 isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
233 @supers = $meta->superclasses;
234 }, undef, '... got the superclasses okay' );
236 isnt( exception { $meta->superclasses( ['UNIVERSAL'] ) }, undef, '... but could not set the superclasses okay' );
240 $meta_instance = $meta->get_meta_instance;
241 }, undef, '... got the meta instance okay' );
242 isa_ok( $meta_instance, 'Class::MOP::Instance' );
243 is( $meta_instance, $meta->get_meta_instance,
244 '... and we know it is cached' );
248 @cpl = $meta->class_precedence_list;
249 }, undef, '... got the class precedence list okay' );
252 [ 'Baz', 'Bar', 'Foo' ],
253 '... we just have ourselves in the class precedence list'
258 @attributes = $meta->get_all_attributes;
259 }, undef, '... got the attribute list okay' );
261 [ sort { $a->name cmp $b->name } @attributes ],
263 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
264 Bar->meta->get_attribute('baz')
266 '... got the right list of attributes'
270 # This test probably needs to go last since it will muck up the Foo class
272 my $meta = Foo->meta;
275 $meta->make_immutable(
276 inline_accessors => 0,
277 inline_constructor => 0,
278 constructor_name => 'newer',
280 my $line = __LINE__ - 5;
283 { $meta->immutable_options },
285 inline_accessors => 0,
286 inline_constructor => 0,
287 inline_destructor => 0,
289 immutable_trait => 'Class::MOP::Class::Immutable::Trait',
290 constructor_name => 'newer',
291 constructor_class => 'Class::MOP::Method::Constructor',
292 destructor_class => undef,
296 'custom immutable_options are returned by immutable_options accessor'