Subject: | SetOnce interacts badly with MooseX::Clone |
package Bug;
use Moose;
use MooseX::SetOnce;
with qw(MooseX::Clone);
has attr => (
is => 'rw',
traits => [ 'SetOnce' ],
);
no Moose;
my $bug = Bug->new();
$bug->attr(1);
my $bug2 = $bug->clone(attr => 2);
__END__
I tried to clone $bug, but with attr set to 2 instead of to 1.
Since I have not yet set the attribute on the clone, I should
be able to do this. But ->clone first copies the 1 and
then tries to set it to 2, producing:
cannot change value of SetOnce attribute at
/usr/local/share/perl/5.10.1/MooseX/SetOnce.pm line 16
MooseX::SetOnce::Attribute::_ensure_unset('Class::MOP::Class::__
ANON__::SERIAL::1=HASH(0xa3a8ac8)', 'Bug=HASH(0xa3a25c0)') called at
/usr/local/share/perl/5.10.1/MooseX/SetOnce.pm line 12
Class::MOP::Class:::before('Class::MOP::Class::__ANON__::SERIAL:
:1=HASH(0xa3a8ac8)', 'Bug=HASH(0xa3a25c0)', 2) called at
/usr/local/lib/perl/5.10.1/Class/MOP/Method/Wrapped.pm line 47
Class::MOP::Method::Wrapped::__ANON__('Class::MOP::Class::__ANON
__::SERIAL::1=HASH(0xa3a8ac8)', 'Bug=HASH(0xa3a25c0)', 2) called at
/usr/local/lib/perl/5.10.1/Class/MOP/Method/Wrapped.pm line 89
Class::MOP::Class::__ANON__::SERIAL::1::set_value('Class::MOP::C
lass::__ANON__::SERIAL::1=HASH(0xa3a8ac8)', 'Bug=HASH(0xa3a25c0)', 2)
called at /usr/local/lib/perl/5.10.1/Class/MOP/Class.pm line 682
Class::MOP::Class::_clone_instance('Moose::Meta::Class=HASH(0xa2
9c540)', 'Bug=HASH(0xa34add8)', 'attr', 2) called at
/usr/local/lib/perl/5.10.1/Class/MOP/Class.pm line 672
Class::MOP::Class::clone_object('Moose::Meta::Class=HASH(0xa29c5
40)', 'Bug=HASH(0xa34add8)', 'attr', 2) called at
/usr/local/share/perl/5.10.1/MooseX/Clone.pm line 40
MooseX::Clone::clone('Bug=HASH(0xa34add8)', 'attr', 2) called at
Bug2.pm line 16