| 1 | package App::Tel::Merge; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 7 | require Exporter; | |||||||||||||||||||||||||||
| 7 | 7 | our @ISA = qw/ Exporter /; | |||||||||||||||||||||||||||
| 8 | 7 | our @EXPORT_OK = qw/ merge /; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | App::Tel::Merge - simple hash merge | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # This was stoled from Hash::Merge::Simple, which stoled from Catalyst::Utils | ||||||||||||||||||||||||||||
| 18 | # I stole it because I wanted to get rid of the dependancy on Clone which | ||||||||||||||||||||||||||||
| 19 | # needs to be compiled by cpanm when we weren't using it. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head2 merge | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | my $merged = merge($left, @right); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Used to merge two hash references together. Returns a hashref. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub merge (@); ## no critic qw(Subroutines::ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||||
| 30 | 8 | ▶ | sub merge (@) { ## no critic qw(Subroutines::ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
merge: called CC=7 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 8 | ▶ | shift unless ref $_[0]; # Take care of the case we're called like Hash::Merge::Simple->merge(...) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 8 | my ($left, @right) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | return $left unless @right; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | return merge($left, merge(@right)) if @right > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 8 | my ($right) = @right; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 8 | my %merge = %$left; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | for my $key (keys %$right) { | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 22 | my ($hr, $hl) = map { ref $_->{$key} eq 'HASH' } $right, $left; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 22 | ▶ | if ($hr and $hl){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hr and $hl
MC/DC0%0/2
$hr and $hl
$hr
$hl
Truth table66%2/3
A and B
A= $hrB= $hl
| |||||||||||||||||||||||||||||
| 47 | 0 | $merge{$key} = merge($left->{$key}, $right->{$key}); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 22 | $merge{$key} = $right->{$key}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 8 | return \%merge; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||