6 use Test::More tests => 89;
8 use Scalar::Util 'reftype';
12 require_ok(File::Spec->catdir('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(@_);
49 Bar->meta->add_attribute('baz' => (
51 predicate => 'has_baz',
59 ':attribute_metaclass' => 'InsideOutClass::Attribute',
60 ':instance_metaclass' => 'InsideOutClass::Instance'
63 Baz->meta->add_attribute('bling' => (
65 default => 'Baz::bling'
73 use base 'Bar', 'Baz';
79 is(reftype($foo), 'SCALAR', '... Foo is made with SCALAR');
82 can_ok($foo, 'has_foo');
83 can_ok($foo, 'get_bar');
84 can_ok($foo, 'set_bar');
86 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
87 is($foo->foo(), undef, '... Foo::foo is not defined yet');
88 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
90 $foo->foo('This is Foo');
92 ok($foo->has_foo, '... Foo::foo is defined now');
93 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
96 is($foo->get_bar(), 42, '... Foo::bar == 42');
98 my $foo2 = Foo->new();
101 is(reftype($foo2), 'SCALAR', '... Foo is made with SCALAR');
103 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
104 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
105 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
107 $foo2->set_bar('DONT PANIC');
108 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
110 is($foo->get_bar(), 42, '... Foo::bar == 42');
114 my $bar = Bar->new();
118 is(reftype($bar), 'SCALAR', '... Bar is made with SCALAR');
121 can_ok($bar, 'has_foo');
122 can_ok($bar, 'get_bar');
123 can_ok($bar, 'set_bar');
125 can_ok($bar, 'has_baz');
127 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
128 is($bar->foo(), undef, '... Bar::foo is not defined yet');
129 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
130 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
131 is($bar->baz(), undef, '... Bar::baz is not defined yet');
133 $bar->foo('This is Bar::foo');
135 ok($bar->has_foo, '... Bar::foo is defined now');
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');
139 $bar->baz('This is Bar::baz');
141 ok($bar->has_baz, '... Bar::baz is defined now');
142 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
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');
148 my $baz = Bar::Baz->new();
149 isa_ok($baz, 'Bar::Baz');
154 is(reftype($baz), 'SCALAR', '... Bar::Baz is made with SCALAR');
157 can_ok($baz, 'has_foo');
158 can_ok($baz, 'get_bar');
159 can_ok($baz, 'set_bar');
161 can_ok($baz, 'has_baz');
162 can_ok($baz, 'bling');
164 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
165 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
167 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
168 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
169 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
170 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
172 $baz->foo('This is Bar::Baz::foo');
174 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
175 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
176 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
177 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
179 $baz->baz('This is Bar::Baz::baz');
181 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
182 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
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');
190 ok(*{'Foo::foo'}{HASH}, '... there is a foo package variable in Foo');
191 ok(*{'Foo::bar'}{HASH}, '... there is a bar package variable in Foo');
193 is(scalar(keys(%{'Foo::foo'})), 4, '... got the right number of entries for Foo::foo');
194 is(scalar(keys(%{'Foo::bar'})), 4, '... got the right number of entries for Foo::bar');
196 ok(!*{'Bar::foo'}{HASH}, '... no foo package variable in Bar');
197 ok(!*{'Bar::bar'}{HASH}, '... no bar package variable in Bar');
198 ok(*{'Bar::baz'}{HASH}, '... there is a baz package variable in Bar');
200 is(scalar(keys(%{'Bar::foo'})), 0, '... got the right number of entries for Bar::foo');
201 is(scalar(keys(%{'Bar::bar'})), 0, '... got the right number of entries for Bar::bar');
202 is(scalar(keys(%{'Bar::baz'})), 2, '... got the right number of entries for Bar::baz');
204 ok(*{'Baz::bling'}{HASH}, '... there is a bar package variable in Baz');
206 is(scalar(keys(%{'Baz::bling'})), 1, '... got the right number of entries for Baz::bling');
208 ok(!*{'Bar::Baz::foo'}{HASH}, '... no foo package variable in Bar::Baz');
209 ok(!*{'Bar::Baz::bar'}{HASH}, '... no bar package variable in Bar::Baz');
210 ok(!*{'Bar::Baz::baz'}{HASH}, '... no baz package variable in Bar::Baz');
211 ok(!*{'Bar::Baz::bling'}{HASH}, '... no bar package variable in Baz::Baz');
213 is(scalar(keys(%{'Bar::Baz::foo'})), 0, '... got the right number of entries for Bar::Baz::foo');
214 is(scalar(keys(%{'Bar::Baz::bar'})), 0, '... got the right number of entries for Bar::Baz::bar');
215 is(scalar(keys(%{'Bar::Baz::baz'})), 0, '... got the right number of entries for Bar::Baz::baz');
216 is(scalar(keys(%{'Bar::Baz::bling'})), 0, '... got the right number of entries for Bar::Baz::bling');