4 use Test::More tests => 86;
16 __PACKAGE__->meta->add_attribute('bar');
24 __PACKAGE__->meta->superclasses('Foo');
26 __PACKAGE__->meta->add_attribute('baz');
34 __PACKAGE__->meta->superclasses('Bar');
36 __PACKAGE__->meta->add_attribute('bah');
43 lives_ok{ $transformer = $meta->create_immutable_transformer }
44 "Created immutable transformer";
45 isa_ok($transformer, 'Class::MOP::Immutable', '... transformer isa Class::MOP::Immutable');
46 my $methods = $transformer->create_methods_for_immutable_metaclass;
48 my $immutable_metaclass = $transformer->immutable_metaclass;
49 is($transformer->metaclass, $meta, '... transformer has correct metaclass');
50 ok(!$transformer->inlined_constructor, '... transformer says it did not inline the constructor');
51 ok($immutable_metaclass->is_anon_class, '... immutable_metaclass is an anonymous class');
53 #I don't understand why i need to ->meta here...
54 my $obj = $immutable_metaclass->name;
55 ok(!$obj->is_mutable, '... immutable_metaclass is not mutable');
56 ok($obj->is_immutable, '... immutable_metaclass is immutable');
57 ok(!$obj->make_immutable, '... immutable_metaclass make_mutable is noop');
58 is($obj->meta, $immutable_metaclass, '... immutable_metaclass meta hack works');
61 [ $immutable_metaclass->superclasses ],
62 [ Scalar::Util::blessed($meta) ],
63 '... immutable_metaclass superclasses are correct'
65 ok($immutable_metaclass->has_method('get_mutable_metaclass_name'),
66 'immutable metaclass has get_mutable_metaclass_name method');
72 is($meta->name, 'Foo', '... checking the Foo metaclass');
74 ok($meta->is_mutable, '... our class is mutable');
75 ok(!$meta->is_immutable, '... our class is not immutable');
77 my $transformer = $meta->get_immutable_transformer;
80 $meta->make_immutable();
81 } '... changed Foo to be immutable';
83 ok($transformer->inlined_constructor, '... transformer says it did inline the constructor');
84 is($transformer, $meta->get_immutable_transformer, '... immutable transformer cache works');
85 ok(!$meta->make_immutable, '... make immutable now returns nothing');
87 ok(!$meta->is_mutable, '... our class is no longer mutable');
88 ok($meta->is_immutable, '... our class is now immutable');
90 isa_ok($meta, 'Class::MOP::Class');
92 dies_ok { $meta->add_method() } '... exception thrown as expected';
93 dies_ok { $meta->alias_method() } '... exception thrown as expected';
94 dies_ok { $meta->remove_method() } '... exception thrown as expected';
96 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
97 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
99 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
100 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
102 lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case';
106 @supers = $meta->superclasses;
107 } '... got the superclasses okay';
109 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
113 $meta_instance = $meta->get_meta_instance;
114 } '... got the meta instance okay';
115 isa_ok($meta_instance, 'Class::MOP::Instance');
116 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
120 @cpl = $meta->class_precedence_list;
121 } '... got the class precedence list okay';
125 '... we just have ourselves in the class precedence list');
129 @attributes = $meta->compute_all_applicable_attributes;
130 } '... got the attribute list okay';
133 [ $meta->get_attribute('bar') ],
134 '... got the right list of attributes');
138 my $meta = Bar->meta;
139 is($meta->name, 'Bar', '... checking the Bar metaclass');
141 ok($meta->is_mutable, '... our class is mutable');
142 ok(!$meta->is_immutable, '... our class is not immutable');
145 $meta->make_immutable();
146 } '... changed Bar to be immutable';
148 ok(!$meta->make_immutable, '... make immutable now returns nothing');
150 ok(!$meta->is_mutable, '... our class is no longer mutable');
151 ok($meta->is_immutable, '... our class is now immutable');
153 isa_ok($meta, 'Class::MOP::Class');
155 dies_ok { $meta->add_method() } '... exception thrown as expected';
156 dies_ok { $meta->alias_method() } '... exception thrown as expected';
157 dies_ok { $meta->remove_method() } '... exception thrown as expected';
159 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
160 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
162 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
163 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
167 @supers = $meta->superclasses;
168 } '... got the superclasses okay';
170 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
174 $meta_instance = $meta->get_meta_instance;
175 } '... got the meta instance okay';
176 isa_ok($meta_instance, 'Class::MOP::Instance');
177 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
181 @cpl = $meta->class_precedence_list;
182 } '... got the class precedence list okay';
186 '... we just have ourselves in the class precedence list');
190 @attributes = $meta->compute_all_applicable_attributes;
191 } '... got the attribute list okay';
193 [ sort { $a->name cmp $b->name } @attributes ],
194 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
195 '... got the right list of attributes');
199 my $meta = Baz->meta;
200 is($meta->name, 'Baz', '... checking the Baz metaclass');
202 ok($meta->is_mutable, '... our class is mutable');
203 ok(!$meta->is_immutable, '... our class is not immutable');
206 $meta->make_immutable();
207 } '... changed Baz to be immutable';
209 ok(!$meta->make_immutable, '... make immutable now returns nothing');
211 ok(!$meta->is_mutable, '... our class is no longer mutable');
212 ok($meta->is_immutable, '... our class is now immutable');
214 isa_ok($meta, 'Class::MOP::Class');
216 dies_ok { $meta->add_method() } '... exception thrown as expected';
217 dies_ok { $meta->alias_method() } '... exception thrown as expected';
218 dies_ok { $meta->remove_method() } '... exception thrown as expected';
220 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
221 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
223 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
224 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
228 @supers = $meta->superclasses;
229 } '... got the superclasses okay';
231 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
235 $meta_instance = $meta->get_meta_instance;
236 } '... got the meta instance okay';
237 isa_ok($meta_instance, 'Class::MOP::Instance');
238 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
242 @cpl = $meta->class_precedence_list;
243 } '... got the class precedence list okay';
246 [ 'Baz', 'Bar', 'Foo'],
247 '... we just have ourselves in the class precedence list');
251 @attributes = $meta->compute_all_applicable_attributes;
252 } '... got the attribute list okay';
254 [ sort { $a->name cmp $b->name } @attributes ],
255 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
256 '... got the right list of attributes');