6 use Test::More tests => 84;
20 __PACKAGE__->meta->add_attribute('bar');
28 __PACKAGE__->meta->superclasses('Foo');
30 __PACKAGE__->meta->add_attribute('baz');
38 __PACKAGE__->meta->superclasses('Bar');
40 __PACKAGE__->meta->add_attribute('bah');
47 lives_ok{ $transformer = $meta->create_immutable_transformer }
48 "Created immutable transformer";
49 isa_ok($transformer, 'Class::MOP::Immutable', '... transformer isa Class::MOP::Immutable');
50 my $methods = $transformer->create_methods_for_immutable_metaclass;
52 my $immutable_metaclass = $transformer->immutable_metaclass;
53 is($transformer->metaclass, $meta, '... transformer has correct metaclass');
54 ok($immutable_metaclass->is_anon_class, '... immutable_metaclass is an anonymous class');
56 #I don't understand why i need to ->meta here...
57 my $obj = $immutable_metaclass->name;
58 ok(!$obj->is_mutable, '... immutable_metaclass is not mutable');
59 ok($obj->is_immutable, '... immutable_metaclass is immutable');
60 ok(!$obj->make_immutable, '... immutable_metaclass make_mutable is noop');
61 is($obj->meta, $immutable_metaclass, '... immutable_metaclass meta hack works');
64 [ $immutable_metaclass->superclasses ],
65 [ Scalar::Util::blessed($meta) ],
66 '... immutable_metaclass superclasses are correct'
68 ok($immutable_metaclass->has_method('get_mutable_metaclass_name'));
74 is($meta->name, 'Foo', '... checking the Foo metaclass');
76 ok($meta->is_mutable, '... our class is mutable');
77 ok(!$meta->is_immutable, '... our class is not immutable');
80 $meta->make_immutable();
81 } '... changed Foo to be immutable';
83 ok(!$meta->make_immutable, '... make immutable now returns nothing');
85 ok(!$meta->is_mutable, '... our class is no longer mutable');
86 ok($meta->is_immutable, '... our class is now immutable');
88 isa_ok($meta, 'Class::MOP::Class');
90 dies_ok { $meta->add_method() } '... exception thrown as expected';
91 dies_ok { $meta->alias_method() } '... exception thrown as expected';
92 dies_ok { $meta->remove_method() } '... exception thrown as expected';
94 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
95 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
97 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
98 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
100 lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case';
104 @supers = $meta->superclasses;
105 } '... got the superclasses okay';
107 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
111 $meta_instance = $meta->get_meta_instance;
112 } '... got the meta instance okay';
113 isa_ok($meta_instance, 'Class::MOP::Instance');
114 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
118 @cpl = $meta->class_precedence_list;
119 } '... got the class precedence list okay';
123 '... we just have ourselves in the class precedence list');
127 @attributes = $meta->compute_all_applicable_attributes;
128 } '... got the attribute list okay';
131 [ $meta->get_attribute('bar') ],
132 '... got the right list of attributes');
136 my $meta = Bar->meta;
137 is($meta->name, 'Bar', '... checking the Bar metaclass');
139 ok($meta->is_mutable, '... our class is mutable');
140 ok(!$meta->is_immutable, '... our class is not immutable');
143 $meta->make_immutable();
144 } '... changed Bar to be immutable';
146 ok(!$meta->make_immutable, '... make immutable now returns nothing');
148 ok(!$meta->is_mutable, '... our class is no longer mutable');
149 ok($meta->is_immutable, '... our class is now immutable');
151 isa_ok($meta, 'Class::MOP::Class');
153 dies_ok { $meta->add_method() } '... exception thrown as expected';
154 dies_ok { $meta->alias_method() } '... exception thrown as expected';
155 dies_ok { $meta->remove_method() } '... exception thrown as expected';
157 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
158 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
160 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
161 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
165 @supers = $meta->superclasses;
166 } '... got the superclasses okay';
168 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
172 $meta_instance = $meta->get_meta_instance;
173 } '... got the meta instance okay';
174 isa_ok($meta_instance, 'Class::MOP::Instance');
175 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
179 @cpl = $meta->class_precedence_list;
180 } '... got the class precedence list okay';
184 '... we just have ourselves in the class precedence list');
188 @attributes = $meta->compute_all_applicable_attributes;
189 } '... got the attribute list okay';
191 [ sort { $a->name cmp $b->name } @attributes ],
192 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
193 '... 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();
205 } '... changed Baz to be immutable';
207 ok(!$meta->make_immutable, '... make immutable now returns nothing');
209 ok(!$meta->is_mutable, '... our class is no longer mutable');
210 ok($meta->is_immutable, '... our class is now immutable');
212 isa_ok($meta, 'Class::MOP::Class');
214 dies_ok { $meta->add_method() } '... exception thrown as expected';
215 dies_ok { $meta->alias_method() } '... exception thrown as expected';
216 dies_ok { $meta->remove_method() } '... exception thrown as expected';
218 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
219 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
221 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
222 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
226 @supers = $meta->superclasses;
227 } '... got the superclasses okay';
229 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
233 $meta_instance = $meta->get_meta_instance;
234 } '... got the meta instance okay';
235 isa_ok($meta_instance, 'Class::MOP::Instance');
236 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
240 @cpl = $meta->class_precedence_list;
241 } '... got the class precedence list okay';
244 [ 'Baz', 'Bar', 'Foo'],
245 '... we just have ourselves in the class precedence list');
249 @attributes = $meta->compute_all_applicable_attributes;
250 } '... got the attribute list okay';
252 [ sort { $a->name cmp $b->name } @attributes ],
253 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
254 '... got the right list of attributes');