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