as well. There will be 2 releases, and then it will
be removed.
+ * Moose::Meta::Method::Constructor
+ - immutable classes which had non-lazy attributes were calling
+ the default generating sub twice in the constructor. (bug
+ found by Jesse Luehrs, fixed by Dave Rolsky)
+ - added tests for this (Dave Rolsky)
+
0.40 Fri. March 14, 2008
- I hate Pod::Coverage
('$type_constraints[' . $index . ']'),
'$val'
) if ($is_moose && $attr->has_type_constraint);
- push @source => $self->_generate_slot_assignment($attr, $default, $index);
+ push @source => $self->_generate_slot_assignment($attr, '$val', $index);
push @source => '}'; # close - wrap this to avoid my $val overrite warnings
push @source => "}" if defined $attr->init_arg;
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+{
+ package Foo;
+ use Moose;
+
+ our $foo_default_called = 0;
+
+ has foo => (
+ is => 'rw',
+ isa => 'Str',
+ default => sub { use Devel::StackTrace; warn Devel::StackTrace->new;$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");