6 use Test::More tests => 29;
11 require_ok(File::Spec->catdir('examples', 'ClassEncapsulatedAttributes.pod'));
17 sub meta { ClassEncapsulatedAttributes->initialize($_[0]) }
19 Foo->meta->add_attribute(
20 ClassEncapsulatedAttributes::Attribute->new('foo' => (
22 predicate => 'has_foo',
23 default => 'init in FOO'
27 Foo->meta->add_attribute(
28 ClassEncapsulatedAttributes::Attribute->new('bar' => (
31 default => 'init in FOO'
37 bless $class->meta->construct_instance(@_) => $class;
43 Bar->meta->add_attribute(
44 ClassEncapsulatedAttributes::Attribute->new('foo' => (
46 predicate => 'has_foo',
47 default => 'init in BAR'
51 Bar->meta->add_attribute(
52 ClassEncapsulatedAttributes::Attribute->new('bar' => (
55 default => 'init in BAR'
59 sub SUPER_foo { (shift)->SUPER::foo(@_) }
60 sub SUPER_has_foo { (shift)->SUPER::foo(@_) }
61 sub SUPER_get_bar { (shift)->SUPER::get_bar() }
62 sub SUPER_set_bar { (shift)->SUPER::set_bar(@_) }
71 can_ok($foo, 'has_foo');
72 can_ok($foo, 'get_bar');
73 can_ok($foo, 'set_bar');
79 can_ok($bar, 'has_foo');
80 can_ok($bar, 'get_bar');
81 can_ok($bar, 'set_bar');
83 ok($foo->has_foo, '... Foo::has_foo == 1');
84 ok($bar->has_foo, '... Bar::has_foo == 1');
86 is($foo->foo, 'init in FOO', '... got the right default value for Foo::foo');
87 is($bar->foo, 'init in BAR', '... got the right default value for Bar::foo');
89 is($bar->SUPER_foo(), 'init in FOO', '... got the right default value for Bar::SUPER::foo');
91 $bar->SUPER_foo(undef);
93 is($bar->SUPER_foo(), undef, '... successfully set Foo::foo through Bar::SUPER::foo');
94 ok(!$bar->SUPER_has_foo, '... BAR::SUPER::has_foo == 0');
96 ok($foo->has_foo, '... Foo::has_foo (is still) 1');
101 'Foo' => { 'foo' => 'Foo::foo' },
102 'Bar' => { 'foo' => 'Bar::foo' }
107 can_ok($bar, 'has_foo');
108 can_ok($bar, 'get_bar');
109 can_ok($bar, 'set_bar');
111 ok($bar->has_foo, '... Bar::has_foo == 1');
112 ok($bar->SUPER_has_foo, '... Bar::SUPER_has_foo == 1');
114 is($bar->foo, 'Bar::foo', '... got the right default value for Bar::foo');
115 is($bar->SUPER_foo(), 'Foo::foo', '... got the right default value for Bar::SUPER::foo');