X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Emulate-Class-Accessor-Fast.git;a=blobdiff_plain;f=t%2Fgetset.t;h=b3b13b409421015c0f39dbdbe2e7878210313deb;hp=d3ad761ace7c24ffbbd0319fa32e5104b5d4fd4a;hb=e8abb6ef66e72c5943e570e94b31b8b6fc4bf321;hpb=8eb9108bc536b72c729ed2f454085f429472a2ff diff --git a/t/getset.t b/t/getset.t index d3ad761..b3b13b4 100644 --- a/t/getset.t +++ b/t/getset.t @@ -1,14 +1,30 @@ #!perl use strict; -use Test::More tests => 3; +use Test::More tests => 9; require_ok("MooseX::Adopt::Class::Accessor::Fast"); +{ + @Foo::ISA = qw(Class::Accessor::Fast); + Foo->mk_accessors(qw( foo )); + my $test = Foo->new({ foo => 49 }); + is( $test->get('foo'), 49, "get initial foo"); + $test->set('foo', 42); + is($test->get('foo'), 42, "get new foo"); +} -@Foo::ISA = qw(Class::Accessor::Fast); -Foo->mk_accessors(qw( foo )); +{ + @Bar::ISA = qw(Class::Accessor::Fast); + my $get_ref = Bar->make_ro_accessor('read'); + my $set_ref = Bar->make_wo_accessor('write'); + my $getset_ref = Bar->make_accessor('read_write'); -my $test = Foo->new({ foo => 49 }); + ok(Bar->meta->has_attribute("read"),"has read"); + ok(Bar->meta->has_attribute("write"),"has write"); + ok(Bar->meta->has_attribute("read_write"),"has read_write"); -is( $test->get('foo'), 49, "get initial foo"); -$test->set('foo', 42); -is($test->get('foo'), 42, "get new foo"); + my $obj = Bar->new({read => 1, write => 2, read_write => 3}); + is($get_ref->($obj), 1, "read get works"); + is($getset_ref->($obj), 3, "read_write get works"); + $getset_ref->($obj,2); + is($getset_ref->($obj), 2, "read_write set works"); +}