6 use Test::More tests => 17;
13 is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
14 is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
15 is => rw, accessor => _foo # turns into (accessor => _foo)
16 is => ro, accessor => _foo # error, accesor is rw
21 my ($is, $attr, $class) = @_;
23 eval "package $class; use Moose; has 'foo' => ( is => '$is', $attr => '_foo' );";
25 return $@ ? die $@ : $class;
31 $class = make_class('rw', 'writer', 'Test::Class::WriterRW');
32 ok($class, "Can define attr with rw + writer");
36 can_ok($obj, qw/foo _foo/);
37 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
38 is($obj->foo(), 1, "$class->foo is reader");
39 dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail
40 ok(!defined $obj->_foo(), "$class->_foo is not reader");
42 $class = make_class('ro', 'writer', 'Test::Class::WriterRO');
43 ok($class, "Can define attr with ro + writer");
47 can_ok($obj, qw/foo _foo/);
48 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
49 is($obj->foo(), 1, "$class->foo is reader");
50 dies_ok {$obj->foo(1)} "$class->foo is not writer";
51 isnt($obj->_foo(), 1, "$class->_foo is not reader");
53 $class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
54 ok($class, "Can define attr with rw + accessor");
58 can_ok($obj, qw/_foo/);
59 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
60 is($obj->_foo(), 1, "$class->foo is reader");
62 dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";