6 use Test::More tests => 86;
18 __PACKAGE__->meta->add_attribute('bar');
26 __PACKAGE__->meta->superclasses('Foo');
28 __PACKAGE__->meta->add_attribute('baz');
36 __PACKAGE__->meta->superclasses('Bar');
38 __PACKAGE__->meta->add_attribute('bah');
45 lives_ok{ $transformer = $meta->create_immutable_transformer }
46 "Created immutable transformer";
47 isa_ok($transformer, 'Class::MOP::Immutable', '... transformer isa Class::MOP::Immutable');
48 my $methods = $transformer->create_methods_for_immutable_metaclass;
50 my $immutable_metaclass = $transformer->immutable_metaclass;
51 is($transformer->metaclass, $meta, '... transformer has correct metaclass');
52 ok(!$transformer->inlined_constructor, '... transformer says it did not inline the constructor');
53 ok($immutable_metaclass->is_anon_class, '... immutable_metaclass is an anonymous class');
55 #I don't understand why i need to ->meta here...
56 my $obj = $immutable_metaclass->name;
57 ok(!$obj->is_mutable, '... immutable_metaclass is not mutable');
58 ok($obj->is_immutable, '... immutable_metaclass is immutable');
59 ok(!$obj->make_immutable, '... immutable_metaclass make_mutable is noop');
60 is($obj->meta, $immutable_metaclass, '... immutable_metaclass meta hack works');
63 [ $immutable_metaclass->superclasses ],
64 [ Scalar::Util::blessed($meta) ],
65 '... immutable_metaclass superclasses are correct'
67 ok($immutable_metaclass->has_method('get_mutable_metaclass_name'),
68 'immutable metaclass has get_mutable_metaclass_name method');
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 ok($transformer->inlined_constructor, '... transformer says it did inline the constructor');
86 is($transformer, $meta->get_immutable_transformer, '... immutable transformer cache works');
87 ok(!$meta->make_immutable, '... make immutable now returns nothing');
89 ok(!$meta->is_mutable, '... our class is no longer mutable');
90 ok($meta->is_immutable, '... our class is now immutable');
92 isa_ok($meta, 'Class::MOP::Class');
94 dies_ok { $meta->add_method() } '... exception thrown as expected';
95 dies_ok { $meta->alias_method() } '... exception thrown as expected';
96 dies_ok { $meta->remove_method() } '... exception thrown as expected';
98 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
99 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
101 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
102 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
104 lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case';
108 @supers = $meta->superclasses;
109 } '... got the superclasses okay';
111 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
115 $meta_instance = $meta->get_meta_instance;
116 } '... got the meta instance okay';
117 isa_ok($meta_instance, 'Class::MOP::Instance');
118 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
122 @cpl = $meta->class_precedence_list;
123 } '... got the class precedence list okay';
127 '... we just have ourselves in the class precedence list');
131 @attributes = $meta->compute_all_applicable_attributes;
132 } '... got the attribute list okay';
135 [ $meta->get_attribute('bar') ],
136 '... got the right list of attributes');
140 my $meta = Bar->meta;
141 is($meta->name, 'Bar', '... checking the Bar metaclass');
143 ok($meta->is_mutable, '... our class is mutable');
144 ok(!$meta->is_immutable, '... our class is not immutable');
147 $meta->make_immutable();
148 } '... changed Bar to be immutable';
150 ok(!$meta->make_immutable, '... make immutable now returns nothing');
152 ok(!$meta->is_mutable, '... our class is no longer mutable');
153 ok($meta->is_immutable, '... our class is now immutable');
155 isa_ok($meta, 'Class::MOP::Class');
157 dies_ok { $meta->add_method() } '... exception thrown as expected';
158 dies_ok { $meta->alias_method() } '... exception thrown as expected';
159 dies_ok { $meta->remove_method() } '... exception thrown as expected';
161 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
162 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
164 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
165 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
169 @supers = $meta->superclasses;
170 } '... got the superclasses okay';
172 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
176 $meta_instance = $meta->get_meta_instance;
177 } '... got the meta instance okay';
178 isa_ok($meta_instance, 'Class::MOP::Instance');
179 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
183 @cpl = $meta->class_precedence_list;
184 } '... got the class precedence list okay';
188 '... we just have ourselves in the class precedence list');
192 @attributes = $meta->compute_all_applicable_attributes;
193 } '... got the attribute list okay';
195 [ sort { $a->name cmp $b->name } @attributes ],
196 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
197 '... got the right list of attributes');
201 my $meta = Baz->meta;
202 is($meta->name, 'Baz', '... checking the Baz metaclass');
204 ok($meta->is_mutable, '... our class is mutable');
205 ok(!$meta->is_immutable, '... our class is not immutable');
208 $meta->make_immutable();
209 } '... changed Baz to be immutable';
211 ok(!$meta->make_immutable, '... make immutable now returns nothing');
213 ok(!$meta->is_mutable, '... our class is no longer mutable');
214 ok($meta->is_immutable, '... our class is now immutable');
216 isa_ok($meta, 'Class::MOP::Class');
218 dies_ok { $meta->add_method() } '... exception thrown as expected';
219 dies_ok { $meta->alias_method() } '... exception thrown as expected';
220 dies_ok { $meta->remove_method() } '... exception thrown as expected';
222 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
223 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
225 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
226 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
230 @supers = $meta->superclasses;
231 } '... got the superclasses okay';
233 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
237 $meta_instance = $meta->get_meta_instance;
238 } '... got the meta instance okay';
239 isa_ok($meta_instance, 'Class::MOP::Instance');
240 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
244 @cpl = $meta->class_precedence_list;
245 } '... got the class precedence list okay';
248 [ 'Baz', 'Bar', 'Foo'],
249 '... we just have ourselves in the class precedence list');
253 @attributes = $meta->compute_all_applicable_attributes;
254 } '... got the attribute list okay';
256 [ sort { $a->name cmp $b->name } @attributes ],
257 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
258 '... got the right list of attributes');