Implement strict constructors, which will warn unkown constructor arguments
[gitmo/Mouse.git] / t / 100_bugs / 010_immutable_n_default_x2.t
CommitLineData
4c98ebb0 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 2;
7
8
9
10{
11 package Foo;
12 use Mouse;
13
14 our $foo_default_called = 0;
15
16 has foo => (
17 is => 'rw',
18 isa => 'Str',
19 default => sub { $foo_default_called++; 'foo' },
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");