Picnic/Result/Search.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 68.7% 11 / 16 Conditioncond 47.0% 8 / 17 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 76.5% 75 / 98 CC 18 SCAR 23.5
CC
18
Cov
81%
first_group_id
16.1
_find_selling_units
10.1
BEGIN
1.0
CRAP 10.5
↑ Summary Picnic/Result.pm »
1 package WWW::Picnic::Result::Search;
2 2 our $VERSION = '0.100';
3 2 our $AUTHORITY = 'cpan:GETTY';
4 # ABSTRACT: Picnic search results collection
5  
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 extends 'WWW::Picnic::Result';
9  
10 2 ▶use WWW::Picnic::Result::SearchResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 # Recursively find all sellingUnit objects in the response
14 sub _find_selling_units {
15 30 ▶ my ($self, $data, $seen) = @_;
Subroutine _find_selling_units: called CC=10 SCAR=23.1
16 30 ▶ $seen //= {};
Condition100%2/2
$seen //= {}
l!l
291
MC/DC100%1/1
$seen //= {}
$seen
Truth table100%2/2
A
A= $seen
Aresult
11
00
17 30 my @units;
18  
19 30 ▶ return @units unless ref $data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 13 17 30
20  
21 17 ▶ if (ref $data eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 12 5 17
elsif (ref $data eq 'ARRAY') { } 5 0 5
22 # Found a sellingUnit
23 12 ▶ if (exists $data->{sellingUnit} && ref $data->{sellingUnit} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"sellingUnit"} and ref $data->{"sellingUnit"} eq "HASH") 2 10 12
Condition66%2/3
exists $data->{"sellingUnit"} and ref $data->{"sellingUnit"} eq "HASH"
!ll&&!rl&&r
1002
MC/DC50%1/2
exists $data->{"sellingUnit"} and ref $data->{"sellingUnit"} eq "HASH"
exists $data->{"sellingUnit"} ref $data->{"sellingUnit"} eq "HASH"
Truth table66%2/3
A and B
A= exists $data->{"sellingUnit"}B= ref $data->{"sellingUnit"} eq "HASH"
ABresult
0X0
100
111
24 2 my $unit = $data->{sellingUnit};
25 2 my $id = $unit->{id};
26 # Deduplicate by ID
27 2 ▶ unless ($seen->{$id}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen->{$id}++) 2 0 2
28 2 push @units, $unit;
29 }
30 }
31 # Recurse into hash values
32 12 for my $val (values %$data) {
33 25 push @units, $self->_find_selling_units($val, $seen);
34 }
35 }
36 elsif (ref $data eq 'ARRAY') {
37 # Recurse into array elements
38 5 for my $elem (@$data) {
39 4 push @units, $self->_find_selling_units($elem, $seen);
40 }
41 }
42  
43 17 return @units;
44 }
45  
46 has items => (
47 is => 'ro',
48 lazy => 1,
49 default => sub {
50 1 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 my @units = $self->_find_selling_units($self->raw);
52 1 return [ map { WWW::Picnic::Result::SearchResult->new($_) } @units ];
53 },
54 2 );
55  
56  
57 sub all_items {
58 1 ▶ my ( $self ) = @_;
Subroutine all_items: called CC=1 SCAR=0.0
Pod documented
59 1 return @{ $self->items };
60 }
61  
62  
63 sub total_count {
64 1 ▶ my ( $self ) = @_;
Subroutine total_count: called CC=1 SCAR=0.0
Pod documented
65 1 return scalar @{ $self->items };
66 }
67  
68  
69 sub first_group_id {
70 1 ▶ my ( $self ) = @_;
Subroutine first_group_id: called CC=9 SCAR=27.8
Pod documented
71 1 my $raw = $self->raw;
72 # Try to extract from analytics context
73 1 ▶ if (ref $raw eq 'HASH' && $raw->{body} && $raw->{body}{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw eq "HASH" and $raw->{"body"} and $raw->{"body"}{"child"}) 1 0 1
Condition33%2/6
ref $raw eq "HASH" and $raw->{"body"} and $raw->{"body"}{"child"}
!ll&&!rl&&r
001
ref $raw eq "HASH" and $raw->{"body"}
!ll&&!rl&&r
001
MC/DC0%0/3
ref $raw eq "HASH" and $raw->{"body"} and $raw->{"body"}{"child"}
ref $raw eq "HASH" $raw->{"body"} $raw->{"body"}{"child"}
Truth table25%1/4
A and B and C
A= ref $raw eq "HASH"B= $raw->{"body"}C= $raw->{"body"}{"child"}
ABCresult
0XX0
10X0
1100
1111
74 1 my $analytics = $raw->{body}{child}{analytics};
75 1 ▶ if ($analytics && $analytics->{contexts}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($analytics and $analytics->{"contexts"}) 1 0 1
Condition33%1/3
$analytics and $analytics->{"contexts"}
!ll&&!rl&&r
001
MC/DC0%0/2
$analytics and $analytics->{"contexts"}
$analytics $analytics->{"contexts"}
Truth table33%1/3
A and B
A= $analyticsB= $analytics->{"contexts"}
ABresult
0X0
100
111
76 1 for my $ctx (@{$analytics->{contexts}}) {
77 1 ▶ return $ctx->{data}{main_entity} if $ctx->{data} && $ctx->{data}{main_entity};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"data"} and $ctx->{"data"}{"main_entity"} 1 0 1
Condition33%1/3
$ctx->{"data"} and $ctx->{"data"}{"main_entity"}
!ll&&!rl&&r
001
MC/DC0%0/2
$ctx->{"data"} and $ctx->{"data"}{"main_entity"}
$ctx->{"data"} $ctx->{"data"}{"main_entity"}
Truth table33%1/3
A and B
A= $ctx->{"data"}B= $ctx->{"data"}{"main_entity"}
ABresult
0X0
100
111
78 }
79 }
80 }
81 0 return;
82 }
83  
84  
85 2 1;
86  
87 __END__
↑ Summary Picnic/Result.pm »