Net/Z3950/FOLIO/lodashGet.pm

filter: Statementstmt 100% 38 / 38 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 96.6% 57 / 59 CC 8 SCAR 12.4
CC
8
Cov
98%
_compilePath
5.0
lodashGet
4.0
BEGIN
1.0
CRAP 3.5
« Net/Z3950/FOLIO/PostProcess/OPAC.pm ↑ Summary Net/Z3950/FOLIO/ResultSet.pm »
1 package Net::Z3950::FOLIO::lodashGet;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Data::Dumper; $Data::Dumper::INDENT = 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 27 ▶sub _compilePath {
Subroutine _compilePath: called CC=5 SCAR=16.1
9 27 my($path) = @_;
10 27 my @components;
11  
12 27 ▶ while ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 60 6 66
13 60 my @match = $path =~ /^([^.\[]*)(\.|\[\d+\]\.?)(.*)/;
14 60 ▶ if (!@match) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@match) 21 39 60
15 21 push @components, $path;
16 21 last;
17 }
18  
19 39 my($head, $sep, $tail) = @match;
20 39 ▶ push @components, $head if $head ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $head ne "" 38 1 39
21 39 ▶ if ($sep ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep ne ".") 11 28 39
22 11 $sep =~ s/\]\.?//;
23 11 push @components, substr($sep, 1) + 0;
24 }
25  
26 39 $path = $tail;
27 }
28  
29 27 return @components;
30 }
31  
32  
33 12 ▶sub lodashGet {
Subroutine lodashGet: called CC=4 SCAR=13.9
Pod undocumented
34 12 my($data, $path) = @_;
35 # warn "starting with ", Dumper($data);
36  
37 12 my @components = _compilePath($path);
38 12 ▶ while (@components) {
Branch: 1 branch
BranchTrueFalseTotal
if (@components) 34 12 46
39 34 my $component = shift @components;
40 34 ▶ if (ref $data eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 24 10 34
41 24 $data = $data->{$component};
42 } else {
43 # Assume it's an array
44 10 $data = $data->[$component];
45 }
46 # warn "moved down from '$component' to ", Dumper($data);
47 34 ▶ return undef if !defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 34 34
48 }
49  
50 # warn "got ", (defined $data ? "'$data'" : 'UNDEF');
51  
52 12 return $data;
53 }
54  
55  
56 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
57 3 our @EXPORT_OK = qw(_compilePath lodashGet);
58  
59  
60 3 1;
« Net/Z3950/FOLIO/PostProcess/OPAC.pm ↑ Summary Net/Z3950/FOLIO/ResultSet.pm »