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'} |
0d931f8a |
19 | |
20 | has two => ( |
21 | is => 'lazy', |
22 | default => sub { 2 }, |
23 | reader => 'get_two', |
24 | ); |
25 | |
26 | has three => ( |
27 | is => 'rwp', |
28 | reader => 'get_three', |
29 | writer => 'set_three', |
30 | ); |
68a51c00 |
31 | } |
32 | |
33 | { |
34 | package Bar; |
35 | |
36 | use Moo; |
37 | |
38 | has two => ( |
39 | is => 'rw', |
40 | accessor => 'TWO', |
41 | ); |
42 | } |
43 | |
44 | my $foo = Foo->new(one => 'lol'); |
45 | my $bar = Bar->new(two => '...'); |
46 | |
47 | is( $foo->get_one, 'lol', 'reader works' ); |
48 | $foo->set_one('rofl'); |
49 | is( $foo->get_one, 'rofl', 'writer works' ); |
b1a9585f |
50 | is( $foo->one, 'sub', 'reader+writer = no accessor' ); |
68a51c00 |
51 | |
0d931f8a |
52 | is( $foo->get_two, 2, 'lazy doesn\'t override reader' ); |
53 | |
54 | is( $foo->can('two'), undef, 'reader+ro = no accessor' ); |
55 | |
56 | ok( $foo->can('get_three'), 'rwp doesn\'t override reader'); |
57 | ok( $foo->can('set_three'), 'rwp doesn\'t override writer'); |
58 | |
204ca0d3 |
59 | ok( exception { $foo->get_one('blah') }, 'reader dies on write' ); |
33d35735 |
60 | |
68a51c00 |
61 | is( $bar->TWO, '...', 'accessor works for reading' ); |
62 | $bar->TWO('!!!'); |
63 | is( $bar->TWO, '!!!', 'accessor works for writing' ); |
64 | |
65 | done_testing; |