Picnic/Result/Search.pm

filter: Statementstmt 97.7% 43 / 44 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.2% 74 / 97 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 # ABSTRACT: Picnic search results collection
3 2 our $VERSION = '0.101';
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 extends 'WWW::Picnic::Result';
7  
8 2 ▶use WWW::Picnic::Result::SearchResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # Recursively find all sellingUnit objects in the response
12 30 ▶sub _find_selling_units {
Subroutine _find_selling_units: called CC=10 SCAR=23.1
13 30 my ($self, $data, $seen) = @_;
14 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
15 30 my @units;
16  
17 30 ▶ return @units unless ref $data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 13 17 30
18  
19 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
20 # Found a sellingUnit
21 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
22 2 my $unit = $data->{sellingUnit};
23 2 my $id = $unit->{id};
24 # Deduplicate by ID
25 2 ▶ unless ($seen->{$id}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen->{$id}++) 2 0 2
26 2 push @units, $unit;
27 }
28 }
29 # Recurse into hash values
30 12 for my $val (values %$data) {
31 25 push @units, $self->_find_selling_units($val, $seen);
32 }
33 }
34 elsif (ref $data eq 'ARRAY') {
35 # Recurse into array elements
36 5 for my $elem (@$data) {
37 4 push @units, $self->_find_selling_units($elem, $seen);
38 }
39 }
40  
41 17 return @units;
42 }
43  
44 has items => (
45 is => 'ro',
46 lazy => 1,
47 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 1 my $self = shift;
49 1 my @units = $self->_find_selling_units($self->raw);
50 1 return [ map { WWW::Picnic::Result::SearchResult->new($_) } @units ];
51 },
52 2 );
53  
54  
55 1 ▶sub all_items {
Subroutine all_items: called CC=1 SCAR=0.0
Pod documented
56 1 my ( $self ) = @_;
57 1 return @{ $self->items };
58 }
59  
60  
61 1 ▶sub total_count {
Subroutine total_count: called CC=1 SCAR=0.0
Pod documented
62 1 my ( $self ) = @_;
63 1 return scalar @{ $self->items };
64 }
65  
66  
67 1 ▶sub first_group_id {
Subroutine first_group_id: called CC=9 SCAR=27.8
Pod documented
68 1 my ( $self ) = @_;
69 1 my $raw = $self->raw;
70 # Try to extract from analytics context
71 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
72 1 my $analytics = $raw->{body}{child}{analytics};
73 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
74 1 for my $ctx (@{$analytics->{contexts}}) {
75 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
76 }
77 }
78 }
79 0 return;
80 }
81  
82  
83 2 1;
84  
85 __END__
↑ Summary Picnic/Result.pm »