From: Stevan Little Date: Tue, 21 Feb 2006 02:51:28 +0000 (+0000) Subject: 0.11 release X-Git-Tag: 0_12~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=19d4b5b84fffff46f1b46f7dae5966fea399d003;p=gitmo%2FClass-MOP.git 0.11 release --- diff --git a/Changes b/Changes index 3938ebc..3e520d1 100644 --- a/Changes +++ b/Changes @@ -5,9 +5,8 @@ Revision history for Perl extension Class-MOP. - added example of changing method dispatch order to C3 * Class::MOP::Class - - changed how clone_instance behaves, it now goes through - each attribute and does what is appropriate (see docs - for a more detailed description) + - changed how clone_instance behaves, it now only does a + shallow clone (see docs for more details) - added docs and tests 0.10 Tues Feb. 14, 2006 diff --git a/README b/README index 9d550bc..6c09b50 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Class::MOP version 0.10 +Class::MOP version 0.11 =========================== See the individual module documentation for more information diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 2d57710..a6514cd 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -181,42 +181,7 @@ sub clone_instance { my ($class, $instance, %params) = @_; (blessed($instance)) || confess "You can only clone instances, \$self is not a blessed instance"; - # NOTE: - # This will deep clone, which might - # not be what you always want. So - # the best thing is to write a more - # controled &clone method locally - # in the class (see Class::MOP) - my $clone = {}; - foreach my $attr ($class->compute_all_applicable_attributes()) { - my $init_arg = $attr->init_arg(); - # try to fetch the init arg from the %params ... - # (no sense in cloning if we are overriding it) - if (exists $params{$init_arg}) { - $clone->{$attr->name} = $params{$init_arg} - } - else { - # if it is an object ... - if (blessed($instance->{$attr->name})) { - # see if it has a clone method ... - if ($instance->{$attr->name}->can('clone')) { - # if so ,.. call it - $clone->{$attr->name} = $instance->{$attr->name}->clone(); - } - # otherwise we assume that it does - # not wish to be cloned, and just - # copy the reference ... - else { - $clone->{$attr->name} = $instance->{$attr->name}; - } - } - # if it is not an object, then we - # deep clone it ... - else { - $clone->{$attr->name} = Clone::clone($instance->{$attr->name}); - } - } - } + my $clone = { %$instance, %params }; return $clone; } @@ -662,8 +627,10 @@ attribute meta-object. =item B This is a convience method for cloning an object instance, then -blessing it into the appropriate package. Ideally your class -would call a C this method like so: +blessing it into the appropriate package. This method will call +C, which performs a shallow copy of the object, +see that methods documentation for more details. Ideally your +class would call a C this method like so: sub MyClass::clone { my ($self, %param) = @_; @@ -676,23 +643,21 @@ but that is considered bad style, so we do not do that. =item B This method is a compliment of C (which means if -you override C, you need to override this one too). -This method will clone the C<$instance> structure in the following -way: - -If the attribute name is in C<%params> it will use that, otherwise it -will attempt to clone the value in that slot. If the value is C -then it will look for a C method. If a C method is found, -then it is called and the return value is added to the clone. If a -C method is B found, then we will respect the object's -encapsulation and not clone it, and just copy the object's pointer. If -the value is not C, then it will be deep-copied using L. +you override C, you need to override this one too), +and clones the instance shallowly. The cloned structure returned is (like with C) an unCed HASH reference, it is your responsibility to then bless this cloned structure into the right class (which C will do for you). +As of 0.11, this method will clone the C<$instance> structure shallowly, +as opposed to the deep cloning implemented in prior versions. After much +thought, research and discussion, I have decided that anything but basic +shallow cloning is outside the scope of the meta-object protocol. I +think Yuval "nothingmuch" Kogman put it best when he said that cloning +is too I to be part of the MOP. + =back =head2 Informational