Subject: | Reference defaults handled badly |
When using references as defaults, they will be shared between all instances of an object. This is why Moo does not allow defaults to be specified that way.
Moo will already handle non-reference defaults, so the only thing MooX::LazierAttributes handling of defaults does is encourage broken usage.
If you do want to allow specifying reference defaults the way you show in the docs, the default sub would need to create a clone of it rather than using it directly.
Failing test attached.
Subject: | moox-lazierattributes-ref-defaults.t |
use strict;
use warnings;
use Test::More;
{
package Foo;
use Moo;
use MooX::LazierAttributes;
attributes (
foo => ['ro', {}],
);
}
my $o1 = Foo->new;
my $o2 = Foo->new;
$o1->foo->{foo} = 219;
is $o2->foo->{foo}, undef;
done_testing;