4 use Test::More tests => 75;
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');
41 my $original_metaclass_name = ref $meta;
43 $meta->make_immutable;
45 my $immutable_metaclass = $meta->immutable_metaclass->meta;
47 #I don't understand why i need to ->meta here...
48 my $obj = $immutable_metaclass->name;
50 ok( !$obj->is_mutable, '... immutable_metaclass is not mutable' );
51 ok( $obj->is_immutable, '... immutable_metaclass is immutable' );
52 ok( !$obj->make_immutable,
53 '... immutable_metaclass make_mutable is noop' );
54 is( $obj->meta, $immutable_metaclass,
55 '... immutable_metaclass meta hack works' );
57 isa_ok( $meta, "Class::MOP::Class::Immutable::Trait" );
58 isa_ok( $meta, "Class::MOP::Class" );
64 is( $meta->name, 'Foo', '... checking the Foo metaclass' );
66 ok( !$meta->is_mutable, '... our class is not mutable' );
67 ok( $meta->is_immutable, '... our class is immutable' );
69 isa_ok( $meta, 'Class::MOP::Class' );
71 dies_ok { $meta->add_method() } '... exception thrown as expected';
72 dies_ok { $meta->alias_method() } '... exception thrown as expected';
73 dies_ok { $meta->remove_method() } '... exception thrown as expected';
75 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
76 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
78 dies_ok { $meta->add_package_symbol() }
79 '... exception thrown as expected';
80 dies_ok { $meta->remove_package_symbol() }
81 '... exception thrown as expected';
83 lives_ok { $meta->identifier() }
84 '... no exception for get_package_symbol special case';
88 @supers = $meta->superclasses;
90 '... got the superclasses okay';
92 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
93 '... but could not set the superclasses okay';
97 $meta_instance = $meta->get_meta_instance;
99 '... got the meta instance okay';
100 isa_ok( $meta_instance, 'Class::MOP::Instance' );
101 is( $meta_instance, $meta->get_meta_instance,
102 '... and we know it is cached' );
106 @cpl = $meta->class_precedence_list;
108 '... got the class precedence list okay';
112 '... we just have ourselves in the class precedence list'
117 @attributes = $meta->get_all_attributes;
119 '... got the attribute list okay';
122 [ $meta->get_attribute('bar') ],
123 '... got the right list of attributes'
128 my $meta = Bar->meta;
129 is( $meta->name, 'Bar', '... checking the Bar metaclass' );
131 ok( $meta->is_mutable, '... our class is mutable' );
132 ok( !$meta->is_immutable, '... our class is not immutable' );
135 $meta->make_immutable();
137 '... changed Bar to be immutable';
139 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
141 ok( !$meta->is_mutable, '... our class is no longer mutable' );
142 ok( $meta->is_immutable, '... our class is now immutable' );
144 isa_ok( $meta, 'Class::MOP::Class' );
146 dies_ok { $meta->add_method() } '... exception thrown as expected';
147 dies_ok { $meta->alias_method() } '... exception thrown as expected';
148 dies_ok { $meta->remove_method() } '... exception thrown as expected';
150 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
151 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
153 dies_ok { $meta->add_package_symbol() }
154 '... exception thrown as expected';
155 dies_ok { $meta->remove_package_symbol() }
156 '... exception thrown as expected';
160 @supers = $meta->superclasses;
162 '... got the superclasses okay';
164 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
165 '... but could not set the superclasses okay';
169 $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,
174 '... and we know it is cached' );
178 @cpl = $meta->class_precedence_list;
180 '... got the class precedence list okay';
184 '... we just have ourselves in the class precedence list'
189 @attributes = $meta->get_all_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'
200 my $meta = Baz->meta;
201 is( $meta->name, 'Baz', '... checking the Baz metaclass' );
203 ok( $meta->is_mutable, '... our class is mutable' );
204 ok( !$meta->is_immutable, '... our class is not immutable' );
207 $meta->make_immutable();
209 '... changed Baz to be immutable';
211 ok( !$meta->make_immutable, '... make immutable now returns nothing' );
213 ok( !$meta->is_mutable, '... our class is no longer mutable' );
214 ok( $meta->is_immutable, '... our class is now immutable' );
216 isa_ok( $meta, 'Class::MOP::Class' );
218 dies_ok { $meta->add_method() } '... exception thrown as expected';
219 dies_ok { $meta->alias_method() } '... exception thrown as expected';
220 dies_ok { $meta->remove_method() } '... exception thrown as expected';
222 dies_ok { $meta->add_attribute() } '... exception thrown as expected';
223 dies_ok { $meta->remove_attribute() } '... exception thrown as expected';
225 dies_ok { $meta->add_package_symbol() }
226 '... exception thrown as expected';
227 dies_ok { $meta->remove_package_symbol() }
228 '... exception thrown as expected';
232 @supers = $meta->superclasses;
234 '... got the superclasses okay';
236 dies_ok { $meta->superclasses( ['UNIVERSAL'] ) }
237 '... but could not set the superclasses okay';
241 $meta_instance = $meta->get_meta_instance;
243 '... got the meta instance okay';
244 isa_ok( $meta_instance, 'Class::MOP::Instance' );
245 is( $meta_instance, $meta->get_meta_instance,
246 '... and we know it is cached' );
250 @cpl = $meta->class_precedence_list;
252 '... got the class precedence list okay';
255 [ 'Baz', 'Bar', 'Foo' ],
256 '... we just have ourselves in the class precedence list'
261 @attributes = $meta->get_all_attributes;
263 '... got the attribute list okay';
265 [ sort { $a->name cmp $b->name } @attributes ],
267 $meta->get_attribute('bah'), Foo->meta->get_attribute('bar'),
268 Bar->meta->get_attribute('baz')
270 '... got the right list of attributes'