lib/App/Tel/Merge.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 50.0% 4 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 79.4% 31 / 39 CC 7 SCAR 18.3
CC
7
Cov
82%
merge
7.8
BEGIN
1.0
BEGIN
1.0
CRAP 6.3
« lib/App/Tel/Passwd/PWSafe.pm ↑ Summary lib/App/Tel/Color/Cisco.pm »
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
BranchTrueFalseTotal
unless ref $_[0] 0 8 8
32 8 my ($left, @right) = @_;
33  
34 8 ▶ return $left unless @right;
Branch: 1 branch
BranchTrueFalseTotal
unless @right 0 8 8
35  
36 8 ▶ return merge($left, merge(@right)) if @right > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @right > 1 0 8 8
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
BranchTrueFalseTotal
if ($hr and $hl) { } 0 22 22
Condition66%2/3
$hr and $hl
!ll&&!rl&&r
1930
MC/DC0%0/2
$hr and $hl
$hr $hl
Truth table66%2/3
A and B
A= $hrB= $hl
ABresult
0X0
100
111
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  
« lib/App/Tel/Passwd/PWSafe.pm ↑ Summary lib/App/Tel/Color/Cisco.pm »