line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
15
|
|
|
15
|
|
6533
|
use strict; |
|
15
|
|
|
|
|
80
|
|
|
15
|
|
|
|
|
391
|
|
2
|
15
|
|
|
15
|
|
71
|
use warnings; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
613
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::API::Autocomplete; |
4
|
|
|
|
|
|
|
# ABSTRACT: Autocompletion info for MetaCPAN::API |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.51'; |
7
|
|
|
|
|
|
|
|
8
|
15
|
|
|
15
|
|
99
|
use Carp; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
655
|
|
9
|
15
|
|
|
15
|
|
81
|
use Moo::Role; |
|
15
|
|
|
|
|
27
|
|
|
15
|
|
|
|
|
79
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# /search/autocomplete?q={search} |
12
|
|
|
|
|
|
|
sub autocomplete { |
13
|
4
|
|
|
4
|
1
|
3554
|
my $self = shift; |
14
|
4
|
100
|
|
|
|
20
|
my %opts = @_ ? @_ : (); |
15
|
4
|
|
|
|
|
10
|
my $url = ''; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
7
|
my $error = "You have to provide a search term"; |
18
|
4
|
|
|
|
|
8
|
my $size_error = "The size has to be between 0 and 100"; |
19
|
|
|
|
|
|
|
|
20
|
4
|
100
|
|
|
|
138
|
%opts or croak $error; |
21
|
3
|
100
|
66
|
|
|
83
|
$opts{search} && ref $opts{search} eq 'HASH' or croak $error; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
|
|
5
|
my %extra_opts; |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
|
|
|
9
|
if ( defined ( my $term = $opts{search}->{query} ) ) { |
26
|
2
|
|
|
|
|
5
|
$url = 'search/autocomplete'; |
27
|
2
|
|
|
|
|
5
|
$extra_opts{q} = $term; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
4
|
my $size = $opts{search}->{size}; |
30
|
2
|
100
|
33
|
|
|
17
|
if ( defined $size && $size >= 0 && $size <= 100 ) { |
|
|
|
66
|
|
|
|
|
31
|
1
|
|
|
|
|
3
|
$extra_opts{size} = $size; |
32
|
|
|
|
|
|
|
} else { |
33
|
1
|
|
|
|
|
129
|
croak $size_error; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
0
|
croak $error; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
7
|
return $self->fetch( $url, %extra_opts ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |