/usr/share/perl5/MetaCPAN/Client/ResultSet.pm is in libmetacpan-client-perl 2.023000-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | use strict;
use warnings;
package MetaCPAN::Client::ResultSet;
# ABSTRACT: A Result Set
$MetaCPAN::Client::ResultSet::VERSION = '2.023000';
use Moo;
use Carp;
use MetaCPAN::Client::Types qw< ArrayRef >;
has type => (
is => 'ro',
isa => sub {
croak 'Invalid type' unless
grep { $_ eq $_[0] } qw<author distribution favorite
file module rating release mirror package>;
},
lazy => 1,
);
# in case we're returning from a scrolled search
has scroller => (
is => 'ro',
isa => sub {
use Safe::Isa;
$_[0]->$_isa('MetaCPAN::Client::Scroll')
or croak 'scroller must be an MetaCPAN::Client::Scroll object';
},
predicate => 'has_scroller',
);
# in case we're returning from a fetch
has items => (
is => 'ro',
isa => ArrayRef,
);
has total => (
is => 'ro',
default => sub {
my $self = shift;
return $self->has_scroller ? $self->scroller->total
: scalar @{ $self->items };
},
);
has 'class' => (
is => 'ro',
lazy => 1,
builder => '_build_class',
);
sub BUILDARGS {
my ( $class, %args ) = @_;
exists $args{scroller} or exists $args{items}
or croak 'ResultSet must get either scroller or items';
exists $args{scroller} and exists $args{items}
and croak 'ResultSet must get either scroller or items, not both';
exists $args{type} or exists $args{class}
or croak 'Must pass either type or target class to ResultSet';
exists $args{type} and exists $args{class}
and croak 'Must pass either type or target class to ResultSet, not both';
return \%args;
}
sub BUILD {
my ( $self ) = @_;
$self->class; # vifify and validate
}
sub next {
my $self = shift;
my $result = $self->has_scroller ? $self->scroller->next
: shift @{ $self->items };
defined $result or return;
return $self->class->new_from_request( $result->{'_source'} || $result->{'fields'} || $result );
}
sub aggregations {
my $self = shift;
return $self->has_scroller ? $self->scroller->aggregations : {};
}
sub _build_class {
my $self = shift;
return 'MetaCPAN::Client::' . ucfirst $self->type;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
MetaCPAN::Client::ResultSet - A Result Set
=head1 VERSION
version 2.023000
=head1 DESCRIPTION
Object representing a result from Elastic Search. This is used for the complex
(as in L<non-simple/MetaCPAN::Client/"SEARCH SPEC">) queries to MetaCPAN. It
provides easy access to the scroller and aggregations.
=head1 ATTRIBUTES
=head2 scroller
An L<MetaCPAN::Client::Scroll> object.
=head2 items
An arrayref of items to manually scroll over, instead of a scroller object.
=head2 type
The entity of the result set. Available types:
=over 4
=item * author
=item * distribution
=item * module
=item * release
=item * favorite
=item * file
=back
=head2 aggregations
The aggregations available in the Elastic Search response.
=head1 METHODS
=head2 next
Iterator call to fetch the next result set object.
=head2 total
Iterator call to fetch the total amount of objects available in result set.
=head2 has_scroller
Predicate for ES scroller presence.
=head2 BUILDARGS
Double checks construction of objects. You should never run this yourself.
=head2 BUILD
Validates the object. You should never run this yourself.
=head1 AUTHORS
=over 4
=item *
Sawyer X <xsawyerx@cpan.org>
=item *
Mickey Nasriachi <mickey@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Sawyer X.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|