| 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 //= {}
MC/DC100%1/1
$seen //= {}
$seen
Truth table100%2/2
A
A= $seen
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 30 | my @units; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 30 | ▶ | return @units unless ref $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | ▶ | if (ref $data eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Found a sellingUnit | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | if (exists $data->{sellingUnit} && ref $data->{sellingUnit} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $data->{"sellingUnit"} and ref $data->{"sellingUnit"} eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my $unit = $data->{sellingUnit}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my $id = $unit->{id}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | # Deduplicate by ID | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | unless ($seen->{$id}++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $raw eq "HASH" and $raw->{"body"} and $raw->{"body"}{"child"}
ref $raw eq "HASH" and $raw->{"body"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my $analytics = $raw->{body}{child}{analytics}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if ($analytics && $analytics->{contexts}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$analytics and $analytics->{"contexts"}
MC/DC0%0/2
$analytics and $analytics->{"contexts"}
$analytics
$analytics->{"contexts"}
Truth table33%1/3
A and B
A= $analyticsB= $analytics->{"contexts"}
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | for my $ctx (@{$analytics->{contexts}}) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | return $ctx->{data}{main_entity} if $ctx->{data} && $ctx->{data}{main_entity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ctx->{"data"} and $ctx->{"data"}{"main_entity"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||