3 package MooseX::Clone::Meta::Attribute::Trait::Copy;
8 use namespace::clean -except => 'meta';
10 with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Base);
12 sub Moose::Meta::Attribute::Custom::Trait::Copy::register_implementation { __PACKAGE__ }
15 my ( $self, $target, $proto, %args ) = @_;
17 return unless $self->has_value($proto);
19 my $clone = exists $args{init_arg} ? $args{init_arg} : $self->_copy_ref($self->get_value($proto));
21 $self->set_value( $target, $clone );
25 my ( $self, $value ) = @_;
27 if ( not ref $value ) {
29 } elsif ( ref $value eq 'ARRAY' ) {
31 } elsif ( ref $value eq 'HASH' ) {
34 croak "The Copy trait is for arrays and hashes. Use the Clone trait for objects";
46 MooseX::Clone::Meta::Attribute::Trait::Copy - Simple copying of arrays and
47 hashes for L<MooseX::Clone>
58 Unlike the C<Clone> trait, which does deep copying of almost anything, this
59 trait will only do one additional level of copying of arrays and hashes.
61 This is both simpler and faster when you don't need a real deep copy of the
62 entire structure, and probably more correct.