4 use Test::More tests => 28;
8 require_ok(File::Spec->catfile('examples', 'ClassEncapsulatedAttributes.pod'));
14 use metaclass 'ClassEncapsulatedAttributes';
16 Foo->meta->add_attribute('foo' => (
18 predicate => 'has_foo',
19 default => 'init in FOO'
22 Foo->meta->add_attribute('bar' => (
25 default => 'init in FOO'
30 $class->meta->new_object(@_);
36 Bar->meta->add_attribute('foo' => (
38 predicate => 'has_foo',
39 default => 'init in BAR'
42 Bar->meta->add_attribute('bar' => (
45 default => 'init in BAR'
48 sub SUPER_foo { (shift)->SUPER::foo(@_) }
49 sub SUPER_has_foo { (shift)->SUPER::foo(@_) }
50 sub SUPER_get_bar { (shift)->SUPER::get_bar() }
51 sub SUPER_set_bar { (shift)->SUPER::set_bar(@_) }
60 can_ok($foo, 'has_foo');
61 can_ok($foo, 'get_bar');
62 can_ok($foo, 'set_bar');
68 can_ok($bar, 'has_foo');
69 can_ok($bar, 'get_bar');
70 can_ok($bar, 'set_bar');
72 ok($foo->has_foo, '... Foo::has_foo == 1');
73 ok($bar->has_foo, '... Bar::has_foo == 1');
75 is($foo->foo, 'init in FOO', '... got the right default value for Foo::foo');
76 is($bar->foo, 'init in BAR', '... got the right default value for Bar::foo');
78 is($bar->SUPER_foo(), 'init in FOO', '... got the right default value for Bar::SUPER::foo');
80 $bar->SUPER_foo(undef);
82 is($bar->SUPER_foo(), undef, '... successfully set Foo::foo through Bar::SUPER::foo');
83 ok(!$bar->SUPER_has_foo, '... BAR::SUPER::has_foo == 0');
85 ok($foo->has_foo, '... Foo::has_foo (is still) 1');
90 'Foo' => { 'foo' => 'Foo::foo' },
91 'Bar' => { 'foo' => 'Bar::foo' }
96 can_ok($bar, 'has_foo');
97 can_ok($bar, 'get_bar');
98 can_ok($bar, 'set_bar');
100 ok($bar->has_foo, '... Bar::has_foo == 1');
101 ok($bar->SUPER_has_foo, '... Bar::SUPER_has_foo == 1');
103 is($bar->foo, 'Bar::foo', '... got the right default value for Bar::foo');
104 is($bar->SUPER_foo(), 'Foo::foo', '... got the right default value for Bar::SUPER::foo');