Subject: | asserter checks for truth not definedness |
Method::Generate::Accessor generates an asserter using logic similar to
do { _generate_get() } || die. This is problematic when generating
delegations, as it fails for non true (but valid) values. I've provided
a simple test exercising this bug, which outputs
Attempted to access '_string' but it is not set at (eval 15) line 4.
the problem code areas are from what I can tell
https://metacpan.org/source/MSTROUT/Moo-1.000008/lib/Method/Generate/Accessor.pm#L166
https://metacpan.org/source/MSTROUT/Moo-1.000008/lib/Method/Generate/Accessor.pm#L511
Subject: | test.pl |
package Bar;
sub foo {
die;
print ${$_[0]};
}
package Foo;
use Moo;
has _string => (
is => 'rw',
default => sub { 0 },
handles => { bar => '${\\Bar->can("foo")}' },
clearer => '_clear_string',
);
package main;
my $f = Foo->new();
$f->_string;
$f->bar;