6 use Test::More tests => 76;
11 use_ok('Class::MOP::Class::Immutable');
21 __PACKAGE__->meta->add_attribute('bar' => (
32 __PACKAGE__->meta->superclasses('Foo');
34 __PACKAGE__->meta->add_attribute('baz' => (
36 default => sub { 'BAZ' },
45 __PACKAGE__->meta->superclasses('Bar');
47 __PACKAGE__->meta->add_attribute('bah' => (
55 is($meta->name, 'Foo', '... checking the Foo metaclass');
58 my $bar_accessor = $meta->get_method('bar');
59 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
60 isa_ok($bar_accessor, 'Class::MOP::Method');
62 ok(!$bar_accessor->is_inline, '... the bar accessor is not inlined');
65 ok(!$meta->is_immutable, '... our class is not immutable');
68 $meta->make_immutable(
69 inline_constructor => 1,
70 inline_accessors => 0,
72 } '... changed Foo to be immutable';
74 ok($meta->is_immutable, '... our class is now immutable');
75 isa_ok($meta, 'Class::MOP::Class::Immutable');
76 isa_ok($meta, 'Class::MOP::Class');
78 # they made a constructor for us :)
84 is($foo->bar, 'BAR', '... got the right default value');
88 my $foo = Foo->new(bar => 'BAZ');
90 is($foo->bar, 'BAZ', '... got the right parameter value');
93 # check out accessors too
95 my $bar_accessor = $meta->get_method('bar');
96 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
97 isa_ok($bar_accessor, 'Class::MOP::Method');
99 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
104 my $meta = Bar->meta;
105 is($meta->name, 'Bar', '... checking the Bar metaclass');
108 my $bar_accessor = $meta->find_method_by_name('bar');
109 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
110 isa_ok($bar_accessor, 'Class::MOP::Method');
112 ok(!$bar_accessor->is_inline, '... the bar accessor is not inlined');
114 my $baz_accessor = $meta->get_method('baz');
115 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
116 isa_ok($baz_accessor, 'Class::MOP::Method');
118 ok(!$baz_accessor->is_inline, '... the baz accessor is not inlined');
121 ok(!$meta->is_immutable, '... our class is not immutable');
124 $meta->make_immutable(
125 inline_constructor => 1,
126 inline_accessors => 1,
128 } '... changed Bar to be immutable';
130 ok($meta->is_immutable, '... our class is now immutable');
131 isa_ok($meta, 'Class::MOP::Class::Immutable');
132 isa_ok($meta, 'Class::MOP::Class');
134 # they made a constructor for us :)
135 can_ok('Bar', 'new');
140 is($bar->bar, 'BAR', '... got the right default value');
141 is($bar->baz, 'BAZ', '... got the right default value');
145 my $bar = Bar->new(bar => 'BAZ!', baz => 'BAR!');
147 is($bar->bar, 'BAZ!', '... got the right parameter value');
148 is($bar->baz, 'BAR!', '... got the right parameter value');
151 # check out accessors too
153 my $bar_accessor = $meta->find_method_by_name('bar');
154 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
155 isa_ok($bar_accessor, 'Class::MOP::Method');
157 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
159 my $baz_accessor = $meta->get_method('baz');
160 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
161 isa_ok($baz_accessor, 'Class::MOP::Method');
163 ok($baz_accessor->is_inline, '... the baz accessor is not inlined');
168 my $meta = Baz->meta;
169 is($meta->name, 'Baz', '... checking the Bar metaclass');
172 my $bar_accessor = $meta->find_method_by_name('bar');
173 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
174 isa_ok($bar_accessor, 'Class::MOP::Method');
176 ok(!$bar_accessor->is_inline, '... the bar accessor is not inlined');
178 my $baz_accessor = $meta->find_method_by_name('baz');
179 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
180 isa_ok($baz_accessor, 'Class::MOP::Method');
182 ok($baz_accessor->is_inline, '... the baz accessor is inlined');
184 my $bah_accessor = $meta->get_method('bah');
185 isa_ok($bah_accessor, 'Class::MOP::Method::Accessor');
186 isa_ok($bah_accessor, 'Class::MOP::Method');
188 ok(!$bah_accessor->is_inline, '... the baz accessor is not inlined');
191 ok(!$meta->is_immutable, '... our class is not immutable');
194 $meta->make_immutable(
195 inline_constructor => 0,
196 inline_accessors => 1,
198 } '... changed Bar to be immutable';
200 ok($meta->is_immutable, '... our class is now immutable');
201 isa_ok($meta, 'Class::MOP::Class::Immutable');
202 isa_ok($meta, 'Class::MOP::Class');
204 ok(!Baz->meta->has_method('new'), '... no constructor was made');
207 my $baz = Baz->meta->construct_instance;
209 is($baz->bar, 'BAR', '... got the right default value');
210 is($baz->baz, 'BAZ', '... got the right default value');
214 my $baz = Baz->meta->construct_instance(bar => 'BAZ!', baz => 'BAR!', bah => 'BAH!');
216 is($baz->bar, 'BAZ!', '... got the right parameter value');
217 is($baz->baz, 'BAR!', '... got the right parameter value');
218 is($baz->bah, 'BAH!', '... got the right parameter value');
221 # check out accessors too
223 my $bar_accessor = $meta->find_method_by_name('bar');
224 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
225 isa_ok($bar_accessor, 'Class::MOP::Method');
227 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
229 my $baz_accessor = $meta->find_method_by_name('baz');
230 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
231 isa_ok($baz_accessor, 'Class::MOP::Method');
233 ok($baz_accessor->is_inline, '... the baz accessor is not inlined');
235 my $bah_accessor = $meta->get_method('bah');
236 isa_ok($bah_accessor, 'Class::MOP::Method::Accessor');
237 isa_ok($bah_accessor, 'Class::MOP::Method');
239 ok($bah_accessor->is_inline, '... the baz accessor is not inlined');