Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / Clone / Meta / Attribute / Trait / NoClone.pm
1 #!/usr/bin/perl
2
3 package MooseX::Clone::Meta::Attribute::Trait::NoClone;
4 use Moose::Role;
5
6 use namespace::clean -except => [qw(meta)];
7
8 with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Base);
9
10 sub Moose::Meta::Attribute::Custom::Trait::NoClone::register_implementation { __PACKAGE__ }
11
12 sub 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
37 MooseX::Clone::Meta::Attribute::Trait::NoClone - A trait for attrs that should
38 not 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
50 Sometimes certain values should not be carried over when cloning an object.
51
52 This attribute trait implements just that.
53
54 =head1 METHODS
55
56 =over 4
57
58 =item clone_value
59
60 If the C<init_arg> param is set (that means an explicit value was given to
61 C<clone>) sets the attribute to that value.
62
63 Otherwise calls C<clear_value> and C<initialize_instance_slot>.
64
65 =back
66
67 =cut
68
69