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.005';
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 386 ▶{
Subroutine clone: called CC=4 SCAR=14.0
Pod undocumented
12 386 my ($self) = @_;
13  
14 386 my %new_self;
15 386 foreach my $key (keys %{$self}) {
16 2002 my $value = $self->{$key};
17 2002 my $ref = ref $value;
18  
19 2002 ▶ if ($ref eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 770 1232 2002
elsif ($ref eq 'HASH') { } 0 1232 1232
20 770 $new_self{$key} = [@{$value}];
21 }
22 elsif ($ref eq 'HASH') {
23 0 $new_self{$key} = {%{$value}};
24 }
25 else {
26 1232 $new_self{$key} = $value;
27 }
28 }
29  
30 # Don't use the constructor because not all state may be assignable this
31 # way
32 386 my $clone = bless \%new_self, ref $self;
33 386 $clone->_cloned;
34 386 return $clone;
35 }
36  
37 # overridable to modify after cloning
38 386 ▶sub _cloned { }
Subroutine _cloned: called CC=1 SCAR=0.0
39  
40 64 1;
41  
« Crypto/Key/Public.pm ↑ Summary Crypto/Exception.pm »