4 use Test::More tests => 73;
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" );
59 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
61 ok( !$meta->is_mutable, '... our class is not mutable' );
62 ok( $meta->is_immutable, '... our class is immutable' );
64 isa_ok( $meta, 'Class::MOP::Class' );
66 dies_ok { $meta->add_method() } '... exception thrown as expected';
67 dies_ok { $meta->alias_method() } '... exception thrown as expected';
68 dies_ok { $meta->remove_method() } '... exception thrown as expected';
70 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
71 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
73 dies_ok { $meta->add_package_symbol() }
74 '... exception thrown as expected';
75 dies_ok { $meta->remove_package_symbol() }
76 '... exception thrown as expected';
78 lives_ok { $meta->identifier() }
79 '... no exception for get_package_symbol special case';
83 @supers = $meta->superclasses;
85 '... got the superclasses okay';
87 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
88 '... but could not set the superclasses okay';
92 $meta_instance = $meta->get_meta_instance;
94 '... got the meta instance okay';
95 isa_ok( $meta_instance, 'Class::MOP::Instance' );
96 is( $meta_instance, $meta->get_meta_instance,
97 '... and we know it is cached' );
101 @cpl = $meta->class_precedence_list;
103 '... got the class precedence list okay';
107 '... we just have ourselves in the class precedence list'
112 @attributes = $meta->get_all_attributes;
114 '... got the attribute list okay';
117 [ $meta->get_attribute('bar') ],
118 '... got the right list of attributes'
123 my $meta = Bar->meta;
124 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
126 ok( $meta->is_mutable, '... our class is mutable' );
127 ok( !$meta->is_immutable, '... our class is not immutable' );
130 $meta->make_immutable();
132 '... changed Bar to be immutable';
134 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
136 ok( !$meta->is_mutable, '... our class is no longer mutable' );
137 ok( $meta->is_immutable, '... our class is now immutable' );
139 isa_ok( $meta, 'Class::MOP::Class' );
141 dies_ok { $meta->add_method() } '... exception thrown as expected';
142 dies_ok { $meta->alias_method() } '... exception thrown as expected';
143 dies_ok { $meta->remove_method() } '... exception thrown as expected';
145 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
146 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
148 dies_ok { $meta->add_package_symbol() }
149 '... exception thrown as expected';
150 dies_ok { $meta->remove_package_symbol() }
151 '... exception thrown as expected';
155 @supers = $meta->superclasses;
157 '... got the superclasses okay';
159 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
160 '... but could not set the superclasses okay';
164 $meta_instance = $meta->get_meta_instance;
166 '... got the meta instance okay';
167 isa_ok( $meta_instance, 'Class::MOP::Instance' );
168 is( $meta_instance, $meta->get_meta_instance,
169 '... and we know it is cached' );
173 @cpl = $meta->class_precedence_list;
175 '... got the class precedence list okay';
179 '... we just have ourselves in the class precedence list'
184 @attributes = $meta->get_all_attributes;
186 '... got the attribute list okay';
188 [ sort { $a->name cmp $b->name } @attributes ],
189 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
190 '... got the right list of attributes'
195 my $meta = Baz->meta;
196 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
198 ok( $meta->is_mutable, '... our class is mutable' );
199 ok( !$meta->is_immutable, '... our class is not immutable' );
202 $meta->make_immutable();
204 '... changed Baz to be immutable';
206 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
208 ok( !$meta->is_mutable, '... our class is no longer mutable' );
209 ok( $meta->is_immutable, '... our class is now immutable' );
211 isa_ok( $meta, 'Class::MOP::Class' );
213 dies_ok { $meta->add_method() } '... exception thrown as expected';
214 dies_ok { $meta->alias_method() } '... exception thrown as expected';
215 dies_ok { $meta->remove_method() } '... exception thrown as expected';
217 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
218 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
220 dies_ok { $meta->add_package_symbol() }
221 '... exception thrown as expected';
222 dies_ok { $meta->remove_package_symbol() }
223 '... exception thrown as expected';
227 @supers = $meta->superclasses;
229 '... got the superclasses okay';
231 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
232 '... but could not set the superclasses okay';
236 $meta_instance = $meta->get_meta_instance;
238 '... got the meta instance okay';
239 isa_ok( $meta_instance, 'Class::MOP::Instance' );
240 is( $meta_instance, $meta->get_meta_instance,
241 '... and we know it is cached' );
245 @cpl = $meta->class_precedence_list;
247 '... 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;
258 '... got the attribute list okay';
260 [ sort { $a->name cmp $b->name } @attributes ],
262 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
263 Bar->meta->get_attribute('baz')
265 '... got the right list of attributes'