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 $obj = $immutable_metaclass->name;
49 ok( !$obj->is_mutable, '... immutable_metaclass is not mutable' );
50 ok( $obj->is_immutable, '... immutable_metaclass is immutable' );
51 ok( !$obj->make_immutable,
52 '... immutable_metaclass make_mutable is noop' );
53 is( $obj->meta, $immutable_metaclass,
54 '... immutable_metaclass meta hack works' );
56 isa_ok( $meta, "Class::MOP::Class::Immutable::Trait" );
57 isa_ok( $meta, "Class::MOP::Class" );
63 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
65 ok( !$meta->is_mutable, '... our class is not mutable' );
66 ok( $meta->is_immutable, '... our class is immutable' );
68 isa_ok( $meta, 'Class::MOP::Class' );
70 dies_ok { $meta->add_method() } '... exception thrown as expected';
71 dies_ok { $meta->alias_method() } '... exception thrown as expected';
72 dies_ok { $meta->remove_method() } '... exception thrown as expected';
74 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
75 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
77 dies_ok { $meta->add_package_symbol() }
78 '... exception thrown as expected';
79 dies_ok { $meta->remove_package_symbol() }
80 '... exception thrown as expected';
82 lives_ok { $meta->identifier() }
83 '... no exception for get_package_symbol special case';
87 @supers = $meta->superclasses;
89 '... got the superclasses okay';
91 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
92 '... but could not set the superclasses okay';
96 $meta_instance = $meta->get_meta_instance;
98 '... got the meta instance okay';
99 isa_ok( $meta_instance, 'Class::MOP::Instance' );
100 is( $meta_instance, $meta->get_meta_instance,
101 '... and we know it is cached' );
105 @cpl = $meta->class_precedence_list;
107 '... got the class precedence list okay';
111 '... we just have ourselves in the class precedence list'
116 @attributes = $meta->get_all_attributes;
118 '... got the attribute list okay';
121 [ $meta->get_attribute('bar') ],
122 '... got the right list of attributes'
127 my $meta = Bar->meta;
128 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
130 ok( $meta->is_mutable, '... our class is mutable' );
131 ok( !$meta->is_immutable, '... our class is not immutable' );
134 $meta->make_immutable();
136 '... changed Bar to be immutable';
138 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
140 ok( !$meta->is_mutable, '... our class is no longer mutable' );
141 ok( $meta->is_immutable, '... our class is now immutable' );
143 isa_ok( $meta, 'Class::MOP::Class' );
145 dies_ok { $meta->add_method() } '... exception thrown as expected';
146 dies_ok { $meta->alias_method() } '... exception thrown as expected';
147 dies_ok { $meta->remove_method() } '... exception thrown as expected';
149 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
150 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
152 dies_ok { $meta->add_package_symbol() }
153 '... exception thrown as expected';
154 dies_ok { $meta->remove_package_symbol() }
155 '... exception thrown as expected';
159 @supers = $meta->superclasses;
161 '... got the superclasses okay';
163 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
164 '... but could not set the superclasses okay';
168 $meta_instance = $meta->get_meta_instance;
170 '... got the meta instance okay';
171 isa_ok( $meta_instance, 'Class::MOP::Instance' );
172 is( $meta_instance, $meta->get_meta_instance,
173 '... and we know it is cached' );
177 @cpl = $meta->class_precedence_list;
179 '... got the class precedence list okay';
183 '... we just have ourselves in the class precedence list'
188 @attributes = $meta->get_all_attributes;
190 '... got the attribute list okay';
192 [ sort { $a->name cmp $b->name } @attributes ],
193 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
194 '... got the right list of attributes'
199 my $meta = Baz->meta;
200 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
202 ok( $meta->is_mutable, '... our class is mutable' );
203 ok( !$meta->is_immutable, '... our class is not immutable' );
206 $meta->make_immutable();
208 '... changed Baz to be immutable';
210 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
212 ok( !$meta->is_mutable, '... our class is no longer mutable' );
213 ok( $meta->is_immutable, '... our class is now immutable' );
215 isa_ok( $meta, 'Class::MOP::Class' );
217 dies_ok { $meta->add_method() } '... exception thrown as expected';
218 dies_ok { $meta->alias_method() } '... exception thrown as expected';
219 dies_ok { $meta->remove_method() } '... exception thrown as expected';
221 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
222 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
224 dies_ok { $meta->add_package_symbol() }
225 '... exception thrown as expected';
226 dies_ok { $meta->remove_package_symbol() }
227 '... exception thrown as expected';
231 @supers = $meta->superclasses;
233 '... got the superclasses okay';
235 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
236 '... but could not set the superclasses okay';
240 $meta_instance = $meta->get_meta_instance;
242 '... got the meta instance okay';
243 isa_ok( $meta_instance, 'Class::MOP::Instance' );
244 is( $meta_instance, $meta->get_meta_instance,
245 '... and we know it is cached' );
249 @cpl = $meta->class_precedence_list;
251 '... got the class precedence list okay';
254 [ 'Baz', 'Bar', 'Foo' ],
255 '... we just have ourselves in the class precedence list'
260 @attributes = $meta->get_all_attributes;
262 '... got the attribute list okay';
264 [ sort { $a->name cmp $b->name } @attributes ],
266 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
267 Bar->meta->get_attribute('baz')
269 '... got the right list of attributes'