line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sereal::Dclone; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13965
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
3
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
3
|
use Sereal::Decoder 'sereal_decode_with_object'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
7
|
1
|
|
|
1
|
|
4
|
use Sereal::Encoder 'sereal_encode_with_object'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
181
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = 'dclone'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $decoder = Sereal::Decoder->new; |
14
|
|
|
|
|
|
|
my $encoder = Sereal::Encoder->new({freeze_callbacks => 1, no_shared_hashkeys => 1}); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub dclone { |
17
|
12
|
|
|
12
|
1
|
13216
|
my ($input, $options) = @_; |
18
|
12
|
|
|
|
|
11
|
my $enc; |
19
|
12
|
100
|
66
|
|
|
55
|
if ($options and keys %$options) { |
20
|
3
|
|
|
|
|
28
|
$enc = Sereal::Encoder->new({freeze_callbacks => 1, no_shared_hashkeys => 1, %$options}); |
21
|
|
|
|
|
|
|
} else { |
22
|
9
|
|
|
|
|
9
|
$enc = $encoder; |
23
|
|
|
|
|
|
|
} |
24
|
12
|
|
|
|
|
224
|
return sereal_decode_with_object $decoder, sereal_encode_with_object $enc, $input; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Sereal::Dclone - Deep (recursive) cloning via Sereal |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Sereal::Dclone 'dclone'; |
36
|
|
|
|
|
|
|
my $cloned = dclone $ref; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
L provides a L"dclone"> function modeled after the function |
41
|
|
|
|
|
|
|
from L, using L for fast serialization. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
L is presently known to support serializing C, C, |
44
|
|
|
|
|
|
|
C, C[, and C references. L will also serialize and ] |
45
|
|
|
|
|
|
|
recreate blessed objects, provided the underlying reference type is supported, |
46
|
|
|
|
|
|
|
or the object class provides C and C serialization methods |
47
|
|
|
|
|
|
|
(L). Be cautious with cloned |
48
|
|
|
|
|
|
|
objects as only the internal data structure is cloned, and the destructor will |
49
|
|
|
|
|
|
|
still be called when it is destroyed. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 FUNCTIONS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
L provides one function, which is exported on demand. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 dclone |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $cloned = dclone $ref; |
58
|
|
|
|
|
|
|
my $cloned = dclone $ref, {undef_unknown => 1, warn_unknown => 1}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Recursively clones a referenced data structure by serializing and then |
61
|
|
|
|
|
|
|
deserializing it with L. Unlike L's dclone, the argument can |
62
|
|
|
|
|
|
|
be any serializable scalar, not just a reference. If an unsupported value is |
63
|
|
|
|
|
|
|
encountered, an exception will be thrown as it cannot be cloned. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Options can be passed to the underlying L object in an |
66
|
|
|
|
|
|
|
optional hash reference. To prevent exceptions when serializing unsupported |
67
|
|
|
|
|
|
|
values, the C or C options may be useful. The |
68
|
|
|
|
|
|
|
C or C options can be used to control cloning |
69
|
|
|
|
|
|
|
of objects. C is enabled by default. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 BUGS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Dan Book |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Dan Book. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is free software, licensed under: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SEE ALSO |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L, L |