6 use Test::More tests => 85;
11 require_ok(File::Spec->catdir('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(@_);
48 Bar->meta->add_attribute('baz' => (
50 predicate => 'has_baz',
58 ':attribute_metaclass' => 'InsideOutClass::Attribute',
59 ':instance_metaclass' => 'InsideOutClass::Instance'
62 Baz->meta->add_attribute('bling' => (
64 default => 'Baz::bling'
72 use base 'Bar', 'Baz';
79 can_ok($foo, 'has_foo');
80 can_ok($foo, 'get_bar');
81 can_ok($foo, 'set_bar');
83 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
84 is($foo->foo(), undef, '... Foo::foo is not defined yet');
85 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
87 $foo->foo('This is Foo');
89 ok($foo->has_foo, '... Foo::foo is defined now');
90 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
93 is($foo->get_bar(), 42, '... Foo::bar == 42');
95 my $foo2 = Foo->new();
98 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
99 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
100 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
102 $foo2->set_bar('DONT PANIC');
103 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
105 is($foo->get_bar(), 42, '... Foo::bar == 42');
109 my $bar = Bar->new();
114 can_ok($bar, 'has_foo');
115 can_ok($bar, 'get_bar');
116 can_ok($bar, 'set_bar');
118 can_ok($bar, 'has_baz');
120 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
121 is($bar->foo(), undef, '... Bar::foo is not defined yet');
122 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
123 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
124 is($bar->baz(), undef, '... Bar::baz is not defined yet');
126 $bar->foo('This is Bar::foo');
128 ok($bar->has_foo, '... Bar::foo is defined now');
129 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
130 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
132 $bar->baz('This is Bar::baz');
134 ok($bar->has_baz, '... Bar::baz is defined now');
135 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
136 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
137 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
141 my $baz = Bar::Baz->new();
142 isa_ok($baz, 'Bar::Baz');
148 can_ok($baz, 'has_foo');
149 can_ok($baz, 'get_bar');
150 can_ok($baz, 'set_bar');
152 can_ok($baz, 'has_baz');
153 can_ok($baz, 'bling');
155 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
156 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
158 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
159 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
160 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
161 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
163 $baz->foo('This is Bar::Baz::foo');
165 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
166 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
167 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
168 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
170 $baz->baz('This is Bar::Baz::baz');
172 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
173 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
174 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
175 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
176 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
181 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
182 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
184 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
185 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
187 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
188 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
189 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
191 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
192 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
193 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
195 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
197 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
199 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
200 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
201 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
202 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
204 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
205 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
206 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
207 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');