6 use Test::More tests => 80;
11 use_ok('Class::MOP::Class::Immutable');
21 __PACKAGE__->meta->add_attribute('bar');
29 __PACKAGE__->meta->superclasses('Foo');
31 __PACKAGE__->meta->add_attribute('baz');
39 __PACKAGE__->meta->superclasses('Bar');
41 __PACKAGE__->meta->add_attribute('bah');
46 is($meta->name, 'Foo', '... checking the Foo metaclass');
48 ok($meta->is_mutable, '... our class is mutable');
49 ok(!$meta->is_immutable, '... our class is not immutable');
52 $meta->make_immutable();
53 } '... changed Foo to be immutable';
55 ok(!$meta->make_immutable, '... make immutable now returns nothing');
57 ok(!$meta->is_mutable, '... our class is no longer mutable');
58 ok($meta->is_immutable, '... our class is now immutable');
60 isa_ok($meta, 'Class::MOP::Class::Immutable');
61 isa_ok($meta, 'Class::MOP::Class');
63 dies_ok { $meta->reinitialize() } '... exception thrown as expected';
65 dies_ok { $meta->add_method() } '... exception thrown as expected';
66 dies_ok { $meta->alias_method() } '... exception thrown as expected';
67 dies_ok { $meta->remove_method() } '... exception thrown as expected';
69 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
70 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
72 dies_ok { $meta->add_package_variable() } '... exception thrown as expected';
73 dies_ok { $meta->remove_package_variable() } '... exception thrown as expected';
77 @supers = $meta->superclasses;
78 } '... got the superclasses okay';
80 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
84 $meta_instance = $meta->get_meta_instance;
85 } '... got the meta instance okay';
86 isa_ok($meta_instance, 'Class::MOP::Instance');
87 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
91 @cpl = $meta->class_precedence_list;
92 } '... got the class precedence list okay';
96 '... we just have ourselves in the class precedence list');
100 @attributes = $meta->compute_all_applicable_attributes;
101 } '... got the attribute list okay';
104 [ $meta->get_attribute('bar') ],
105 '... got the right list of attributes');
109 my $meta = Bar->meta;
110 is($meta->name, 'Bar', '... checking the Bar metaclass');
112 ok($meta->is_mutable, '... our class is mutable');
113 ok(!$meta->is_immutable, '... our class is not immutable');
116 $meta->make_immutable();
117 } '... changed Bar to be immutable';
119 ok(!$meta->make_immutable, '... make immutable now returns nothing');
121 ok(!$meta->is_mutable, '... our class is no longer mutable');
122 ok($meta->is_immutable, '... our class is now immutable');
124 isa_ok($meta, 'Class::MOP::Class::Immutable');
125 isa_ok($meta, 'Class::MOP::Class');
127 dies_ok { $meta->reinitialize() } '... exception thrown as expected';
129 dies_ok { $meta->add_method() } '... exception thrown as expected';
130 dies_ok { $meta->alias_method() } '... exception thrown as expected';
131 dies_ok { $meta->remove_method() } '... exception thrown as expected';
133 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
134 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
136 dies_ok { $meta->add_package_variable() } '... exception thrown as expected';
137 dies_ok { $meta->remove_package_variable() } '... exception thrown as expected';
141 @supers = $meta->superclasses;
142 } '... got the superclasses okay';
144 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
148 $meta_instance = $meta->get_meta_instance;
149 } '... got the meta instance okay';
150 isa_ok($meta_instance, 'Class::MOP::Instance');
151 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
155 @cpl = $meta->class_precedence_list;
156 } '... got the class precedence list okay';
160 '... we just have ourselves in the class precedence list');
164 @attributes = $meta->compute_all_applicable_attributes;
165 } '... got the attribute list okay';
167 [ sort { $a->name cmp $b->name } @attributes ],
168 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
169 '... got the right list of attributes');
173 my $meta = Baz->meta;
174 is($meta->name, 'Baz', '... checking the Baz metaclass');
176 ok($meta->is_mutable, '... our class is mutable');
177 ok(!$meta->is_immutable, '... our class is not immutable');
180 $meta->make_immutable();
181 } '... changed Baz to be immutable';
183 ok(!$meta->make_immutable, '... make immutable now returns nothing');
185 ok(!$meta->is_mutable, '... our class is no longer mutable');
186 ok($meta->is_immutable, '... our class is now immutable');
188 isa_ok($meta, 'Class::MOP::Class::Immutable');
189 isa_ok($meta, 'Class::MOP::Class');
191 dies_ok { $meta->reinitialize() } '... exception thrown as expected';
193 dies_ok { $meta->add_method() } '... exception thrown as expected';
194 dies_ok { $meta->alias_method() } '... exception thrown as expected';
195 dies_ok { $meta->remove_method() } '... exception thrown as expected';
197 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
198 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
200 dies_ok { $meta->add_package_variable() } '... exception thrown as expected';
201 dies_ok { $meta->remove_package_variable() } '... exception thrown as expected';
205 @supers = $meta->superclasses;
206 } '... got the superclasses okay';
208 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
212 $meta_instance = $meta->get_meta_instance;
213 } '... got the meta instance okay';
214 isa_ok($meta_instance, 'Class::MOP::Instance');
215 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
219 @cpl = $meta->class_precedence_list;
220 } '... got the class precedence list okay';
223 [ 'Baz', 'Bar', 'Foo'],
224 '... we just have ourselves in the class precedence list');
228 @attributes = $meta->compute_all_applicable_attributes;
229 } '... got the attribute list okay';
231 [ sort { $a->name cmp $b->name } @attributes ],
232 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
233 '... got the right list of attributes');