moving stuff around a bit
[gitmo/Moose.git] / t / 100_bugs / 010_immutable_n_default_x2.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3;
7
8 BEGIN {
9     use_ok('Moose');
10 }
11
12 {
13     package Foo;
14     use Moose;
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");