Crypto/Role/ShallowClone.pm

filter: Statementstmt 92.0% 23 / 25 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 88.5% 31 / 35 CC 4 SCAR 9.3
CC
4
Cov
90%
clone
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« Crypto/Key/Public.pm ↑ Summary Crypto/Exception.pm »
1 package Bitcoin::Crypto::Role::ShallowClone;
2 64 $Bitcoin::Crypto::Role::ShallowClone::VERSION = '4.004';
3 64 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 64 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 64 ▶use Mooish::Base -standard, -role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Clones up to two levels deep - main reference and any plain hash / array
9 # references inside it
10 sub clone
11 {
12 374 ▶ my ($self) = @_;
Subroutine clone: called CC=4 SCAR=14.0
Pod undocumented
13  
14 374 my %new_self;
15 374 foreach my $key (keys %{$self}) {
16 1938 my $value = $self->{$key};
17 1938 my $ref = ref $value;
18  
19 1938 ▶ if ($ref eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 746 1192 1938
elsif ($ref eq 'HASH') { } 0 1192 1192
20 746 $new_self{$key} = [@{$value}];
21 }
22 elsif ($ref eq 'HASH') {
23 0 $new_self{$key} = {%{$value}};
24 }
25 else {
26 1192 $new_self{$key} = $value;
27 }
28 }
29  
30 # Don't use the constructor because not all state may be assignable this
31 # way
32 374 my $clone = bless \%new_self, ref $self;
33 374 $clone->_cloned;
34 374 return $clone;
35 }
36  
37 # overridable to modify after cloning
38 ▶sub _cloned { }
Subroutine _cloned: called CC=1 SCAR=0.0
39  
40 64 1;
41  
« Crypto/Key/Public.pm ↑ Summary Crypto/Exception.pm »