Commit | Line | Data |
8f333548 |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
4 | { |
5 | package Foo; |
6 | |
7 | use Class::Tiny; |
8 | |
9 | has one => ( |
10 | is => 'ro', lazy => 1, default => sub { 3 }, |
11 | predicate => 'has_one', clearer => 'clear_one' |
12 | ); |
13 | } |
14 | |
15 | my $foo = Foo->new; |
16 | |
17 | ok(!$foo->has_one, 'empty'); |
18 | is($foo->one, 3, 'lazy default'); |
19 | ok($foo->has_one, 'not empty now'); |
20 | is($foo->clear_one, 3, 'clearer returns value'); |
21 | ok(!$foo->has_one, 'clearer empties'); |
22 | is($foo->one, 3, 'default re-fired'); |
23 | ok($foo->has_one, 'not empty again'); |
24 | |
25 | done_testing; |