6 use Test::More tests => 101;
22 __PACKAGE__->meta->add_attribute('bar');
30 __PACKAGE__->meta->superclasses('Foo');
32 __PACKAGE__->meta->add_attribute('baz');
40 __PACKAGE__->meta->superclasses('Bar');
42 __PACKAGE__->meta->add_attribute('bah');
47 is($meta->name, 'Baz', '... checking the Baz metaclass');
48 my @orig_keys = sort keys %$meta;
50 lives_ok {$meta->make_immutable() } '... changed Baz to be immutable';
51 ok(!$meta->is_mutable, '... our class is no longer mutable');
52 ok($meta->is_immutable, '... our class is now immutable');
53 ok(!$meta->make_immutable, '... make immutable now returns nothing');
55 lives_ok { $meta->make_mutable() } '... changed Baz to be mutable';
56 ok($meta->is_mutable, '... our class is mutable');
57 ok(!$meta->is_immutable, '... our class is not immutable');
58 ok(!$meta->make_mutable, '... make mutable now returns nothing');
60 my @new_keys = sort keys %$meta;
61 is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys');
63 isa_ok($meta, 'Class::MOP::Class', '... Baz->meta isa Class::MOP::Class');
65 ok( $meta->add_method('xyz', sub{'xxx'}), '... added method');
66 is( Baz->xyz, 'xxx', '... method xyz works');
67 ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
68 is( Baz->zxy, 'xxx', '... method zxy works');
69 ok( $meta->remove_method('xyz'), '... removed method');
70 ok( $meta->remove_method('zxy'), '... removed aliased method');
72 ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
73 ok(Baz->can('fickle'), '... Baz can fickle');
74 ok($meta->remove_attribute('fickle'), '... removed attribute');
77 ok($meta->add_package_symbol('$ref', $reef), '... added package symbol');
78 is($meta->get_package_symbol('$ref'), $reef, '... values match');
79 lives_ok { $meta->remove_package_symbol('$ref') } '... removed it';
80 isnt($meta->get_package_symbol('$ref'), $reef, '... values match');
82 ok( my @supers = $meta->superclasses, '... got the superclasses okay');
83 ok( $meta->superclasses('Foo'), '... set the superclasses');
84 is_deeply(['Foo'], [$meta->superclasses], '... set the superclasses okay');
85 ok( $meta->superclasses( @supers ), '... reset superclasses');
86 is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay');
88 ok( $meta->$_ , "... ${_} works")
89 for qw(get_meta_instance compute_all_applicable_attributes
90 class_precedence_list get_method_map );
96 lives_ok { $meta->make_immutable() } 'Changed Baz to be immutable';
97 lives_ok { $meta->make_mutable() } '... changed Baz to be mutable';
98 lives_ok { $meta->make_immutable() } '... changed Baz to be immutable';
100 dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected';
101 dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected';
102 dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected';
105 $meta->add_attribute('fickle', accessor => 'fickle')
106 } '... exception thrown as expected';
107 dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected';
110 dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected';
111 dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected';
113 ok( my @supers = $meta->superclasses, '... got the superclasses okay');
114 dies_ok { $meta->superclasses('Foo') } '... set the superclasses';
116 ok( $meta->$_ , "... ${_} works")
117 for qw(get_meta_instance compute_all_applicable_attributes
118 class_precedence_list get_method_map );
125 my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']);
126 my @orig_keys = sort keys %$meta;
127 my @orig_meths = sort $meta->compute_all_applicable_methods;
128 ok($meta->is_anon_class, 'We have an anon metaclass');
129 lives_ok {$meta->make_immutable(
130 inline_accessor => 1,
131 inline_destructor => 0,
132 inline_constructor => 1,
134 } '... changed class to be immutable';
135 ok(!$meta->is_mutable, '... our class is no longer mutable');
136 ok($meta->is_immutable, '... our class is now immutable');
137 ok(!$meta->make_immutable, '... make immutable now returns nothing');
139 lives_ok { $meta->make_mutable } '... changed Baz to be mutable';
140 ok($meta->is_mutable, '... our class is mutable');
141 ok(!$meta->is_immutable, '... our class is not immutable');
142 ok(!$meta->make_mutable, '... make mutable now returns nothing');
143 ok($meta->is_anon_class, '... still marked as an anon class');
144 my $instance = $meta->new_object;
146 my @new_keys = sort keys %$meta;
147 my @new_meths = sort $meta->compute_all_applicable_methods;
148 is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys');
149 is_deeply(\@orig_meths, \@new_meths, '... no straneous methods');
151 isa_ok($meta, 'Class::MOP::Class', '... Anon class isa Class::MOP::Class');
153 ok( $meta->add_method('xyz', sub{'xxx'}), '... added method');
154 is( $instance->xyz , 'xxx', '... method xyz works');
155 ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
156 is( $instance->zxy, 'xxx', '... method zxy works');
157 ok( $meta->remove_method('xyz'), '... removed method');
158 ok( $meta->remove_method('zxy'), '... removed aliased method');
160 ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
161 ok($instance->can('fickle'), '... instance can fickle');
162 ok($meta->remove_attribute('fickle'), '... removed attribute');
165 ok($meta->add_package_symbol('$ref', $reef), '... added package symbol');
166 is($meta->get_package_symbol('$ref'), $reef, '... values match');
167 lives_ok { $meta->remove_package_symbol('$ref') } '... removed it';
168 isnt($meta->get_package_symbol('$ref'), $reef, '... values match');
170 ok( my @supers = $meta->superclasses, '... got the superclasses okay');
171 ok( $meta->superclasses('Foo'), '... set the superclasses');
172 is_deeply(['Foo'], [$meta->superclasses], '... set the superclasses okay');
173 ok( $meta->superclasses( @supers ), '... reset superclasses');
174 is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay');
176 ok( $meta->$_ , "... ${_} works")
177 for qw(get_meta_instance compute_all_applicable_attributes
178 class_precedence_list get_method_map );
182 #rerun the same tests on an anon class.. just cause we can.
184 my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']);
186 lives_ok {$meta->make_immutable(
187 inline_accessor => 1,
188 inline_destructor => 0,
189 inline_constructor => 1,
191 } '... changed class to be immutable';
192 lives_ok { $meta->make_mutable() } '... changed class to be mutable';
193 lives_ok {$meta->make_immutable } '... changed class to be immutable';
195 dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected';
196 dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected';
197 dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected';
200 $meta->add_attribute('fickle', accessor => 'fickle')
201 } '... exception thrown as expected';
202 dies_ok { $meta->remove_attribute('fickle') } '... exception thrown as expected';
205 dies_ok { $meta->add_package_symbol('$ref', $reef) } '... exception thrown as expected';
206 dies_ok { $meta->remove_package_symbol('$ref') } '... exception thrown as expected';
208 ok( my @supers = $meta->superclasses, '... got the superclasses okay');
209 dies_ok { $meta->superclasses('Foo') } '... set the superclasses';
211 ok( $meta->$_ , "... ${_} works")
212 for qw(get_meta_instance compute_all_applicable_attributes
213 class_precedence_list get_method_map );