tests + fix for $obj->$code_ref notation that blew up
[gitmo/MooseX-Emulate-Class-Accessor-Fast.git] / t / getset.t
CommitLineData
c5a105b3 1#!perl
2use strict;
e8abb6ef 3use Test::More tests => 9;
c5a105b3 4
5require_ok("MooseX::Adopt::Class::Accessor::Fast");
e8abb6ef 6{
7 @Foo::ISA = qw(Class::Accessor::Fast);
8 Foo->mk_accessors(qw( foo ));
9 my $test = Foo->new({ foo => 49 });
10 is( $test->get('foo'), 49, "get initial foo");
11 $test->set('foo', 42);
12 is($test->get('foo'), 42, "get new foo");
13}
c5a105b3 14
e8abb6ef 15{
16 @Bar::ISA = qw(Class::Accessor::Fast);
17 my $get_ref = Bar->make_ro_accessor('read');
18 my $set_ref = Bar->make_wo_accessor('write');
19 my $getset_ref = Bar->make_accessor('read_write');
c5a105b3 20
e8abb6ef 21 ok(Bar->meta->has_attribute("read"),"has read");
22 ok(Bar->meta->has_attribute("write"),"has write");
23 ok(Bar->meta->has_attribute("read_write"),"has read_write");
c5a105b3 24
e8abb6ef 25 my $obj = Bar->new({read => 1, write => 2, read_write => 3});
26 is($get_ref->($obj), 1, "read get works");
27 is($getset_ref->($obj), 3, "read_write get works");
28 $getset_ref->($obj,2);
29 is($getset_ref->($obj), 2, "read_write set works");
30}