6 use Test::More tests => 83;
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';
102 @supers = $meta->superclasses;
103 } '... got the superclasses okay';
105 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
109 $meta_instance = $meta->get_meta_instance;
110 } '... got the meta instance okay';
111 isa_ok($meta_instance, 'Class::MOP::Instance');
112 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
116 @cpl = $meta->class_precedence_list;
117 } '... got the class precedence list okay';
121 '... we just have ourselves in the class precedence list');
125 @attributes = $meta->compute_all_applicable_attributes;
126 } '... got the attribute list okay';
129 [ $meta->get_attribute('bar') ],
130 '... got the right list of attributes');
134 my $meta = Bar->meta;
135 is($meta->name, 'Bar', '... checking the Bar metaclass');
137 ok($meta->is_mutable, '... our class is mutable');
138 ok(!$meta->is_immutable, '... our class is not immutable');
141 $meta->make_immutable();
142 } '... changed Bar to be immutable';
144 ok(!$meta->make_immutable, '... make immutable now returns nothing');
146 ok(!$meta->is_mutable, '... our class is no longer mutable');
147 ok($meta->is_immutable, '... our class is now immutable');
149 isa_ok($meta, 'Class::MOP::Class');
151 dies_ok { $meta->add_method() } '... exception thrown as expected';
152 dies_ok { $meta->alias_method() } '... exception thrown as expected';
153 dies_ok { $meta->remove_method() } '... exception thrown as expected';
155 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
156 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
158 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
159 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
163 @supers = $meta->superclasses;
164 } '... got the superclasses okay';
166 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
170 $meta_instance = $meta->get_meta_instance;
171 } '... got the meta instance okay';
172 isa_ok($meta_instance, 'Class::MOP::Instance');
173 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
177 @cpl = $meta->class_precedence_list;
178 } '... got the class precedence list okay';
182 '... we just have ourselves in the class precedence list');
186 @attributes = $meta->compute_all_applicable_attributes;
187 } '... got the attribute list okay';
189 [ sort { $a->name cmp $b->name } @attributes ],
190 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
191 '... got the right list of attributes');
195 my $meta = Baz->meta;
196 is($meta->name, 'Baz', '... checking the Baz metaclass');
198 ok($meta->is_mutable, '... our class is mutable');
199 ok(!$meta->is_immutable, '... our class is not immutable');
202 $meta->make_immutable();
203 } '... changed Baz to be immutable';
205 ok(!$meta->make_immutable, '... make immutable now returns nothing');
207 ok(!$meta->is_mutable, '... our class is no longer mutable');
208 ok($meta->is_immutable, '... our class is now immutable');
210 isa_ok($meta, 'Class::MOP::Class');
212 dies_ok { $meta->add_method() } '... exception thrown as expected';
213 dies_ok { $meta->alias_method() } '... exception thrown as expected';
214 dies_ok { $meta->remove_method() } '... exception thrown as expected';
216 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
217 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
219 dies_ok { $meta->add_package_symbol() } '... exception thrown as expected';
220 dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected';
224 @supers = $meta->superclasses;
225 } '... got the superclasses okay';
227 dies_ok { $meta->superclasses([ 'UNIVERSAL' ]) } '... but could not set the superclasses okay';
231 $meta_instance = $meta->get_meta_instance;
232 } '... got the meta instance okay';
233 isa_ok($meta_instance, 'Class::MOP::Instance');
234 is($meta_instance, $meta->get_meta_instance, '... and we know it is cached');
238 @cpl = $meta->class_precedence_list;
239 } '... got the class precedence list okay';
242 [ 'Baz', 'Bar', 'Foo'],
243 '... we just have ourselves in the class precedence list');
247 @attributes = $meta->compute_all_applicable_attributes;
248 } '... got the attribute list okay';
250 [ sort { $a->name cmp $b->name } @attributes ],
251 [ $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'), Bar->meta->get_attribute('baz') ],
252 '... got the right list of attributes');