X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F105_ClassEncapsulatedAttributes_test.t;h=075f61665c8b9e5430ace4454a28b7b8c920f000;hb=86a4d8730cfe673db674c692f7703632b700c7c9;hp=3f294264ba92fabff33b8efe454e2fc077e9dd1c;hpb=6bb3669a84ccc4e5e984238258c4bcd0868fe137;p=gitmo%2FClass-MOP.git diff --git a/t/105_ClassEncapsulatedAttributes_test.t b/t/105_ClassEncapsulatedAttributes_test.t index 3f29426..075f616 100644 --- a/t/105_ClassEncapsulatedAttributes_test.t +++ b/t/105_ClassEncapsulatedAttributes_test.t @@ -1,55 +1,57 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More; use File::Spec; -BEGIN {use Class::MOP; +use Class::MOP; + +BEGIN { require_ok(File::Spec->catfile('examples', 'ClassEncapsulatedAttributes.pod')); } { package Foo; - + use metaclass 'ClassEncapsulatedAttributes'; - + Foo->meta->add_attribute('foo' => ( accessor => 'foo', - predicate => 'has_foo', + predicate => 'has_foo', default => 'init in FOO' )); - + Foo->meta->add_attribute('bar' => ( reader => 'get_bar', writer => 'set_bar', default => 'init in FOO' )); - + sub new { my $class = shift; $class->meta->new_object(@_); } - + package Bar; our @ISA = ('Foo'); - + Bar->meta->add_attribute('foo' => ( accessor => 'foo', predicate => 'has_foo', - default => 'init in BAR' + default => 'init in BAR' )); - + Bar->meta->add_attribute('bar' => ( reader => 'get_bar', writer => 'set_bar', - default => 'init in BAR' + default => 'init in BAR' )); - + sub SUPER_foo { (shift)->SUPER::foo(@_) } - sub SUPER_has_foo { (shift)->SUPER::foo(@_) } - sub SUPER_get_bar { (shift)->SUPER::get_bar() } - sub SUPER_set_bar { (shift)->SUPER::set_bar(@_) } - + sub SUPER_has_foo { (shift)->SUPER::foo(@_) } + sub SUPER_get_bar { (shift)->SUPER::get_bar() } + sub SUPER_set_bar { (shift)->SUPER::set_bar(@_) } + } { @@ -74,13 +76,13 @@ BEGIN {use Class::MOP; is($foo->foo, 'init in FOO', '... got the right default value for Foo::foo'); is($bar->foo, 'init in BAR', '... got the right default value for Bar::foo'); - - is($bar->SUPER_foo(), 'init in FOO', '... got the right default value for Bar::SUPER::foo'); - + + is($bar->SUPER_foo(), 'init in FOO', '... got the right default value for Bar::SUPER::foo'); + $bar->SUPER_foo(undef); - is($bar->SUPER_foo(), undef, '... successfully set Foo::foo through Bar::SUPER::foo'); - ok(!$bar->SUPER_has_foo, '... BAR::SUPER::has_foo == 0'); + is($bar->SUPER_foo(), undef, '... successfully set Foo::foo through Bar::SUPER::foo'); + ok(!$bar->SUPER_has_foo, '... BAR::SUPER::has_foo == 0'); ok($foo->has_foo, '... Foo::has_foo (is still) 1'); } @@ -88,7 +90,7 @@ BEGIN {use Class::MOP; { my $bar = Bar->new( 'Foo' => { 'foo' => 'Foo::foo' }, - 'Bar' => { 'foo' => 'Bar::foo' } + 'Bar' => { 'foo' => 'Bar::foo' } ); isa_ok($bar, 'Bar'); @@ -98,9 +100,10 @@ BEGIN {use Class::MOP; can_ok($bar, 'set_bar'); ok($bar->has_foo, '... Bar::has_foo == 1'); - ok($bar->SUPER_has_foo, '... Bar::SUPER_has_foo == 1'); + ok($bar->SUPER_has_foo, '... Bar::SUPER_has_foo == 1'); - is($bar->foo, 'Bar::foo', '... got the right default value for Bar::foo'); - is($bar->SUPER_foo(), 'Foo::foo', '... got the right default value for Bar::SUPER::foo'); + is($bar->foo, 'Bar::foo', '... got the right default value for Bar::foo'); + is($bar->SUPER_foo(), 'Foo::foo', '... got the right default value for Bar::SUPER::foo'); } +done_testing;