4 use Test::More tests => 86;
17 __PACKAGE__->meta->add_attribute('bar');
25 __PACKAGE__->meta->superclasses('Foo');
27 __PACKAGE__->meta->add_attribute('baz');
35 __PACKAGE__->meta->superclasses('Bar');
37 __PACKAGE__->meta->add_attribute('bah');
44 lives_ok { $transformer = $meta->create_immutable_transformer }
45 "Created immutable transformer";
46 isa_ok( $transformer, 'Class::MOP::Immutable',
47 '... 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,
52 '... transformer has correct metaclass' );
53 ok( !$transformer->inlined_constructor,
54 '... transformer says it did not inline the constructor' );
55 ok( $immutable_metaclass->is_anon_class,
56 '... immutable_metaclass is an anonymous class' );
58 #I don't understand why i need to ->meta here...
59 my $obj = $immutable_metaclass->name;
60 ok( !$obj->is_mutable, '... immutable_metaclass is not mutable' );
61 ok( $obj->is_immutable, '... immutable_metaclass is immutable' );
62 ok( !$obj->make_immutable,
63 '... immutable_metaclass make_mutable is noop' );
64 is( $obj->meta, $immutable_metaclass,
65 '... immutable_metaclass meta hack works' );
68 [ $immutable_metaclass->superclasses ],
69 [ Scalar::Util::blessed($meta) ],
70 '... immutable_metaclass superclasses are correct'
73 $immutable_metaclass->has_method('get_mutable_metaclass_name'),
74 'immutable metaclass has get_mutable_metaclass_name method'
81 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
83 ok( $meta->is_mutable, '... our class is mutable' );
84 ok( !$meta->is_immutable, '... our class is not immutable' );
86 my $transformer = $meta->get_immutable_transformer;
89 $meta->make_immutable();
91 '... changed Foo to be immutable';
93 ok( $transformer->inlined_constructor,
94 '... transformer says it did inline the constructor' );
95 is( $transformer, $meta->get_immutable_transformer,
96 '... immutable transformer cache works' );
97 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
99 ok( !$meta->is_mutable, '... our class is no longer mutable' );
100 ok( $meta->is_immutable, '... our class is now immutable' );
102 isa_ok( $meta, 'Class::MOP::Class' );
104 dies_ok { $meta->add_method() } '... exception thrown as expected';
105 dies_ok { $meta->alias_method() } '... exception thrown as expected';
106 dies_ok { $meta->remove_method() } '... exception thrown as expected';
108 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
109 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
111 dies_ok { $meta->add_package_symbol() }
112 '... exception thrown as expected';
113 dies_ok { $meta->remove_package_symbol() }
114 '... exception thrown as expected';
116 lives_ok { $meta->identifier() }
117 '... no exception for get_package_symbol special case';
121 @supers = $meta->superclasses;
123 '... got the superclasses okay';
125 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
126 '... but could not set the superclasses okay';
130 $meta_instance = $meta->get_meta_instance;
132 '... got the meta instance okay';
133 isa_ok( $meta_instance, 'Class::MOP::Instance' );
134 is( $meta_instance, $meta->get_meta_instance,
135 '... and we know it is cached' );
139 @cpl = $meta->class_precedence_list;
141 '... got the class precedence list okay';
145 '... we just have ourselves in the class precedence list'
150 @attributes = $meta->compute_all_applicable_attributes;
152 '... got the attribute list okay';
155 [ $meta->get_attribute('bar') ],
156 '... got the right list of attributes'
161 my $meta = Bar->meta;
162 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
164 ok( $meta->is_mutable, '... our class is mutable' );
165 ok( !$meta->is_immutable, '... our class is not immutable' );
168 $meta->make_immutable();
170 '... changed Bar to be immutable';
172 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
174 ok( !$meta->is_mutable, '... our class is no longer mutable' );
175 ok( $meta->is_immutable, '... our class is now immutable' );
177 isa_ok( $meta, 'Class::MOP::Class' );
179 dies_ok { $meta->add_method() } '... exception thrown as expected';
180 dies_ok { $meta->alias_method() } '... exception thrown as expected';
181 dies_ok { $meta->remove_method() } '... exception thrown as expected';
183 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
184 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
186 dies_ok { $meta->add_package_symbol() }
187 '... exception thrown as expected';
188 dies_ok { $meta->remove_package_symbol() }
189 '... exception thrown as expected';
193 @supers = $meta->superclasses;
195 '... got the superclasses okay';
197 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
198 '... but could not set the superclasses okay';
202 $meta_instance = $meta->get_meta_instance;
204 '... got the meta instance okay';
205 isa_ok( $meta_instance, 'Class::MOP::Instance' );
206 is( $meta_instance, $meta->get_meta_instance,
207 '... and we know it is cached' );
211 @cpl = $meta->class_precedence_list;
213 '... got the class precedence list okay';
217 '... we just have ourselves in the class precedence list'
222 @attributes = $meta->compute_all_applicable_attributes;
224 '... got the attribute list okay';
226 [ sort { $a->name cmp $b->name } @attributes ],
227 [ Foo->meta->get_attribute('bar'), $meta->get_attribute('baz') ],
228 '... got the right list of attributes'
233 my $meta = Baz->meta;
234 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
236 ok( $meta->is_mutable, '... our class is mutable' );
237 ok( !$meta->is_immutable, '... our class is not immutable' );
240 $meta->make_immutable();
242 '... changed Baz to be immutable';
244 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
246 ok( !$meta->is_mutable, '... our class is no longer mutable' );
247 ok( $meta->is_immutable, '... our class is now immutable' );
249 isa_ok( $meta, 'Class::MOP::Class' );
251 dies_ok { $meta->add_method() } '... exception thrown as expected';
252 dies_ok { $meta->alias_method() } '... exception thrown as expected';
253 dies_ok { $meta->remove_method() } '... exception thrown as expected';
255 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
256 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
258 dies_ok { $meta->add_package_symbol() }
259 '... exception thrown as expected';
260 dies_ok { $meta->remove_package_symbol() }
261 '... exception thrown as expected';
265 @supers = $meta->superclasses;
267 '... got the superclasses okay';
269 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
270 '... but could not set the superclasses okay';
274 $meta_instance = $meta->get_meta_instance;
276 '... got the meta instance okay';
277 isa_ok( $meta_instance, 'Class::MOP::Instance' );
278 is( $meta_instance, $meta->get_meta_instance,
279 '... and we know it is cached' );
283 @cpl = $meta->class_precedence_list;
285 '... got the class precedence list okay';
288 [ 'Baz', 'Bar', 'Foo' ],
289 '... we just have ourselves in the class precedence list'
294 @attributes = $meta->compute_all_applicable_attributes;
296 '... got the attribute list okay';
298 [ sort { $a->name cmp $b->name } @attributes ],
300 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
301 Bar->meta->get_attribute('baz')
303 '... got the right list of attributes'