summaryrefslogtreecommitdiff
path: root/t/bugs/immutable_n_default_x2.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/bugs/immutable_n_default_x2.t
downloadMoose-tarball-master.tar.gz
Diffstat (limited to 't/bugs/immutable_n_default_x2.t')
-rw-r--r--t/bugs/immutable_n_default_x2.t39
1 files changed, 39 insertions, 0 deletions
diff --git a/t/bugs/immutable_n_default_x2.t b/t/bugs/immutable_n_default_x2.t
new file mode 100644
index 0000000..2ba3e3b
--- /dev/null
+++ b/t/bugs/immutable_n_default_x2.t
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+
+{
+ package Foo;
+ use Moose;
+
+ 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");
+
+done_testing;