Skip Alien-Ditaa
[gitmo/Moose.git] / t / bugs / immutable_n_default_x2.t
CommitLineData
51c107ef 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
bad76b8e 7
51c107ef 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',
bad76b8e 18 default => sub { $foo_default_called++; 'foo' },
51c107ef 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
33my $foo = Foo->new();
34
35is($Foo::foo_default_called, 1, "foo default was only called once during constructor");
36
37$foo->bar();
38
39is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");
a28e50e4 40
41done_testing;