some doc cleanup
[gitmo/Moose.git] / t / 100_bugs / 010_immutable_n_default_x2.t
CommitLineData
51c107ef 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
bad76b8e 6use Test::More tests => 3;
7
8BEGIN {
9 use_ok('Moose');
10}
51c107ef 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',
bad76b8e 21 default => sub { $foo_default_called++; 'foo' },
51c107ef 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
36my $foo = Foo->new();
37
38is($Foo::foo_default_called, 1, "foo default was only called once during constructor");
39
40$foo->bar();
41
42is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");