3 package MooseX::Clone::Meta::Attribute::Trait::StrableClone;
8 use namespace::clean -except => 'meta';
10 with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Std);
12 sub Moose::Meta::Attribute::Custom::Trait::StorableClone::register_implementation { __PACKAGE__ }
14 sub clone_value_data {
15 my ( $self, $value, @args ) = @_;
19 return Storable::dclone($value);
35 MooseX::Clone::Meta::Attribute::Trait::StorableClone - The L<Moose::Meta::Attribute>
36 trait for deeply cloning attributes using L<Storable>.
43 traits => [qw(StorableClone)],
47 my $clone = $object->clone; # $clone->foo will equal Storable::dclone($object->foo)
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.
57 Deriving this role for your own cloning purposes is encouraged.
59 This will allow your fine grained cloning semantics to interact with
60 L<MooseX::Clone> in the Rightâ„¢ way.
66 =item clone_only_objects
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>.
71 If true then non object values will be copied over in shallow cloning semantics
74 Defaults to false (all reference will be cloned).
76 =item clone_visitor_config
78 A hash ref used to construct C<clone_visitor>. Defaults to the empty ref.
80 This can be used to alter the cloning behavior for non object values.
84 The L<Data::Visitor::Callback> object that will be used to clone.
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
90 Only used if C<clone_only_objects> is false and the value of the attribute is
99 =item clone_value $target, $proto, %args
101 Clones the value the attribute encapsulates from C<$proto> into C<$target>.
103 =item clone_value_data $value, %args
105 Does the actual cloning of the value data by delegating to a C<clone> method on
108 If the object does not support a C<clone> method an error is thrown.
110 If the value is not an object then it will not be cloned.
112 In the future support for deep cloning of simple refs will be added too.
114 =item clone_object_value $object, %args
116 This is the actual workhorse of C<clone_value_data>.
118 =item clone_any_value $value, %args
120 Uses C<clone_visitor> to clone all non object values.
122 Called from C<clone_value_data> if the value is not an object and
123 C<clone_only_objects> is false.