6 use Test::More tests => 85;
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');
79 my $transformer = $meta->get_immutable_transformer;
82 $meta->make_immutable();
83 } '... changed Foo to be immutable';
85 is($transformer, $meta->get_immutable_transformer, '... immutable transformer cache works');
86 ok(!$meta->make_immutable, '... make immutable now returns nothing');
88 ok(!$meta->is_mutable, '... our class is no longer mutable');
89 ok($meta->is_immutable, '... our class is now immutable');
91 isa_ok($meta, 'Class::MOP::Class');
93 dies_ok { $meta->add_method() } '... exception thrown as expected';
94 dies_ok { $meta->alias_method() } '... exception thrown as expected';
95 dies_ok { $meta->remove_method() } '... exception thrown as expected';
97 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
98 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
100 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
101 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
103 lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case';
107 @supers = $meta->superclasses;
108 } '... got the superclasses okay';
110 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
114 $meta_instance = $meta->get_meta_instance;
115 } '... got the meta instance okay';
116 isa_ok($meta_instance, 'Class::MOP::Instance');
117 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
121 @cpl = $meta->class_precedence_list;
122 } '... got the class precedence list okay';
126 '... we just have ourselves in the class precedence list');
130 @attributes = $meta->compute_all_applicable_attributes;
131 } '... got the attribute list okay';
134 [ $meta->get_attribute('bar') ],
135 '... got the right list of attributes');
139 my $meta = Bar->meta;
140 is($meta->name, 'Bar', '... checking the Bar metaclass');
142 ok($meta->is_mutable, '... our class is mutable');
143 ok(!$meta->is_immutable, '... our class is not immutable');
146 $meta->make_immutable();
147 } '... changed Bar to be immutable';
149 ok(!$meta->make_immutable, '... make immutable now returns nothing');
151 ok(!$meta->is_mutable, '... our class is no longer mutable');
152 ok($meta->is_immutable, '... our class is now immutable');
154 isa_ok($meta, 'Class::MOP::Class');
156 dies_ok { $meta->add_method() } '... exception thrown as expected';
157 dies_ok { $meta->alias_method() } '... exception thrown as expected';
158 dies_ok { $meta->remove_method() } '... exception thrown as expected';
160 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
161 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
163 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
164 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
168 @supers = $meta->superclasses;
169 } '... got the superclasses okay';
171 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
175 $meta_instance = $meta->get_meta_instance;
176 } '... got the meta instance okay';
177 isa_ok($meta_instance, 'Class::MOP::Instance');
178 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
182 @cpl = $meta->class_precedence_list;
183 } '... got the class precedence list okay';
187 '... we just have ourselves in the class precedence list');
191 @attributes = $meta->compute_all_applicable_attributes;
192 } '... got the attribute list okay';
194 [ sort { $a->name cmp $b->name } @attributes ],
195 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
196 '... got the right list of attributes');
200 my $meta = Baz->meta;
201 is($meta->name, 'Baz', '... checking the Baz metaclass');
203 ok($meta->is_mutable, '... our class is mutable');
204 ok(!$meta->is_immutable, '... our class is not immutable');
207 $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() } '... exception thrown as expected';
225 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
229 @supers = $meta->superclasses;
230 } '... got the superclasses okay';
232 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
236 $meta_instance = $meta->get_meta_instance;
237 } '... got the meta instance okay';
238 isa_ok($meta_instance, 'Class::MOP::Instance');
239 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
243 @cpl = $meta->class_precedence_list;
244 } '... got the class precedence list okay';
247 [ 'Baz', 'Bar', 'Foo'],
248 '... we just have ourselves in the class precedence list');
252 @attributes = $meta->compute_all_applicable_attributes;
253 } '... got the attribute list okay';
255 [ sort { $a->name cmp $b->name } @attributes ],
256 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
257 '... got the right list of attributes');