My Moo based class has both lazy & non-lazy attributes which have both default
and coerce
subs. If I don't initialize the attributes I'm finding that both default
and coerce
subs are called for the normal attribute, but only default
is called for the lazy attribute. That seems inconsistent. Here's sample code:
package Foo;
use Moo;
has nrml => ( is => 'ro',
default => sub { print "nrml default\n" },
coerce => sub { print "nrml coerce\n" }
);
has lazy => ( is => 'ro',
lazy => 1,
default => sub { print "lazy default\n" },
coerce => sub { print "lazy coerce\n" }
);
my $q = Foo->new( );
$q->lazy;
The output is:
nrml default
nrml coerce
lazy default
I only expect coerce
to run if I provide a value in the constructor. More importantly I expect the same sequence of execution (either default
or default
and coerce
) from both lazy and normal attributes.
So, are my expectations off, is this a bug, or what? Thanks!