/
Module.pm
77 lines (59 loc) · 1.62 KB
/
Module.pm
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
package MetaCPAN::Web::Model::API::Module;
use Moose;
use namespace::autoclean;
extends 'MetaCPAN::Web::Model::API::File';
=head1 NAME
MetaCPAN::Web::Model::Module - Catalyst Model
=head1 DESCRIPTION
Catalyst Model.
=head1 AUTHOR
Moritz Onken, Matthew Phillips
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
sub find {
my ( $self, @path ) = @_;
$self->request( '/module/' . join( q{/}, @path ) );
}
sub autocomplete {
my ( $self, $query ) = @_;
$self->request( "/search/autocomplete", undef,
{ q => $query, size => 50 } )->transform(
done => sub {
my $data = shift;
return { results =>
[ map { $_->{fields} } @{ $data->{hits}->{hits} || [] } ]
};
}
);
}
sub search_web {
my ( $self, $query, $from, $page_size ) = @_;
$self->request( "/search/web", undef,
{ q => $query, size => $page_size // 20, from => $from // 0 } );
}
sub first {
my ( $self, $query ) = @_;
$self->request( "/search/simple", undef, { q => $query } )->transform(
done => sub {
my $data = shift;
return undef
unless ( $data->{hits}->{total} );
return $data->{hits}->{hits}->[0]->{fields}->{documentation};
}
);
}
sub requires {
my ( $self, $module, $page, $page_size ) = @_;
$self->request(
"/release/requires/$module",
undef,
{
page => $page,
page_size => $page_size,
},
);
}
__PACKAGE__->meta->make_immutable;
1;