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 ],
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';
99 lives_ok{ $meta->identifier() } '... no exception for get_package_symbol special case';
103 @supers = $meta->superclasses;
104 } '... got the superclasses okay';
106 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
110 $meta_instance = $meta->get_meta_instance;
111 } '... got the meta instance okay';
112 isa_ok($meta_instance, 'Class::MOP::Instance');
113 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
117 @cpl = $meta->class_precedence_list;
118 } '... got the class precedence list okay';
122 '... we just have ourselves in the class precedence list');
126 @attributes = $meta->compute_all_applicable_attributes;
127 } '... got the attribute list okay';
130 [ $meta->get_attribute('bar') ],
131 '... got the right list of attributes');
135 my $meta = Bar->meta;
136 is($meta->name, 'Bar', '... checking the Bar metaclass');
138 ok($meta->is_mutable, '... our class is mutable');
139 ok(!$meta->is_immutable, '... our class is not immutable');
142 $meta->make_immutable();
143 } '... changed Bar to be immutable';
145 ok(!$meta->make_immutable, '... make immutable now returns nothing');
147 ok(!$meta->is_mutable, '... our class is no longer mutable');
148 ok($meta->is_immutable, '... our class is now immutable');
150 isa_ok($meta, 'Class::MOP::Class');
152 dies_ok { $meta->add_method() } '... exception thrown as expected';
153 dies_ok { $meta->alias_method() } '... exception thrown as expected';
154 dies_ok { $meta->remove_method() } '... exception thrown as expected';
156 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
157 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
159 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
160 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
164 @supers = $meta->superclasses;
165 } '... got the superclasses okay';
167 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
171 $meta_instance = $meta->get_meta_instance;
172 } '... got the meta instance okay';
173 isa_ok($meta_instance, 'Class::MOP::Instance');
174 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
178 @cpl = $meta->class_precedence_list;
179 } '... got the class precedence list okay';
183 '... we just have ourselves in the class precedence list');
187 @attributes = $meta->compute_all_applicable_attributes;
188 } '... got the attribute list okay';
190 [ sort { $a->name cmp $b->name } @attributes ],
191 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
192 '... got the right list of attributes');
196 my $meta = Baz->meta;
197 is($meta->name, 'Baz', '... checking the Baz metaclass');
199 ok($meta->is_mutable, '... our class is mutable');
200 ok(!$meta->is_immutable, '... our class is not immutable');
203 $meta->make_immutable();
204 } '... changed Baz to be immutable';
206 ok(!$meta->make_immutable, '... make immutable now returns nothing');
208 ok(!$meta->is_mutable, '... our class is no longer mutable');
209 ok($meta->is_immutable, '... our class is now immutable');
211 isa_ok($meta, 'Class::MOP::Class');
213 dies_ok { $meta->add_method() } '... exception thrown as expected';
214 dies_ok { $meta->alias_method() } '... exception thrown as expected';
215 dies_ok { $meta->remove_method() } '... exception thrown as expected';
217 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
218 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
220 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
221 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
225 @supers = $meta->superclasses;
226 } '... got the superclasses okay';
228 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
232 $meta_instance = $meta->get_meta_instance;
233 } '... got the meta instance okay';
234 isa_ok($meta_instance, 'Class::MOP::Instance');
235 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
239 @cpl = $meta->class_precedence_list;
240 } '... got the class precedence list okay';
243 [ 'Baz', 'Bar', 'Foo'],
244 '... we just have ourselves in the class precedence list');
248 @attributes = $meta->compute_all_applicable_attributes;
249 } '... got the attribute list okay';
251 [ sort { $a->name cmp $b->name } @attributes ],
252 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
253 '... got the right list of attributes');