Commit | Line | Data |
4c98ebb0 |
1 | #!/usr/bin/perl |
fde8e43f |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
4c98ebb0 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
fde8e43f |
9 | use Test::More; |
4c98ebb0 |
10 | |
11 | |
12 | { |
13 | package Foo; |
14 | use Mouse; |
15 | |
16 | our $foo_default_called = 0; |
17 | |
18 | has foo => ( |
19 | is => 'rw', |
20 | isa => 'Str', |
21 | default => sub { $foo_default_called++; 'foo' }, |
22 | ); |
23 | |
24 | our $bar_default_called = 0; |
25 | |
26 | has bar => ( |
27 | is => 'rw', |
28 | isa => 'Str', |
29 | lazy => 1, |
30 | default => sub { $bar_default_called++; 'bar' }, |
31 | ); |
32 | |
33 | __PACKAGE__->meta->make_immutable; |
34 | } |
35 | |
36 | my $foo = Foo->new(); |
37 | |
38 | is($Foo::foo_default_called, 1, "foo default was only called once during constructor"); |
39 | |
40 | $foo->bar(); |
41 | |
42 | is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed"); |
fde8e43f |
43 | |
44 | done_testing; |