line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
20
|
|
|
20
|
|
60802
|
use strict; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
535
|
|
2
|
20
|
|
|
20
|
|
89
|
use warnings; |
|
20
|
|
|
|
|
51
|
|
|
20
|
|
|
|
|
765
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::Client::ResultSet; |
4
|
|
|
|
|
|
|
# ABSTRACT: A Result Set |
5
|
|
|
|
|
|
|
$MetaCPAN::Client::ResultSet::VERSION = '2.030000'; |
6
|
20
|
|
|
20
|
|
571
|
use Moo; |
|
20
|
|
|
|
|
8913
|
|
|
20
|
|
|
|
|
96
|
|
7
|
20
|
|
|
20
|
|
6696
|
use Carp; |
|
20
|
|
|
|
|
60
|
|
|
20
|
|
|
|
|
1213
|
|
8
|
|
|
|
|
|
|
|
9
|
20
|
|
|
20
|
|
474
|
use MetaCPAN::Client::Types qw< ArrayRef >; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
2603
|
|
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
|
|
8682
|
use Safe::Isa; |
|
20
|
|
|
|
|
8473
|
|
|
20
|
|
|
|
|
9401
|
|
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
|
28236
|
my ( $class, %args ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
exists $args{scroller} or exists $args{items} |
58
|
14
|
50
|
66
|
|
|
76
|
or croak 'ResultSet must get either scroller or items'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
exists $args{scroller} and exists $args{items} |
61
|
14
|
50
|
66
|
|
|
2005
|
and croak 'ResultSet must get either scroller or items, not both'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
exists $args{type} or exists $args{class} |
64
|
14
|
100
|
100
|
|
|
211
|
or croak 'Must pass either type or target class to ResultSet'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
exists $args{type} and exists $args{class} |
67
|
13
|
50
|
66
|
|
|
77
|
and croak 'Must pass either type or target class to ResultSet, not both'; |
68
|
|
|
|
|
|
|
|
69
|
13
|
|
|
|
|
228
|
return \%args; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
sub BUILD { |
72
|
12
|
|
|
12
|
1
|
126
|
my ( $self ) = @_; |
73
|
12
|
|
|
|
|
182
|
$self->class; # vifify and validate |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub next { |
77
|
67
|
|
|
67
|
1
|
32122
|
my $self = shift; |
78
|
|
|
|
|
|
|
my $result = $self->has_scroller ? $self->scroller->next |
79
|
67
|
100
|
|
|
|
252
|
: shift @{ $self->items }; |
|
33
|
|
|
|
|
61
|
|
80
|
|
|
|
|
|
|
|
81
|
67
|
100
|
|
|
|
138
|
defined $result or return; |
82
|
|
|
|
|
|
|
|
83
|
64
|
|
33
|
|
|
893
|
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
|
|
111
|
my $self = shift; |
94
|
11
|
|
|
|
|
190
|
return 'MetaCPAN::Client::' . ucfirst $self->type; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |