blib/lib/Sereal/Dclone.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 95.0% 38 / 40 SCAR 11.0
CC
3
Cov
97%
dclone
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package Sereal::Dclone;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Sereal::Decoder 'sereal_decode_with_object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Sereal::Encoder 'sereal_encode_with_object';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.002';
10  
11 1 our @EXPORT_OK = 'dclone';
12  
13 1 my $decoder = Sereal::Decoder->new;
14 1 my $encoder = Sereal::Encoder->new({freeze_callbacks => 1, no_shared_hashkeys => 1});
15  
16 sub dclone {
17 12 ▶ my ($input, $options) = @_;
Subroutine dclone: called CC=3 SCAR=11.0
Pod documented
18 12 my $enc;
19 12 ▶ if ($options and keys %$options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options and keys %$options) { } 3 9 12
Condition66%2/3
$options and keys %$options
!ll&&!rl&&r
903
MC/DC50%1/2
$options and keys %$options
$options keys %$options
Truth table66%2/3
A and B
A= $optionsB= keys %$options
ABresult
0X0
100
111
20 3 $enc = Sereal::Encoder->new({freeze_callbacks => 1, no_shared_hashkeys => 1, %$options});
21 } else {
22 9 $enc = $encoder;
23 }
24 12 return sereal_decode_with_object $decoder, sereal_encode_with_object $enc, $input;
25 }
26  
27 1 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<Sereal::Dclone> provides a L</"dclone"> function modeled after the function
41 from L<Storable>, using L<Sereal> for fast serialization.
42  
43 L<Sereal> is presently known to support serializing C<SCALAR>, C<ARRAY>,
44 C<HASH>, C<REF>, and C<Regexp> references. L<Sereal> will also serialize and
45 recreate blessed objects, provided the underlying reference type is supported,
46 or the object class provides C<FREEZE> and C<THAW> serialization methods
47 (L<Sereal::Encoder/"FREEZE/THAW CALLBACK MECHANISM">). 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<Sereal::Dclone> 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<Sereal>. Unlike L<Storable>'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<Sereal::Encoder> object in an
66 optional hash reference. To prevent exceptions when serializing unsupported
67 values, the C<undef_unknown> or C<stringify_unknown> options may be useful. The
68 C<croak_on_bless> or C<no_bless_objects> options can be used to control cloning
69 of objects. C<freeze_callbacks> 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 <dbook@cpan.org>
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<Storable>, L<Sereal>
↑ Summary