6 use Test::More tests => 69;
8 use Scalar::Util 'reftype';
12 require_ok(File::Spec->catdir('examples', 'ArrayBasedStorage.pod'));
21 ':instance_metaclass' => 'ArrayBasedStorage::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' => 'ArrayBasedStorage::Instance',
60 Baz->meta->add_attribute('bling' => (
62 default => 'Baz::bling'
70 use base 'Bar', 'Baz';
76 is(reftype($foo), 'ARRAY', '... Foo is made with ARRAY');
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 is(reftype($foo2), 'ARRAY', '... Foo is made with ARRAY');
100 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
101 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
102 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
104 $foo2->set_bar('DONT PANIC');
105 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
107 is($foo->get_bar(), 42, '... Foo::bar == 42');
111 my $bar = Bar->new();
115 is(reftype($bar), 'ARRAY', '... Bar is made with ARRAY');
118 can_ok($bar, 'has_foo');
119 can_ok($bar, 'get_bar');
120 can_ok($bar, 'set_bar');
122 can_ok($bar, 'has_baz');
124 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
125 is($bar->foo(), undef, '... Bar::foo is not defined yet');
126 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
127 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
128 is($bar->baz(), undef, '... Bar::baz is not defined yet');
130 $bar->foo('This is Bar::foo');
132 ok($bar->has_foo, '... Bar::foo is defined now');
133 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
134 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
136 $bar->baz('This is Bar::baz');
138 ok($bar->has_baz, '... Bar::baz is defined now');
139 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
140 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
141 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
145 my $baz = Bar::Baz->new();
146 isa_ok($baz, 'Bar::Baz');
151 is(reftype($baz), 'ARRAY', '... Bar::Baz is made with ARRAY');
154 can_ok($baz, 'has_foo');
155 can_ok($baz, 'get_bar');
156 can_ok($baz, 'set_bar');
158 can_ok($baz, 'has_baz');
159 can_ok($baz, 'bling');
161 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
162 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
164 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
165 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
166 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
167 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
169 $baz->foo('This is Bar::Baz::foo');
171 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
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');
176 $baz->baz('This is Bar::Baz::baz');
178 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
179 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
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');