4 use Test::More tests => 75;
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 $immutable_metaclass = $meta->_immutable_metaclass->meta;
47 my $immutable_class_name = $immutable_metaclass->name;
49 ok( !$immutable_class_name->is_mutable, '... immutable_metaclass is not mutable' );
50 ok( $immutable_class_name->is_immutable, '... immutable_metaclass is immutable' );
51 is( $immutable_class_name->meta, $immutable_metaclass,
52 '... immutable_metaclass meta hack works' );
54 isa_ok( $meta, "Class::MOP::Class::Immutable::Trait" );
55 isa_ok( $meta, "Class::MOP::Class" );
61 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
63 ok( !$meta->is_mutable, '... our class is not mutable' );
64 ok( $meta->is_immutable, '... our class is immutable' );
66 isa_ok( $meta, 'Class::MOP::Class' );
68 dies_ok { $meta->add_method() } '... exception thrown as expected';
69 dies_ok { $meta->alias_method() } '... exception thrown as expected';
70 dies_ok { $meta->remove_method() } '... exception thrown as expected';
72 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
73 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
75 dies_ok { $meta->add_package_symbol() }
76 '... exception thrown as expected';
77 dies_ok { $meta->remove_package_symbol() }
78 '... exception thrown as expected';
80 lives_ok { $meta->identifier() }
81 '... no exception for get_package_symbol special case';
85 @supers = $meta->superclasses;
87 '... got the superclasses okay';
89 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
90 '... but could not set the superclasses okay';
94 $meta_instance = $meta->get_meta_instance;
96 '... got the meta instance okay';
97 isa_ok( $meta_instance, 'Class::MOP::Instance' );
98 is( $meta_instance, $meta->get_meta_instance,
99 '... and we know it is cached' );
103 @cpl = $meta->class_precedence_list;
105 '... got the class precedence list okay';
109 '... we just have ourselves in the class precedence list'
114 @attributes = $meta->get_all_attributes;
116 '... got the attribute list okay';
119 [ $meta->get_attribute('bar') ],
120 '... got the right list of attributes'
125 my $meta = Bar->meta;
126 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
128 ok( $meta->is_mutable, '... our class is mutable' );
129 ok( !$meta->is_immutable, '... our class is not immutable' );
132 $meta->make_immutable();
134 '... changed Bar to be immutable';
136 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
138 ok( !$meta->is_mutable, '... our class is no longer mutable' );
139 ok( $meta->is_immutable, '... our class is now immutable' );
141 isa_ok( $meta, 'Class::MOP::Class' );
143 dies_ok { $meta->add_method() } '... exception thrown as expected';
144 dies_ok { $meta->alias_method() } '... exception thrown as expected';
145 dies_ok { $meta->remove_method() } '... exception thrown as expected';
147 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
148 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
150 dies_ok { $meta->add_package_symbol() }
151 '... exception thrown as expected';
152 dies_ok { $meta->remove_package_symbol() }
153 '... exception thrown as expected';
157 @supers = $meta->superclasses;
159 '... got the superclasses okay';
161 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
162 '... but could not set the superclasses okay';
166 $meta_instance = $meta->get_meta_instance;
168 '... got the meta instance okay';
169 isa_ok( $meta_instance, 'Class::MOP::Instance' );
170 is( $meta_instance, $meta->get_meta_instance,
171 '... and we know it is cached' );
175 @cpl = $meta->class_precedence_list;
177 '... got the class precedence list okay';
181 '... we just have ourselves in the class precedence list'
186 @attributes = $meta->get_all_attributes;
188 '... got the attribute list okay';
190 [ sort { $a->name cmp $b->name } @attributes ],
191 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
192 '... got the right list of attributes'
197 my $meta = Baz->meta;
198 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
200 ok( $meta->is_mutable, '... our class is mutable' );
201 ok( !$meta->is_immutable, '... our class is not immutable' );
204 $meta->make_immutable();
206 '... changed Baz to be immutable';
208 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
210 ok( !$meta->is_mutable, '... our class is no longer mutable' );
211 ok( $meta->is_immutable, '... our class is now immutable' );
213 isa_ok( $meta, 'Class::MOP::Class' );
215 dies_ok { $meta->add_method() } '... exception thrown as expected';
216 dies_ok { $meta->alias_method() } '... exception thrown as expected';
217 dies_ok { $meta->remove_method() } '... exception thrown as expected';
219 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
220 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
222 dies_ok { $meta->add_package_symbol() }
223 '... exception thrown as expected';
224 dies_ok { $meta->remove_package_symbol() }
225 '... exception thrown as expected';
229 @supers = $meta->superclasses;
231 '... got the superclasses okay';
233 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
234 '... but could not set the superclasses okay';
238 $meta_instance = $meta->get_meta_instance;
240 '... got the meta instance okay';
241 isa_ok( $meta_instance, 'Class::MOP::Instance' );
242 is( $meta_instance, $meta->get_meta_instance,
243 '... and we know it is cached' );
247 @cpl = $meta->class_precedence_list;
249 '... 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;
260 '... got the attribute list okay';
262 [ sort { $a->name cmp $b->name } @attributes ],
264 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
265 Bar->meta->get_attribute('baz')
267 '... got the right list of attributes'