6 use Scalar::Util 'reftype';
9 require_ok(File::Spec->catfile('examples', 'InsideOutClass.pod'));
19 'attribute_metaclass' => 'InsideOutClass::Attribute',
20 'instance_metaclass' => 'InsideOutClass::Instance'
23 Foo->meta->add_attribute('foo' => (
25 predicate => 'has_foo',
28 Foo->meta->add_attribute('bar' => (
31 default => 'FOO is BAR'
36 $class->meta->new_object(@_);
41 'attribute_metaclass' => 'InsideOutClass::Attribute',
42 'instance_metaclass' => 'InsideOutClass::Instance'
50 Bar->meta->add_attribute('baz' => (
52 predicate => 'has_baz',
60 'attribute_metaclass' => 'InsideOutClass::Attribute',
61 'instance_metaclass' => 'InsideOutClass::Instance'
64 Baz->meta->add_attribute('bling' => (
66 default => 'Baz::bling'
71 'attribute_metaclass' => 'InsideOutClass::Attribute',
72 'instance_metaclass' => 'InsideOutClass::Instance'
78 use base 'Bar', 'Baz';
84 is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
87 can_ok($foo, 'has_foo');
88 can_ok($foo, 'get_bar');
89 can_ok($foo, 'set_bar');
91 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
92 is($foo->foo(), undef, '... Foo::foo is not defined yet');
93 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
95 $foo->foo('This is Foo');
97 ok($foo->has_foo, '... Foo::foo is defined now');
98 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
101 is($foo->get_bar(), 42, '... Foo::bar == 42');
103 my $foo2 = Foo->new();
104 isa_ok($foo2, 'Foo');
106 is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
108 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
109 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
110 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
112 $foo2->set_bar('DONT PANIC');
113 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
115 is($foo->get_bar(), 42, '... Foo::bar == 42');
119 my $bar = Bar->new();
123 is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
126 can_ok($bar, 'has_foo');
127 can_ok($bar, 'get_bar');
128 can_ok($bar, 'set_bar');
130 can_ok($bar, 'has_baz');
132 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
133 is($bar->foo(), undef, '... Bar::foo is not defined yet');
134 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
135 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
136 is($bar->baz(), undef, '... Bar::baz is not defined yet');
138 $bar->foo('This is Bar::foo');
140 ok($bar->has_foo, '... Bar::foo is defined now');
141 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
142 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
144 $bar->baz('This is Bar::baz');
146 ok($bar->has_baz, '... Bar::baz is defined now');
147 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
148 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
149 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
153 my $baz = Bar::Baz->new();
154 isa_ok($baz, 'Bar::Baz');
159 is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
162 can_ok($baz, 'has_foo');
163 can_ok($baz, 'get_bar');
164 can_ok($baz, 'set_bar');
166 can_ok($baz, 'has_baz');
167 can_ok($baz, 'bling');
169 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
170 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
172 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
173 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
174 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
175 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
177 $baz->foo('This is Bar::Baz::foo');
179 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
180 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
181 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
182 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
184 $baz->baz('This is Bar::Baz::baz');
186 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
187 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
188 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
189 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
190 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
195 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
196 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
198 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
199 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
201 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
202 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
203 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
205 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
206 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
207 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
209 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
211 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
213 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
214 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
215 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
216 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
218 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
219 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
220 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
221 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');