6 use Test::More tests => 88;
8 use Scalar::Util 'reftype';
10 BEGIN {use Class::MOP;
11 require_ok(File::Spec->catfile('examples', 'InsideOutClass.pod'));
21 'attribute_metaclass' => 'InsideOutClass::Attribute',
22 'instance_metaclass' => 'InsideOutClass::Instance'
25 Foo->meta->add_attribute('foo' => (
27 predicate => 'has_foo',
30 Foo->meta->add_attribute('bar' => (
33 default => 'FOO is BAR'
38 $class->meta->new_object(@_);
43 'attribute_metaclass' => 'InsideOutClass::Attribute',
44 'instance_metaclass' => 'InsideOutClass::Instance'
52 Bar->meta->add_attribute('baz' => (
54 predicate => 'has_baz',
62 'attribute_metaclass' => 'InsideOutClass::Attribute',
63 'instance_metaclass' => 'InsideOutClass::Instance'
66 Baz->meta->add_attribute('bling' => (
68 default => 'Baz::bling'
73 'attribute_metaclass' => 'InsideOutClass::Attribute',
74 'instance_metaclass' => 'InsideOutClass::Instance'
80 use base 'Bar', 'Baz';
86 is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
89 can_ok($foo, 'has_foo');
90 can_ok($foo, 'get_bar');
91 can_ok($foo, 'set_bar');
93 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
94 is($foo->foo(), undef, '... Foo::foo is not defined yet');
95 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
97 $foo->foo('This is Foo');
99 ok($foo->has_foo, '... Foo::foo is defined now');
100 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
103 is($foo->get_bar(), 42, '... Foo::bar == 42');
105 my $foo2 = Foo->new();
106 isa_ok($foo2, 'Foo');
108 is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
110 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
111 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
112 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
114 $foo2->set_bar('DONT PANIC');
115 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
117 is($foo->get_bar(), 42, '... Foo::bar == 42');
121 my $bar = Bar->new();
125 is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
128 can_ok($bar, 'has_foo');
129 can_ok($bar, 'get_bar');
130 can_ok($bar, 'set_bar');
132 can_ok($bar, 'has_baz');
134 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
135 is($bar->foo(), undef, '... Bar::foo is not defined yet');
136 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
137 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
138 is($bar->baz(), undef, '... Bar::baz is not defined yet');
140 $bar->foo('This is Bar::foo');
142 ok($bar->has_foo, '... Bar::foo is defined now');
143 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
144 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
146 $bar->baz('This is Bar::baz');
148 ok($bar->has_baz, '... Bar::baz is defined now');
149 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
150 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
151 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
155 my $baz = Bar::Baz->new();
156 isa_ok($baz, 'Bar::Baz');
161 is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
164 can_ok($baz, 'has_foo');
165 can_ok($baz, 'get_bar');
166 can_ok($baz, 'set_bar');
168 can_ok($baz, 'has_baz');
169 can_ok($baz, 'bling');
171 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
172 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
174 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
175 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
176 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
177 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
179 $baz->foo('This is Bar::Baz::foo');
181 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
182 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
183 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
184 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
186 $baz->baz('This is Bar::Baz::baz');
188 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
189 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
190 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
191 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
192 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
197 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
198 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
200 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
201 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
203 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
204 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
205 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
207 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
208 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
209 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
211 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
213 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
215 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
216 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
217 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
218 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
220 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
221 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
222 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
223 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');