6 use Test::More tests => 19;
11 require_ok(File::Spec->catdir('examples', 'ArrayBasedInstance.pod'));
17 use metaclass 'Class::MOP::Class' => (
18 ':attribute_metaclass' => 'ArrayBasedInstance::Attribute',
19 ':instance_metaclass' => 'ArrayBasedInstance::Instance',
22 Foo->meta->add_attribute('foo' => (
24 predicate => 'has_foo',
27 Foo->meta->add_attribute('bar' => (
30 default => 'FOO is BAR'
35 $class->meta->new_object(@_);
43 can_ok($foo, 'has_foo');
44 can_ok($foo, 'get_bar');
45 can_ok($foo, 'set_bar');
47 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
48 is($foo->foo(), undef, '... Foo::foo is not defined yet');
49 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
51 $foo->foo('This is Foo');
53 ok($foo->has_foo, '... Foo::foo is defined now');
54 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
57 is($foo->get_bar(), 42, '... Foo::bar == 42');
59 my $foo2 = Foo->new();
62 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
63 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
64 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
66 $foo2->set_bar('DONT PANIC');
67 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
69 is($foo->get_bar(), 42, '... Foo::bar == 42');