Commit | Line | Data |
51c107ef |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7ff56534 |
6 | use Test::More tests => 2; |
7 | |
bad76b8e |
8 | |
51c107ef |
9 | |
10 | { |
11 | package Foo; |
12 | use Moose; |
13 | |
14 | our $foo_default_called = 0; |
15 | |
16 | has foo => ( |
17 | is => 'rw', |
18 | isa => 'Str', |
bad76b8e |
19 | default => sub { $foo_default_called++; 'foo' }, |
51c107ef |
20 | ); |
21 | |
22 | our $bar_default_called = 0; |
23 | |
24 | has bar => ( |
25 | is => 'rw', |
26 | isa => 'Str', |
27 | lazy => 1, |
28 | default => sub { $bar_default_called++; 'bar' }, |
29 | ); |
30 | |
31 | __PACKAGE__->meta->make_immutable; |
32 | } |
33 | |
34 | my $foo = Foo->new(); |
35 | |
36 | is($Foo::foo_default_called, 1, "foo default was only called once during constructor"); |
37 | |
38 | $foo->bar(); |
39 | |
40 | is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed"); |