line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
20
|
|
|
20
|
|
77928
|
use strict; |
|
20
|
|
|
|
|
57
|
|
|
20
|
|
|
|
|
668
|
|
2
|
20
|
|
|
20
|
|
116
|
use warnings; |
|
20
|
|
|
|
|
45
|
|
|
20
|
|
|
|
|
911
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::Client::ResultSet; |
4
|
|
|
|
|
|
|
# ABSTRACT: A Result Set |
5
|
|
|
|
|
|
|
$MetaCPAN::Client::ResultSet::VERSION = '2.029000'; |
6
|
20
|
|
|
20
|
|
716
|
use Moo; |
|
20
|
|
|
|
|
11412
|
|
|
20
|
|
|
|
|
144
|
|
7
|
20
|
|
|
20
|
|
8025
|
use Carp; |
|
20
|
|
|
|
|
58
|
|
|
20
|
|
|
|
|
1507
|
|
8
|
|
|
|
|
|
|
|
9
|
20
|
|
|
20
|
|
662
|
use MetaCPAN::Client::Types qw< ArrayRef >; |
|
20
|
|
|
|
|
47
|
|
|
20
|
|
|
|
|
3189
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has type => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => sub { |
14
|
|
|
|
|
|
|
croak 'Invalid type' unless |
15
|
|
|
|
|
|
|
grep { $_ eq $_[0] } qw
|
16
|
|
|
|
|
|
|
file module rating release mirror package>; |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
lazy => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# in case we're returning from a scrolled search |
22
|
|
|
|
|
|
|
has scroller => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => sub { |
25
|
20
|
|
|
20
|
|
10267
|
use Safe::Isa; |
|
20
|
|
|
|
|
10634
|
|
|
20
|
|
|
|
|
11882
|
|
26
|
|
|
|
|
|
|
$_[0]->$_isa('MetaCPAN::Client::Scroll') |
27
|
|
|
|
|
|
|
or croak 'scroller must be an MetaCPAN::Client::Scroll object'; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
predicate => 'has_scroller', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# in case we're returning from a fetch |
33
|
|
|
|
|
|
|
has items => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => ArrayRef, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has total => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return $self->has_scroller ? $self->scroller->total |
44
|
|
|
|
|
|
|
: scalar @{ $self->items }; |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has 'class' => ( |
49
|
|
|
|
|
|
|
is => 'ro', |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
builder => '_build_class', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub BUILDARGS { |
55
|
14
|
|
|
14
|
1
|
33753
|
my ( $class, %args ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
exists $args{scroller} or exists $args{items} |
58
|
14
|
50
|
66
|
|
|
84
|
or croak 'ResultSet must get either scroller or items'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
exists $args{scroller} and exists $args{items} |
61
|
14
|
50
|
66
|
|
|
116
|
and croak 'ResultSet must get either scroller or items, not both'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
exists $args{type} or exists $args{class} |
64
|
14
|
100
|
100
|
|
|
249
|
or croak 'Must pass either type or target class to ResultSet'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
exists $args{type} and exists $args{class} |
67
|
13
|
50
|
66
|
|
|
106
|
and croak 'Must pass either type or target class to ResultSet, not both'; |
68
|
|
|
|
|
|
|
|
69
|
13
|
|
|
|
|
254
|
return \%args; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
sub BUILD { |
72
|
12
|
|
|
12
|
1
|
147
|
my ( $self ) = @_; |
73
|
12
|
|
|
|
|
241
|
$self->class; # vifify and validate |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub next { |
77
|
62
|
|
|
62
|
1
|
33586
|
my $self = shift; |
78
|
|
|
|
|
|
|
my $result = $self->has_scroller ? $self->scroller->next |
79
|
62
|
100
|
|
|
|
307
|
: shift @{ $self->items }; |
|
29
|
|
|
|
|
69
|
|
80
|
|
|
|
|
|
|
|
81
|
62
|
100
|
|
|
|
171
|
defined $result or return; |
82
|
|
|
|
|
|
|
|
83
|
59
|
|
33
|
|
|
1050
|
return $self->class->new_from_request( $result->{'_source'} || $result->{'fields'} || $result ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub aggregations { |
87
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
0
|
return $self->has_scroller ? $self->scroller->aggregations : {}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _build_class { |
93
|
11
|
|
|
11
|
|
134
|
my $self = shift; |
94
|
11
|
|
|
|
|
220
|
return 'MetaCPAN::Client::' . ucfirst $self->type; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |