Skip Menu |

This queue is for tickets about the MooX-LazierAttributes CPAN distribution.

Report information
The Basics
Id: 120575
Status: resolved
Priority: 0/
Queue: MooX-LazierAttributes

People
Owner: Nobody in particular
Requestors: haarg [...] haarg.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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;
Attempting to _clone the reference within the default sub. Your failing test now passes. Thanks again. On Fri Mar 10 04:41:45 2017, haarg wrote: Show quoted text
> 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.