Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / Clone / Meta / Attribute / Trait / NoClone.pm
CommitLineData
3fea05b9 1#!/usr/bin/perl
2
3package MooseX::Clone::Meta::Attribute::Trait::NoClone;
4use Moose::Role;
5
6use namespace::clean -except => [qw(meta)];
7
8with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Base);
9
10sub Moose::Meta::Attribute::Custom::Trait::NoClone::register_implementation { __PACKAGE__ }
11
12sub clone_value {
13 my ( $self, $target, $proto, %args ) = @_;
14
15 # FIXME default cloning behavior works like this
16 #if ( exists $args{init_arg} ) {
17 # $self->set_value($args{init_arg});
18 #} else {
19 # but i think this is more correct
20
21 $self->clear_value($target);
22 $self->initialize_instance_slot(
23 $self->meta->get_meta_instance,
24 $target,
25 { exists $args{init_arg} ? ( $self->init_arg => $args{init_arg} ) : () },
26 );
27}
28
29__PACKAGE__
30
31__END__
32
33=pod
34
35=head1 NAME
36
37MooseX::Clone::Meta::Attribute::Trait::NoClone - A trait for attrs that should
38not be copied while cloning.
39
40=head1 SYNOPSIS
41
42 with qw(MooseX::Clone);
43
44 has _some_special_thingy => (
45 traits => [qw(NoClone)],
46 );
47
48=head1 DESCRIPTION
49
50Sometimes certain values should not be carried over when cloning an object.
51
52This attribute trait implements just that.
53
54=head1 METHODS
55
56=over 4
57
58=item clone_value
59
60If the C<init_arg> param is set (that means an explicit value was given to
61C<clone>) sets the attribute to that value.
62
63Otherwise calls C<clear_value> and C<initialize_instance_slot>.
64
65=back
66
67=cut
68
69