Subject: | Generated "is_" methods don't trigger lazy attributes' builders |
Calling the generated "is_$value" methods on the object does not appear to trigger the builder method when the underlying attribute is both lazy and unset.
Code that illustrates this:
package Stoplight;
use Moose;
use Moose::Util::TypeConstraints;
use MooseX::Enumeration;
enum 'StoplightColor', [qw(
red
yellow
green
) ];
has 'color' => (
is => 'ro',
isa => 'StoplightColor',
traits => [ 'Enumeration' ],
handles => 1,
lazy_build => 1,
);
sub _build_color {
return 'green';
}
package main;
my $stoplight = Stoplight->new;
sub go_status {
my ( $stoplight ) = @_;
return "Are we good to go? " . ( $stoplight->is_green? "Yes!\n" : "No.\n" );
}
# I'd expect calling the "is" method to act like an ordinary Moose read-
# accessor, triggering the lazy attribute's build method. But it doesn't.
print go_status( $stoplight );
# Now we'll try it again, calling that ordinary read-accessor first.
$stoplight->color;
print go_status( $stoplight );