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