Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / Clone / Meta / Attribute / Trait / StorableClone.pm
1 #!/usr/bin/perl
2
3 package MooseX::Clone::Meta::Attribute::Trait::StrableClone;
4 use Moose::Role;
5
6 use Carp qw(croak);
7
8 use namespace::clean -except => 'meta';
9
10 with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Std);
11
12 sub Moose::Meta::Attribute::Custom::Trait::StorableClone::register_implementation { __PACKAGE__ }
13
14 sub clone_value_data {
15     my ( $self, $value, @args ) = @_;
16
17     if ( ref($value) ) {
18         require Storable;
19         return Storable::dclone($value);
20     } else {
21         return $value;
22     }
23 }
24
25 __PACKAGE__
26
27 __END__
28
29 =pod
30
31 =encoding utf8
32
33 =head1 NAME
34
35 MooseX::Clone::Meta::Attribute::Trait::StorableClone - The L<Moose::Meta::Attribute>
36 trait for deeply cloning attributes using L<Storable>.
37
38 =head1 SYNOPSIS
39
40     # see MooseX::Clone
41
42     has foo => (
43         traits => [qw(StorableClone)],
44         isa => "Something",
45     );
46
47     my $clone = $object->clone; # $clone->foo will equal Storable::dclone($object->foo)
48
49 =head1 DESCRIPTION
50
51 This meta attribute trait provides a C<clone_value> method, in the spirit of
52 C<get_value> and C<set_value>. This allows clone methods such as the one in
53 L<MooseX::Clone> to make use of this per-attribute cloning behavior.
54
55 =head1 DERIVATION
56
57 Deriving this role for your own cloning purposes is encouraged.
58
59 This will allow your fine grained cloning semantics to interact with
60 L<MooseX::Clone> in the Rightâ„¢ way.
61
62 =head1 ATTRIBUTES
63
64 =over 4
65
66 =item clone_only_objects
67
68 Whether or not L<Data::Visitor> should be used to clone arbitrary structures.
69 Objects found in these structures will be cloned using L<clone_object_value>.
70
71 If true then non object values will be copied over in shallow cloning semantics
72 (shared reference).
73
74 Defaults to false (all reference will be cloned).
75
76 =item clone_visitor_config
77
78 A hash ref used to construct C<clone_visitor>. Defaults to the empty ref.
79
80 This can be used to alter the cloning behavior for non object values.
81
82 =item clone_visitor
83
84 The L<Data::Visitor::Callback> object that will be used to clone.
85
86 It has an C<object> handler that delegates to C<clone_object_value> and sets
87 C<tied_as_objects> to true in order to deeply clone tied structures while
88 retaining magic.
89
90 Only used if C<clone_only_objects> is false and the value of the attribute is
91 not an object.
92
93 =back
94
95 =head1 METHODS
96
97 =over 4
98
99 =item clone_value $target, $proto, %args
100
101 Clones the value the attribute encapsulates from C<$proto> into C<$target>.
102
103 =item clone_value_data $value, %args
104
105 Does the actual cloning of the value data by delegating to a C<clone> method on
106 the object if any.
107
108 If the object does not support a C<clone> method an error is thrown.
109
110 If the value is not an object then it will not be cloned.
111
112 In the future support for deep cloning of simple refs will be added too.
113
114 =item clone_object_value $object, %args
115
116 This is the actual workhorse of C<clone_value_data>.
117
118 =item clone_any_value $value, %args
119
120 Uses C<clone_visitor> to clone all non object values.
121
122 Called from C<clone_value_data> if the value is not an object and
123 C<clone_only_objects> is false.
124
125 =back
126
127 =cut