| 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) || ''
MC/DC100%1/1
builtin::reftype($thing) || ''
builtin::reftype($thing)
Truth table100%2/2
A
A= builtin::reftype($thing)
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 63 | ▶ | if ($type eq 'ARRAY') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 42 | 11 | ▶ | $out->{$hash_key} = $masked if defined $masked; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | } | ||||||||||||||
| 44 | } elsif (exists $hash->{$key}) { | ||||||||||||||
| 45 | 52 | ▶ | if ($filter) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 19 | my $masked = $filter->mask($hash->{$key}); | |||||||||||||
| 47 | 19 | ▶ | $out->{$key} = $masked if defined $masked; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | } else { | ||||||||||||||
| 49 | 33 | $out->{$key} = $hash->{$key}; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | } | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | 50 | ▶ | return $out if keys %$out; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 62 | 2 | return; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 2 | 1; | |||||||||||||
| 66 | |||||||||||||||
| 67 | __END__ | ||||||||||||||