6 use Test::More tests => 18;
15 is => rw, writer => _foo # turns into (reader => foo, writer => _foo)
16 is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before
17 is => rw, accessor => _foo # turns into (accessor => _foo)
18 is => ro, accessor => _foo # error, accesor is rw
23 my ($is, $attr, $class) = @_;
25 eval "package $class; use Moose; has 'foo' => ( is => '$is', $attr => '_foo' );";
27 return $@ ? die $@ : $class;
33 $class = make_class('rw', 'writer', 'Test::Class::WriterRW');
34 ok($class, "Can define attr with rw + writer");
38 can_ok($obj, qw/foo _foo/);
39 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
40 is($obj->foo(), 1, "$class->foo is reader");
41 dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail
42 ok(!defined $obj->_foo(), "$class->_foo is not reader");
44 $class = make_class('ro', 'writer', 'Test::Class::WriterRO');
45 ok($class, "Can define attr with ro + writer");
49 can_ok($obj, qw/foo _foo/);
50 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
51 is($obj->foo(), 1, "$class->foo is reader");
52 dies_ok {$obj->foo(1)} "$class->foo is not writer";
53 isnt($obj->_foo(), 1, "$class->_foo is not reader");
55 $class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
56 ok($class, "Can define attr with rw + accessor");
60 can_ok($obj, qw/_foo/);
61 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
62 is($obj->_foo(), 1, "$class->foo is reader");
64 dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";