Subject: | Native trait initializing attribute |
Date: | Wed, 25 Oct 2017 22:44:56 +0000 |
To: | "bug-Moose [...] rt.cpan.org" <bug-Moose [...] rt.cpan.org> |
From: | Jose Luis Martínez Torres <joseluis.martinez [...] capside.com> |
Hi,
I've discovered this behaviour. I'm reporting it as a bug because it seemed strange:
#!/usr/bin/env perl
use Test::More;
package Test {
use Moose;
has prop => (is => 'ro', isa => 'HashRef', traits => [ 'Hash' ], handles => { count_prop => 'count' });
}
my $instance = Test->new;
ok(not(defined $instance->prop), 'prop is undefined');
$instance->count_prop;
ok(not(defined $instance->prop), 'prop is undefined');
prop gets initialized to a {} when count_prop is called, which is unexpected (it breaks later comparisions for "definedness")
Best Regards,
Jose Luis