6 use Test::More tests => 89;
8 use Scalar::Util 'reftype';
12 require_ok(File::Spec->catfile('examples', 'InsideOutClass.pod'));
22 'attribute_metaclass' => 'InsideOutClass::Attribute',
23 'instance_metaclass' => 'InsideOutClass::Instance'
26 Foo->meta->add_attribute('foo' => (
28 predicate => 'has_foo',
31 Foo->meta->add_attribute('bar' => (
34 default => 'FOO is BAR'
39 $class->meta->new_object(@_);
44 'attribute_metaclass' => 'InsideOutClass::Attribute',
45 'instance_metaclass' => 'InsideOutClass::Instance'
53 Bar->meta->add_attribute('baz' => (
55 predicate => 'has_baz',
63 'attribute_metaclass' => 'InsideOutClass::Attribute',
64 'instance_metaclass' => 'InsideOutClass::Instance'
67 Baz->meta->add_attribute('bling' => (
69 default => 'Baz::bling'
74 'attribute_metaclass' => 'InsideOutClass::Attribute',
75 'instance_metaclass' => 'InsideOutClass::Instance'
81 use base 'Bar', 'Baz';
87 is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
90 can_ok($foo, 'has_foo');
91 can_ok($foo, 'get_bar');
92 can_ok($foo, 'set_bar');
94 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
95 is($foo->foo(), undef, '... Foo::foo is not defined yet');
96 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
98 $foo->foo('This is Foo');
100 ok($foo->has_foo, '... Foo::foo is defined now');
101 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
104 is($foo->get_bar(), 42, '... Foo::bar == 42');
106 my $foo2 = Foo->new();
107 isa_ok($foo2, 'Foo');
109 is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
111 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
112 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
113 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
115 $foo2->set_bar('DONT PANIC');
116 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
118 is($foo->get_bar(), 42, '... Foo::bar == 42');
122 my $bar = Bar->new();
126 is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
129 can_ok($bar, 'has_foo');
130 can_ok($bar, 'get_bar');
131 can_ok($bar, 'set_bar');
133 can_ok($bar, 'has_baz');
135 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
136 is($bar->foo(), undef, '... Bar::foo is not defined yet');
137 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
138 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
139 is($bar->baz(), undef, '... Bar::baz is not defined yet');
141 $bar->foo('This is Bar::foo');
143 ok($bar->has_foo, '... Bar::foo is defined now');
144 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
145 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
147 $bar->baz('This is Bar::baz');
149 ok($bar->has_baz, '... Bar::baz is defined now');
150 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
151 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
152 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
156 my $baz = Bar::Baz->new();
157 isa_ok($baz, 'Bar::Baz');
162 is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
165 can_ok($baz, 'has_foo');
166 can_ok($baz, 'get_bar');
167 can_ok($baz, 'set_bar');
169 can_ok($baz, 'has_baz');
170 can_ok($baz, 'bling');
172 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
173 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
175 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
176 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
177 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
178 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
180 $baz->foo('This is Bar::Baz::foo');
182 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
183 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
184 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
185 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
187 $baz->baz('This is Bar::Baz::baz');
189 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
190 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
191 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
192 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
193 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
198 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
199 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
201 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
202 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
204 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
205 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
206 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
208 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
209 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
210 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
212 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
214 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
216 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
217 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
218 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
219 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
221 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
222 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
223 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
224 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');