Moose now warns when you try to load it from the main package. Added a
[gitmo/Moose.git] / t / 100_bugs / 010_immutable_n_default_x2.t
CommitLineData
51c107ef 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 2;
7
bad76b8e 8
51c107ef 9
10{
11 package Foo;
12 use Moose;
13
14 our $foo_default_called = 0;
15
16 has foo => (
17 is => 'rw',
18 isa => 'Str',
bad76b8e 19 default => sub { $foo_default_called++; 'foo' },
51c107ef 20 );
21
22 our $bar_default_called = 0;
23
24 has bar => (
25 is => 'rw',
26 isa => 'Str',
27 lazy => 1,
28 default => sub { $bar_default_called++; 'bar' },
29 );
30
31 __PACKAGE__->meta->make_immutable;
32}
33
34my $foo = Foo->new();
35
36is($Foo::foo_default_called, 1, "foo default was only called once during constructor");
37
38$foo->bar();
39
40is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");