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