| 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
| |||||||||||||||
| 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 | |||||||||||||||