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