6 use Test::More tests => 72;
8 use Scalar::Util 'reftype';
12 require_ok(File::Spec->catfile('examples', 'ArrayBasedStorage.pod'));
21 'instance_metaclass' => 'ArrayBasedStorage::Instance',
24 Foo->meta->add_attribute('foo' => (
26 clearer => 'clear_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 'instance_metaclass' => 'ArrayBasedStorage::Instance',
61 Baz->meta->add_attribute('bling' => (
63 default => 'Baz::bling'
71 use base 'Bar', 'Baz';
77 is(reftype($foo), 'ARRAY', '... Foo is made with ARRAY');
80 can_ok($foo, 'has_foo');
81 can_ok($foo, 'get_bar');
82 can_ok($foo, 'set_bar');
83 can_ok($foo, 'clear_foo');
85 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
86 is($foo->foo(), undef, '... Foo::foo is not defined yet');
87 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
89 $foo->foo('This is Foo');
91 ok($foo->has_foo, '... Foo::foo is defined now');
92 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
96 ok(!$foo->has_foo, '... Foo::foo is not defined anymore');
97 is($foo->foo(), undef, '... Foo::foo is not defined anymore');
100 is($foo->get_bar(), 42, '... Foo::bar == 42');
102 my $foo2 = Foo->new();
103 isa_ok($foo2, 'Foo');
105 is(reftype($foo2), 'ARRAY', '... Foo is made with ARRAY');
107 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
108 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
109 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
111 $foo2->set_bar('DONT PANIC');
112 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
114 is($foo->get_bar(), 42, '... Foo::bar == 42');
118 my $bar = Bar->new();
122 is(reftype($bar), 'ARRAY', '... Bar is made with ARRAY');
125 can_ok($bar, 'has_foo');
126 can_ok($bar, 'get_bar');
127 can_ok($bar, 'set_bar');
129 can_ok($bar, 'has_baz');
131 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
132 is($bar->foo(), undef, '... Bar::foo is not defined yet');
133 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
134 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
135 is($bar->baz(), undef, '... Bar::baz is not defined yet');
137 $bar->foo('This is Bar::foo');
139 ok($bar->has_foo, '... Bar::foo is defined now');
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');
143 $bar->baz('This is Bar::baz');
145 ok($bar->has_baz, '... Bar::baz is defined now');
146 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
147 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
148 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
152 my $baz = Bar::Baz->new();
153 isa_ok($baz, 'Bar::Baz');
158 is(reftype($baz), 'ARRAY', '... Bar::Baz is made with ARRAY');
161 can_ok($baz, 'has_foo');
162 can_ok($baz, 'get_bar');
163 can_ok($baz, 'set_bar');
165 can_ok($baz, 'has_baz');
166 can_ok($baz, 'bling');
168 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
169 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
171 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
172 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
173 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
174 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
176 $baz->foo('This is Bar::Baz::foo');
178 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
179 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
180 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
181 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
183 $baz->baz('This is Bar::Baz::baz');
185 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
186 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
187 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
188 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
189 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');