6 use Test::More tests => 77;
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->add_method() } '... exception thrown as expected';
64 dies_ok { $meta->alias_method() } '... exception thrown as expected';
65 dies_ok { $meta->remove_method() } '... exception thrown as expected';
67 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
68 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
70 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
71 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
75 @supers = $meta->superclasses;
76 } '... got the superclasses okay';
78 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
82 $meta_instance = $meta->get_meta_instance;
83 } '... got the meta instance okay';
84 isa_ok($meta_instance, 'Class::MOP::Instance');
85 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
89 @cpl = $meta->class_precedence_list;
90 } '... got the class precedence list okay';
94 '... we just have ourselves in the class precedence list');
98 @attributes = $meta->compute_all_applicable_attributes;
99 } '... got the attribute list okay';
102 [ $meta->get_attribute('bar') ],
103 '... got the right list of attributes');
107 my $meta = Bar->meta;
108 is($meta->name, 'Bar', '... checking the Bar metaclass');
110 ok($meta->is_mutable, '... our class is mutable');
111 ok(!$meta->is_immutable, '... our class is not immutable');
114 $meta->make_immutable();
115 } '... changed Bar to be immutable';
117 ok(!$meta->make_immutable, '... make immutable now returns nothing');
119 ok(!$meta->is_mutable, '... our class is no longer mutable');
120 ok($meta->is_immutable, '... our class is now immutable');
122 isa_ok($meta, 'Class::MOP::Class::Immutable');
123 isa_ok($meta, 'Class::MOP::Class');
125 dies_ok { $meta->add_method() } '... exception thrown as expected';
126 dies_ok { $meta->alias_method() } '... exception thrown as expected';
127 dies_ok { $meta->remove_method() } '... exception thrown as expected';
129 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
130 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
132 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
133 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
137 @supers = $meta->superclasses;
138 } '... got the superclasses okay';
140 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
144 $meta_instance = $meta->get_meta_instance;
145 } '... got the meta instance okay';
146 isa_ok($meta_instance, 'Class::MOP::Instance');
147 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
151 @cpl = $meta->class_precedence_list;
152 } '... got the class precedence list okay';
156 '... we just have ourselves in the class precedence list');
160 @attributes = $meta->compute_all_applicable_attributes;
161 } '... got the attribute list okay';
163 [ sort { $a->name cmp $b->name } @attributes ],
164 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
165 '... got the right list of attributes');
169 my $meta = Baz->meta;
170 is($meta->name, 'Baz', '... checking the Baz metaclass');
172 ok($meta->is_mutable, '... our class is mutable');
173 ok(!$meta->is_immutable, '... our class is not immutable');
176 $meta->make_immutable();
177 } '... changed Baz to be immutable';
179 ok(!$meta->make_immutable, '... make immutable now returns nothing');
181 ok(!$meta->is_mutable, '... our class is no longer mutable');
182 ok($meta->is_immutable, '... our class is now immutable');
184 isa_ok($meta, 'Class::MOP::Class::Immutable');
185 isa_ok($meta, 'Class::MOP::Class');
187 dies_ok { $meta->add_method() } '... exception thrown as expected';
188 dies_ok { $meta->alias_method() } '... exception thrown as expected';
189 dies_ok { $meta->remove_method() } '... exception thrown as expected';
191 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
192 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
194 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
195 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
199 @supers = $meta->superclasses;
200 } '... got the superclasses okay';
202 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
206 $meta_instance = $meta->get_meta_instance;
207 } '... got the meta instance okay';
208 isa_ok($meta_instance, 'Class::MOP::Instance');
209 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
213 @cpl = $meta->class_precedence_list;
214 } '... got the class precedence list okay';
217 [ 'Baz', 'Bar', 'Foo'],
218 '... we just have ourselves in the class precedence list');
222 @attributes = $meta->compute_all_applicable_attributes;
223 } '... got the attribute list okay';
225 [ sort { $a->name cmp $b->name } @attributes ],
226 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
227 '... got the right list of attributes');