6 use Test::More tests => 65;
11 require_ok(File::Spec->catdir('examples', 'ArrayBasedStorage.pod'));
20 ':attribute_metaclass' => 'ArrayBasedStorage::Attribute',
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 ':attribute_metaclass' => 'ArrayBasedStorage::Attribute',
58 ':instance_metaclass' => 'ArrayBasedStorage::Instance',
61 Baz->meta->add_attribute('bling' => (
63 default => 'Baz::bling'
71 use base 'Bar', 'Baz';
78 can_ok($foo, 'has_foo');
79 can_ok($foo, 'get_bar');
80 can_ok($foo, 'set_bar');
82 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
83 is($foo->foo(), undef, '... Foo::foo is not defined yet');
84 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
86 $foo->foo('This is Foo');
88 ok($foo->has_foo, '... Foo::foo is defined now');
89 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
92 is($foo->get_bar(), 42, '... Foo::bar == 42');
94 my $foo2 = Foo->new();
97 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
98 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
99 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
101 $foo2->set_bar('DONT PANIC');
102 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
104 is($foo->get_bar(), 42, '... Foo::bar == 42');
108 my $bar = Bar->new();
113 can_ok($bar, 'has_foo');
114 can_ok($bar, 'get_bar');
115 can_ok($bar, 'set_bar');
117 can_ok($bar, 'has_baz');
119 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
120 is($bar->foo(), undef, '... Bar::foo is not defined yet');
121 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
122 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
123 is($bar->baz(), undef, '... Bar::baz is not defined yet');
125 $bar->foo('This is Bar::foo');
127 ok($bar->has_foo, '... Bar::foo is defined now');
128 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
129 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
131 $bar->baz('This is Bar::baz');
133 ok($bar->has_baz, '... Bar::baz is defined now');
134 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
135 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
136 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
140 my $baz = Bar::Baz->new();
141 isa_ok($baz, 'Bar::Baz');
147 can_ok($baz, 'has_foo');
148 can_ok($baz, 'get_bar');
149 can_ok($baz, 'set_bar');
151 can_ok($baz, 'has_baz');
152 can_ok($baz, 'bling');
154 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
155 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
157 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
158 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
159 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
160 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
162 $baz->foo('This is Bar::Baz::foo');
164 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
165 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
166 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
167 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
169 $baz->baz('This is Bar::Baz::baz');
171 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
172 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
173 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
174 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
175 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');