6 use Test::More tests => 84;
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($immutable_metaclass->is_anon_class, '... immutable_metaclass is an anonymous class');
54 #I don't understand why i need to ->meta here...
55 my $obj = $immutable_metaclass->name;
56 ok(!$obj->is_mutable, '... immutable_metaclass is not mutable');
57 ok($obj->is_immutable, '... immutable_metaclass is immutable');
58 ok(!$obj->make_immutable, '... immutable_metaclass make_mutable is noop');
59 is($obj->meta, $immutable_metaclass, '... immutable_metaclass meta hack works');
62 [ $immutable_metaclass->superclasses ],
63 [ Scalar::Util::blessed($meta) ],
64 '... immutable_metaclass superclasses are correct'
66 ok($immutable_metaclass->has_method('get_mutable_metaclass_name'));
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 is($transformer, $meta->get_immutable_transformer, '... immutable transformer cache works');
84 ok(!$meta->make_immutable, '... make immutable now returns nothing');
86 ok(!$meta->is_mutable, '... our class is no longer mutable');
87 ok($meta->is_immutable, '... our class is now immutable');
89 isa_ok($meta, 'Class::MOP::Class');
91 dies_ok { $meta->add_method() } '... exception thrown as expected';
92 dies_ok { $meta->alias_method() } '... exception thrown as expected';
93 dies_ok { $meta->remove_method() } '... exception thrown as expected';
95 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
96 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
98 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
99 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
101 lives_ok { $meta->identifier() } '... no exception for get_package_symbol special case';
105 @supers = $meta->superclasses;
106 } '... got the superclasses okay';
108 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
112 $meta_instance = $meta->get_meta_instance;
113 } '... got the meta instance okay';
114 isa_ok($meta_instance, 'Class::MOP::Instance');
115 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
119 @cpl = $meta->class_precedence_list;
120 } '... got the class precedence list okay';
124 '... we just have ourselves in the class precedence list');
128 @attributes = $meta->compute_all_applicable_attributes;
129 } '... got the attribute list okay';
132 [ $meta->get_attribute('bar') ],
133 '... got the right list of attributes');
137 my $meta = Bar->meta;
138 is($meta->name, 'Bar', '... checking the Bar metaclass');
140 ok($meta->is_mutable, '... our class is mutable');
141 ok(!$meta->is_immutable, '... our class is not immutable');
144 $meta->make_immutable();
145 } '... changed Bar to be immutable';
147 ok(!$meta->make_immutable, '... make immutable now returns nothing');
149 ok(!$meta->is_mutable, '... our class is no longer mutable');
150 ok($meta->is_immutable, '... our class is now immutable');
152 isa_ok($meta, 'Class::MOP::Class');
154 dies_ok { $meta->add_method() } '... exception thrown as expected';
155 dies_ok { $meta->alias_method() } '... exception thrown as expected';
156 dies_ok { $meta->remove_method() } '... exception thrown as expected';
158 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
159 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
161 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
162 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
166 @supers = $meta->superclasses;
167 } '... got the superclasses okay';
169 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
173 $meta_instance = $meta->get_meta_instance;
174 } '... got the meta instance okay';
175 isa_ok($meta_instance, 'Class::MOP::Instance');
176 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
180 @cpl = $meta->class_precedence_list;
181 } '... got the class precedence list okay';
185 '... we just have ourselves in the class precedence list');
189 @attributes = $meta->compute_all_applicable_attributes;
190 } '... got the attribute list okay';
192 [ sort { $a->name cmp $b->name } @attributes ],
193 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
194 '... got the right list of attributes');
198 my $meta = Baz->meta;
199 is($meta->name, 'Baz', '... checking the Baz metaclass');
201 ok($meta->is_mutable, '... our class is mutable');
202 ok(!$meta->is_immutable, '... our class is not immutable');
205 $meta->make_immutable();
206 } '... changed Baz to be immutable';
208 ok(!$meta->make_immutable, '... make immutable now returns nothing');
210 ok(!$meta->is_mutable, '... our class is no longer mutable');
211 ok($meta->is_immutable, '... our class is now immutable');
213 isa_ok($meta, 'Class::MOP::Class');
215 dies_ok { $meta->add_method() } '... exception thrown as expected';
216 dies_ok { $meta->alias_method() } '... exception thrown as expected';
217 dies_ok { $meta->remove_method() } '... exception thrown as expected';
219 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
220 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
222 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
223 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
227 @supers = $meta->superclasses;
228 } '... got the superclasses okay';
230 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
234 $meta_instance = $meta->get_meta_instance;
235 } '... got the meta instance okay';
236 isa_ok($meta_instance, 'Class::MOP::Instance');
237 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
241 @cpl = $meta->class_precedence_list;
242 } '... got the class precedence list okay';
245 [ 'Baz', 'Bar', 'Foo'],
246 '... we just have ourselves in the class precedence list');
250 @attributes = $meta->compute_all_applicable_attributes;
251 } '... got the attribute list okay';
253 [ sort { $a->name cmp $b->name } @attributes ],
254 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
255 '... got the right list of attributes');