Google/Filter.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 20 / 20 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 95.7% 68 / 71 CC 14 SCAR 18.7
CC
14
Cov
100%
mask_hash
10.0
mask
4.0
mask_array
2.0
CRAP 6.5
↑ Summary Google.pm »
1 package Data::Partial::Google::Filter;
2 2 our $VERSION = '0.02'; # VERSION
3 2 our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 has 'properties' => (
9 is => 'ro',
10 );
11  
12 63 ▶sub mask {
Subroutine mask: called CC=4 SCAR=13.9
Pod undocumented
13 63 my ($self, $thing) = @_;
14  
15 63 ▶ my $type = reftype $thing || '';
Condition100%2/2
builtin::reftype($thing) || ''
l!l
603
MC/DC100%1/1
builtin::reftype($thing) || ''
builtin::reftype($thing)
Truth table100%2/2
A
A= builtin::reftype($thing)
Aresult
11
00
16  
17 63 ▶ if ($type eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 10 53 63
elsif ($type eq 'HASH') { } 50 3 53
18 10 return $self->mask_array($thing);
19 } elsif ($type eq 'HASH') {
20 50 return $self->mask_hash($thing);
21 } else {
22 # If we're looking for properties on a thing with no internal structure,
23 # don't return it at all. So for example, if we have a/*/b, a might contain
24 # some scalars, we don't want them, we only want things that have bs.
25 3 return;
26 }
27 }
28  
29 50 ▶sub mask_hash {
Subroutine mask_hash: called CC=10 SCAR=23.0
Pod undocumented
30 50 my ($self, $hash) = @_;
31  
32 50 my $props = $self->properties;
33 50 my $out = {};
34  
35 50 for my $key (keys %$props) {
36 61 my $filter = $props->{$key};
37 61 ▶ if ($key eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq '*') { } 4 57 61
elsif (exists $hash->{$key}) { } 52 5 57
38 # For * go over all keys in the object, but only produce output keys if the
39 # mask returned something useful.
40 4 for my $hash_key (keys %$hash) {
41 11 ▶ my $masked = $filter ? $filter->mask($hash->{$hash_key}) : $hash->{$hash_key};
Branch: 1 branch
BranchTrueFalseTotal
$filter ? : 8 3 11
42 11 ▶ $out->{$hash_key} = $masked if defined $masked;
Branch: 1 branch
BranchTrueFalseTotal
if defined $masked 7 4 11
43 }
44 } elsif (exists $hash->{$key}) {
45 52 ▶ if ($filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) { } 19 33 52
46 19 my $masked = $filter->mask($hash->{$key});
47 19 ▶ $out->{$key} = $masked if defined $masked;
Branch: 1 branch
BranchTrueFalseTotal
if defined $masked 18 1 19
48 } else {
49 33 $out->{$key} = $hash->{$key};
50 }
51 }
52 }
53 50 ▶ return $out if keys %$out;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$out 45 5 50
54 5 return;
55 }
56  
57 10 ▶sub mask_array {
Subroutine mask_array: called CC=2 SCAR=6.9
Pod undocumented
58 10 my ($self, $array) = @_;
59  
60 10 my @out = map { $self->mask($_) } @$array;
61 10 ▶ return \@out if @out;
Branch: 1 branch
BranchTrueFalseTotal
if @out 8 2 10
62 2 return;
63 }
64  
65 2 1;
66  
67 __END__
↑ Summary Google.pm »