10 require_ok(File::Spec->catfile('examples', 'ClassEncapsulatedAttributes.pod'));
16 use metaclass 'ClassEncapsulatedAttributes';
18 Foo->meta->add_attribute('foo' => (
20 predicate => 'has_foo',
21 default => 'init in FOO'
24 Foo->meta->add_attribute('bar' => (
27 default => 'init in FOO'
32 $class->meta->new_object(@_);
38 Bar->meta->add_attribute('foo' => (
40 predicate => 'has_foo',
41 default => 'init in BAR'
44 Bar->meta->add_attribute('bar' => (
47 default => 'init in BAR'
50 sub SUPER_foo { (shift)->SUPER::foo(@_) }
51 sub SUPER_has_foo { (shift)->SUPER::foo(@_) }
52 sub SUPER_get_bar { (shift)->SUPER::get_bar() }
53 sub SUPER_set_bar { (shift)->SUPER::set_bar(@_) }
62 can_ok($foo, 'has_foo');
63 can_ok($foo, 'get_bar');
64 can_ok($foo, 'set_bar');
70 can_ok($bar, 'has_foo');
71 can_ok($bar, 'get_bar');
72 can_ok($bar, 'set_bar');
74 ok($foo->has_foo, '... Foo::has_foo == 1');
75 ok($bar->has_foo, '... Bar::has_foo == 1');
77 is($foo->foo, 'init in FOO', '... got the right default value for Foo::foo');
78 is($bar->foo, 'init in BAR', '... got the right default value for Bar::foo');
80 is($bar->SUPER_foo(), 'init in FOO', '... got the right default value for Bar::SUPER::foo');
82 $bar->SUPER_foo(undef);
84 is($bar->SUPER_foo(), undef, '... successfully set Foo::foo through Bar::SUPER::foo');
85 ok(!$bar->SUPER_has_foo, '... BAR::SUPER::has_foo == 0');
87 ok($foo->has_foo, '... Foo::has_foo (is still) 1');
92 'Foo' => { 'foo' => 'Foo::foo' },
93 'Bar' => { 'foo' => 'Bar::foo' }
98 can_ok($bar, 'has_foo');
99 can_ok($bar, 'get_bar');
100 can_ok($bar, 'set_bar');
102 ok($bar->has_foo, '... Bar::has_foo == 1');
103 ok($bar->SUPER_has_foo, '... Bar::SUPER_has_foo == 1');
105 is($bar->foo, 'Bar::foo', '... got the right default value for Bar::foo');
106 is($bar->SUPER_foo(), 'Foo::foo', '... got the right default value for Bar::SUPER::foo');