Commit | Line | Data |
68a51c00 |
1 | use strictures 1; |
2 | use Test::More; |
204ca0d3 |
3 | use Test::Fatal; |
68a51c00 |
4 | |
5 | my @result; |
6 | |
7 | { |
8 | package Foo; |
9 | |
10 | use Moo; |
11 | |
12 | has one => ( |
13 | is => 'rw', |
14 | reader => 'get_one', |
15 | writer => 'set_one', |
16 | ); |
b1a9585f |
17 | |
18 | sub one {'sub'} |
68a51c00 |
19 | } |
20 | |
21 | { |
22 | package Bar; |
23 | |
24 | use Moo; |
25 | |
26 | has two => ( |
27 | is => 'rw', |
28 | accessor => 'TWO', |
29 | ); |
30 | } |
31 | |
32 | my $foo = Foo->new(one => 'lol'); |
33 | my $bar = Bar->new(two => '...'); |
34 | |
35 | is( $foo->get_one, 'lol', 'reader works' ); |
36 | $foo->set_one('rofl'); |
37 | is( $foo->get_one, 'rofl', 'writer works' ); |
b1a9585f |
38 | is( $foo->one, 'sub', 'reader+writer = no accessor' ); |
68a51c00 |
39 | |
204ca0d3 |
40 | ok( exception { $foo->get_one('blah') }, 'reader dies on write' ); |
33d35735 |
41 | |
68a51c00 |
42 | is( $bar->TWO, '...', 'accessor works for reading' ); |
43 | $bar->TWO('!!!'); |
44 | is( $bar->TWO, '!!!', 'accessor works for writing' ); |
45 | |
46 | done_testing; |