Subject: | predicate doesn't trigger builder when is => 'lazy' |
If an attribute is lazy its builder isn't triggered when its predicate
is invoked:
package Foo;
use Moo;
has 'lazy' => ( is => 'lazy', predicate => 1,);
has 'builder' => ( is => 'ro', predicate => 1, builder => 1,);
sub _build_lazy { return 1 };
sub _build_builder { return 1 };
my $x = Foo->new;
print "builder: ", $x->has_builder || 0, "\n";
print "lazy: ", $x->has_lazy || 0, "\n";
results in
builder: 1
lazy: 0
It may seem odd to have a predicate with a builder, but the two cases
should be consistent. I think that as builders ensure that an attribute
has a value, the predicate should always return true if a builder (lazy
or not) is present. Whether it should trigger a lazy builder is another
question.
Thanks,
Diab