| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Picnic::Result::Search; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.100'; |
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Picnic search results collection |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'WWW::Picnic::Result'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1722
|
use WWW::Picnic::Result::SearchResult; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
1062
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Recursively find all sellingUnit objects in the response |
|
14
|
|
|
|
|
|
|
sub _find_selling_units { |
|
15
|
30
|
|
|
30
|
|
64
|
my ($self, $data, $seen) = @_; |
|
16
|
30
|
|
100
|
|
|
73
|
$seen //= {}; |
|
17
|
30
|
|
|
|
|
45
|
my @units; |
|
18
|
|
|
|
|
|
|
|
|
19
|
30
|
100
|
|
|
|
75
|
return @units unless ref $data; |
|
20
|
|
|
|
|
|
|
|
|
21
|
17
|
100
|
|
|
|
116
|
if (ref $data eq 'HASH') { |
|
|
|
50
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Found a sellingUnit |
|
23
|
12
|
100
|
66
|
|
|
42
|
if (exists $data->{sellingUnit} && ref $data->{sellingUnit} eq 'HASH') { |
|
24
|
2
|
|
|
|
|
5
|
my $unit = $data->{sellingUnit}; |
|
25
|
2
|
|
|
|
|
6
|
my $id = $unit->{id}; |
|
26
|
|
|
|
|
|
|
# Deduplicate by ID |
|
27
|
2
|
50
|
|
|
|
12
|
unless ($seen->{$id}++) { |
|
28
|
2
|
|
|
|
|
6
|
push @units, $unit; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
# Recurse into hash values |
|
32
|
12
|
|
|
|
|
49
|
for my $val (values %$data) { |
|
33
|
25
|
|
|
|
|
78
|
push @units, $self->_find_selling_units($val, $seen); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
elsif (ref $data eq 'ARRAY') { |
|
37
|
|
|
|
|
|
|
# Recurse into array elements |
|
38
|
5
|
|
|
|
|
13
|
for my $elem (@$data) { |
|
39
|
4
|
|
|
|
|
15
|
push @units, $self->_find_selling_units($elem, $seen); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
17
|
|
|
|
|
48
|
return @units; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has items => ( |
|
47
|
|
|
|
|
|
|
is => 'ro', |
|
48
|
|
|
|
|
|
|
lazy => 1, |
|
49
|
|
|
|
|
|
|
default => sub { |
|
50
|
|
|
|
|
|
|
my $self = shift; |
|
51
|
|
|
|
|
|
|
my @units = $self->_find_selling_units($self->raw); |
|
52
|
|
|
|
|
|
|
return [ map { WWW::Picnic::Result::SearchResult->new($_) } @units ]; |
|
53
|
|
|
|
|
|
|
}, |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub all_items { |
|
58
|
1
|
|
|
1
|
1
|
4
|
my ( $self ) = @_; |
|
59
|
1
|
|
|
|
|
3
|
return @{ $self->items }; |
|
|
1
|
|
|
|
|
37
|
|
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub total_count { |
|
64
|
1
|
|
|
1
|
1
|
720
|
my ( $self ) = @_; |
|
65
|
1
|
|
|
|
|
3
|
return scalar @{ $self->items }; |
|
|
1
|
|
|
|
|
39
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub first_group_id { |
|
70
|
1
|
|
|
1
|
1
|
9321
|
my ( $self ) = @_; |
|
71
|
1
|
|
|
|
|
24
|
my $raw = $self->raw; |
|
72
|
|
|
|
|
|
|
# Try to extract from analytics context |
|
73
|
1
|
50
|
33
|
|
|
19
|
if (ref $raw eq 'HASH' && $raw->{body} && $raw->{body}{child}) { |
|
|
|
|
33
|
|
|
|
|
|
74
|
1
|
|
|
|
|
5
|
my $analytics = $raw->{body}{child}{analytics}; |
|
75
|
1
|
50
|
33
|
|
|
8
|
if ($analytics && $analytics->{contexts}) { |
|
76
|
1
|
|
|
|
|
2
|
for my $ctx (@{$analytics->{contexts}}) { |
|
|
1
|
|
|
|
|
4
|
|
|
77
|
1
|
50
|
33
|
|
|
16
|
return $ctx->{data}{main_entity} if $ctx->{data} && $ctx->{data}{main_entity}; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
|
|
|
|
|
return; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |