6 use Test::More tests => 65;
11 require_ok(File::Spec->catdir('examples', 'ArrayBasedStorage.pod'));
20 ':instance_metaclass' => 'ArrayBasedStorage::Instance',
23 Foo->meta->add_attribute('foo' => (
25 predicate => 'has_foo',
28 Foo->meta->add_attribute('bar' => (
31 default => 'FOO is BAR'
36 $class->meta->new_object(@_);
46 Bar->meta->add_attribute('baz' => (
48 predicate => 'has_baz',
56 ':instance_metaclass' => 'ArrayBasedStorage::Instance',
59 Baz->meta->add_attribute('bling' => (
61 default => 'Baz::bling'
69 use base 'Bar', 'Baz';
76 can_ok($foo, 'has_foo');
77 can_ok($foo, 'get_bar');
78 can_ok($foo, 'set_bar');
80 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
81 is($foo->foo(), undef, '... Foo::foo is not defined yet');
82 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
84 $foo->foo('This is Foo');
86 ok($foo->has_foo, '... Foo::foo is defined now');
87 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
90 is($foo->get_bar(), 42, '... Foo::bar == 42');
92 my $foo2 = Foo->new();
95 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
96 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
97 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
99 $foo2->set_bar('DONT PANIC');
100 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
102 is($foo->get_bar(), 42, '... Foo::bar == 42');
106 my $bar = Bar->new();
111 can_ok($bar, 'has_foo');
112 can_ok($bar, 'get_bar');
113 can_ok($bar, 'set_bar');
115 can_ok($bar, 'has_baz');
117 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
118 is($bar->foo(), undef, '... Bar::foo is not defined yet');
119 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
120 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
121 is($bar->baz(), undef, '... Bar::baz is not defined yet');
123 $bar->foo('This is Bar::foo');
125 ok($bar->has_foo, '... Bar::foo is defined now');
126 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
127 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
129 $bar->baz('This is Bar::baz');
131 ok($bar->has_baz, '... Bar::baz is defined now');
132 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
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');
138 my $baz = Bar::Baz->new();
139 isa_ok($baz, 'Bar::Baz');
145 can_ok($baz, 'has_foo');
146 can_ok($baz, 'get_bar');
147 can_ok($baz, 'set_bar');
149 can_ok($baz, 'has_baz');
150 can_ok($baz, 'bling');
152 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
153 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
155 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
156 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
157 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
158 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
160 $baz->foo('This is Bar::Baz::foo');
162 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
163 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
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 $baz->baz('This is Bar::Baz::baz');
169 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
170 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
171 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
172 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
173 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');