6 use Test::More tests => 73;
11 use_ok('Class::MOP::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');
77 # they made a constructor for us :)
83 is($foo->bar, 'BAR', '... got the right default value');
87 my $foo = Foo->new(bar => 'BAZ');
89 is($foo->bar, 'BAZ', '... got the right parameter value');
92 # check out accessors too
94 my $bar_accessor = $meta->get_method('bar');
95 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
96 isa_ok($bar_accessor, 'Class::MOP::Method');
98 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
103 my $meta = Bar->meta;
104 is($meta->name, 'Bar', '... checking the Bar metaclass');
107 my $bar_accessor = $meta->find_method_by_name('bar');
108 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
109 isa_ok($bar_accessor, 'Class::MOP::Method');
111 ok(!$bar_accessor->is_inline, '... the bar accessor is not inlined');
113 my $baz_accessor = $meta->get_method('baz');
114 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
115 isa_ok($baz_accessor, 'Class::MOP::Method');
117 ok(!$baz_accessor->is_inline, '... the baz accessor is not inlined');
120 ok(!$meta->is_immutable, '... our class is not immutable');
123 $meta->make_immutable(
124 inline_constructor => 1,
125 inline_accessors => 1,
127 } '... changed Bar to be immutable';
129 ok($meta->is_immutable, '... our class is now immutable');
130 isa_ok($meta, 'Class::MOP::Class');
132 # they made a constructor for us :)
133 can_ok('Bar', 'new');
138 is($bar->bar, 'BAR', '... got the right default value');
139 is($bar->baz, 'BAZ', '... got the right default value');
143 my $bar = Bar->new(bar => 'BAZ!', baz => 'BAR!');
145 is($bar->bar, 'BAZ!', '... got the right parameter value');
146 is($bar->baz, 'BAR!', '... got the right parameter value');
149 # check out accessors too
151 my $bar_accessor = $meta->find_method_by_name('bar');
152 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
153 isa_ok($bar_accessor, 'Class::MOP::Method');
155 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
157 my $baz_accessor = $meta->get_method('baz');
158 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
159 isa_ok($baz_accessor, 'Class::MOP::Method');
161 ok($baz_accessor->is_inline, '... the baz accessor is not inlined');
166 my $meta = Baz->meta;
167 is($meta->name, 'Baz', '... checking the Bar metaclass');
170 my $bar_accessor = $meta->find_method_by_name('bar');
171 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
172 isa_ok($bar_accessor, 'Class::MOP::Method');
174 ok(!$bar_accessor->is_inline, '... the bar accessor is not inlined');
176 my $baz_accessor = $meta->find_method_by_name('baz');
177 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
178 isa_ok($baz_accessor, 'Class::MOP::Method');
180 ok($baz_accessor->is_inline, '... the baz accessor is inlined');
182 my $bah_accessor = $meta->get_method('bah');
183 isa_ok($bah_accessor, 'Class::MOP::Method::Accessor');
184 isa_ok($bah_accessor, 'Class::MOP::Method');
186 ok(!$bah_accessor->is_inline, '... the baz accessor is not inlined');
189 ok(!$meta->is_immutable, '... our class is not immutable');
192 $meta->make_immutable(
193 inline_constructor => 0,
194 inline_accessors => 1,
196 } '... changed Bar to be immutable';
198 ok($meta->is_immutable, '... our class is now immutable');
199 isa_ok($meta, 'Class::MOP::Class');
201 ok(!Baz->meta->has_method('new'), '... no constructor was made');
204 my $baz = Baz->meta->construct_instance;
206 is($baz->bar, 'BAR', '... got the right default value');
207 is($baz->baz, 'BAZ', '... got the right default value');
211 my $baz = Baz->meta->construct_instance(bar => 'BAZ!', baz => 'BAR!', bah => 'BAH!');
213 is($baz->bar, 'BAZ!', '... got the right parameter value');
214 is($baz->baz, 'BAR!', '... got the right parameter value');
215 is($baz->bah, 'BAH!', '... got the right parameter value');
218 # check out accessors too
220 my $bar_accessor = $meta->find_method_by_name('bar');
221 isa_ok($bar_accessor, 'Class::MOP::Method::Accessor');
222 isa_ok($bar_accessor, 'Class::MOP::Method');
224 ok(!$bar_accessor->is_inline, '... the bar accessor is still not inlined');
226 my $baz_accessor = $meta->find_method_by_name('baz');
227 isa_ok($baz_accessor, 'Class::MOP::Method::Accessor');
228 isa_ok($baz_accessor, 'Class::MOP::Method');
230 ok($baz_accessor->is_inline, '... the baz accessor is not inlined');
232 my $bah_accessor = $meta->get_method('bah');
233 isa_ok($bah_accessor, 'Class::MOP::Method::Accessor');
234 isa_ok($bah_accessor, 'Class::MOP::Method');
236 ok($bah_accessor->is_inline, '... the baz accessor is not inlined');