From: Florian Ragwitz Date: Fri, 13 May 2011 11:42:17 +0000 (+0200) Subject: Make instance cloning go through attribute setters X-Git-Tag: 2.0007~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f5ba01adb0d125db88ddd56448e8f21a68b8889;p=gitmo%2FMoose.git Make instance cloning go through attribute setters This way things like weakening will be taken care of. --- diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index 499cc25..de37d54 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -76,7 +76,14 @@ sub create_instance { sub clone_instance { my ($self, $instance) = @_; - bless { %$instance }, $self->_class_name; + + my $clone = bless {}, $self->_class_name; + for my $attr ($self->get_all_attributes) { + $attr->set_value($clone, $attr->get_raw_value($instance)) + if $attr->has_value($instance); + } + + return $clone; } # operations on meta instance