X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100_bugs%2F010_immutable_n_default_x2.t;fp=t%2F100_bugs%2F010_immutable_n_default_x2.t;h=72f64933a49f19e1ff8c0493f118bf371efa1027;hb=4c98ebb0cca8d5d49d3a91eaf735f9861d00ccb0;hp=0000000000000000000000000000000000000000;hpb=ad20156284763b7d6019af2279f24e1af097f3be;p=gitmo%2FMouse.git diff --git a/t/100_bugs/010_immutable_n_default_x2.t b/t/100_bugs/010_immutable_n_default_x2.t new file mode 100644 index 0000000..72f6493 --- /dev/null +++ b/t/100_bugs/010_immutable_n_default_x2.t @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + + + +{ + package Foo; + use Mouse; + + our $foo_default_called = 0; + + has foo => ( + is => 'rw', + isa => 'Str', + default => sub { $foo_default_called++; 'foo' }, + ); + + our $bar_default_called = 0; + + has bar => ( + is => 'rw', + isa => 'Str', + lazy => 1, + default => sub { $bar_default_called++; 'bar' }, + ); + + __PACKAGE__->meta->make_immutable; +} + +my $foo = Foo->new(); + +is($Foo::foo_default_called, 1, "foo default was only called once during constructor"); + +$foo->bar(); + +is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");