6 use Test::More tests => 85;
11 require_ok(File::Spec->catdir('examples', 'InsideOutClass.pod'));
21 ':instance_metaclass' => 'InsideOutClass::Instance'
24 Foo->meta->add_attribute('foo' => (
26 predicate => 'has_foo',
29 Foo->meta->add_attribute('bar' => (
32 default => 'FOO is BAR'
37 $class->meta->new_object(@_);
47 Bar->meta->add_attribute('baz' => (
49 predicate => 'has_baz',
57 ':instance_metaclass' => 'InsideOutClass::Instance'
60 Baz->meta->add_attribute('bling' => (
62 default => 'Baz::bling'
70 use base 'Bar', 'Baz';
77 can_ok($foo, 'has_foo');
78 can_ok($foo, 'get_bar');
79 can_ok($foo, 'set_bar');
81 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
82 is($foo->foo(), undef, '... Foo::foo is not defined yet');
83 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
85 $foo->foo('This is Foo');
87 ok($foo->has_foo, '... Foo::foo is defined now');
88 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
91 is($foo->get_bar(), 42, '... Foo::bar == 42');
93 my $foo2 = Foo->new();
96 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
97 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
98 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
100 $foo2->set_bar('DONT PANIC');
101 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
103 is($foo->get_bar(), 42, '... Foo::bar == 42');
107 my $bar = Bar->new();
112 can_ok($bar, 'has_foo');
113 can_ok($bar, 'get_bar');
114 can_ok($bar, 'set_bar');
116 can_ok($bar, 'has_baz');
118 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
119 is($bar->foo(), undef, '... Bar::foo is not defined yet');
120 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
121 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
122 is($bar->baz(), undef, '... Bar::baz is not defined yet');
124 $bar->foo('This is Bar::foo');
126 ok($bar->has_foo, '... Bar::foo is defined now');
127 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
128 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
130 $bar->baz('This is Bar::baz');
132 ok($bar->has_baz, '... Bar::baz is defined now');
133 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
134 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
135 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
139 my $baz = Bar::Baz->new();
140 isa_ok($baz, 'Bar::Baz');
146 can_ok($baz, 'has_foo');
147 can_ok($baz, 'get_bar');
148 can_ok($baz, 'set_bar');
150 can_ok($baz, 'has_baz');
151 can_ok($baz, 'bling');
153 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
154 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
156 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
157 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
158 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
159 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
161 $baz->foo('This is Bar::Baz::foo');
163 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
164 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
165 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
166 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
168 $baz->baz('This is Bar::Baz::baz');
170 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
171 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
172 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
173 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
174 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
179 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
180 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
182 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
183 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
185 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
186 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
187 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
189 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
190 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
191 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
193 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
195 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
197 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
198 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
199 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
200 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
202 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
203 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
204 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
205 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');