Commit | Line | Data |
e8dc5201 |
1 | use strictures 1; |
2 | use Test::More; |
3 | use Test::Fatal; |
4 | |
5 | my $test = "test"; |
6 | my $lazy_default = "lazy_default"; |
7 | |
8 | { |
9 | package Foo; |
10 | |
11 | use Moo; |
12 | |
13 | has rwp => (is => 'rwp'); |
14 | has lazy => (is => 'lazy'); |
15 | sub _build_lazy { $test } |
16 | has lazy_default => (is => 'lazy', default => sub { $lazy_default }); |
17 | } |
18 | |
19 | my $foo = Foo->new; |
20 | |
21 | # rwp |
22 | { |
23 | is $foo->rwp, undef, "rwp value starts out undefined"; |
078250e3 |
24 | ok exception { $foo->rwp($test) }, "rwp is read_only"; |
e8dc5201 |
25 | is exception { $foo->_set_rwp($test) }, undef, "rwp can be set by writer"; |
26 | is $foo->rwp, $test, "rwp value was set by writer"; |
27 | } |
28 | |
29 | # lazy |
30 | { |
31 | is $foo->{lazy}, undef, "lazy value storage is undefined"; |
32 | is $foo->lazy, $test, "lazy value returns test value when called"; |
2bb6aaa3 |
33 | ok exception { $foo->lazy($test) }, "lazy is read_only"; |
e8dc5201 |
34 | } |
35 | |
36 | # lazy + default |
37 | { |
38 | is $foo->{lazy_default}, undef, "lazy_default value storage is undefined"; |
39 | is $foo->lazy_default, $lazy_default, "lazy_default value returns test value when called"; |
2bb6aaa3 |
40 | ok exception { $foo->lazy_default($test) }, "lazy_default is read_only"; |
e8dc5201 |
41 | } |
42 | |
43 | done_testing; |