Crypto/Role/ShallowClone.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 88.2% 30 / 34 CC 4 SCAR 9.3
CC
4
Cov
89%
clone
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« Crypto/Script/Transaction.pm ↑ Summary Crypto/Exception.pm »
1 package Bitcoin::Crypto::Role::ShallowClone;
2 68 $Bitcoin::Crypto::Role::ShallowClone::VERSION = '4.006';
3 68 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 68 ▶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 501 ▶{
Subroutine clone: called CC=4 SCAR=14.0
Pod undocumented
12 501 my ($self) = @_;
13  
14 501 my %new_self;
15 501 foreach my $key (keys %{$self}) {
16 2560 my $value = $self->{$key};
17  
18 2560 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 946 1614 2560
elsif (ref $value eq 'HASH') { } 0 1614 1614
19 946 $new_self{$key} = [@{$value}];
20 }
21 elsif (ref $value eq 'HASH') {
22 0 $new_self{$key} = {%{$value}};
23 }
24 else {
25 1614 $new_self{$key} = $value;
26 }
27 }
28  
29 # Don't use the constructor because not all state may be assignable this
30 # way
31 501 my $clone = bless \%new_self, ref $self;
32 501 $clone->_cloned;
33 501 return $clone;
34 }
35  
36 # overridable to modify after cloning
37 474 ▶sub _cloned { }
Subroutine _cloned: called CC=1 SCAR=0.0
38  
39 68 1;
40  
« Crypto/Script/Transaction.pm ↑ Summary Crypto/Exception.pm »