| MooseX-Clone documentation | Contained in the MooseX-Clone distribution. |
MooseX::Clone::Meta::Attribute::Trait::NoClone - A trait for attrs that should not be copied while cloning.
with qw(MooseX::Clone);
has _some_special_thingy => (
traits => [qw(NoClone)],
);
Sometimes certain values should not be carried over when cloning an object.
This attribute trait implements just that.
If the init_arg param is set (that means an explicit value was given to
clone) sets the attribute to that value.
Otherwise calls clear_value and initialize_instance_slot.
| MooseX-Clone documentation | Contained in the MooseX-Clone distribution. |
#!/usr/bin/perl package MooseX::Clone::Meta::Attribute::Trait::NoClone; use Moose::Role; use namespace::clean -except => [qw(meta)]; with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Base); sub Moose::Meta::Attribute::Custom::Trait::NoClone::register_implementation { __PACKAGE__ } sub clone_value { my ( $self, $target, $proto, %args ) = @_; # FIXME default cloning behavior works like this #if ( exists $args{init_arg} ) { # $self->set_value($args{init_arg}); #} else { # but i think this is more correct $self->clear_value($target); $self->initialize_instance_slot( $self->meta->get_meta_instance, $target, { exists $args{init_arg} ? ( $self->init_arg => $args{init_arg} ) : () }, ); } __PACKAGE__ __END__