line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
15
|
|
|
15
|
|
11571
|
use strict; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
551
|
|
2
|
15
|
|
|
15
|
|
74
|
use warnings; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
737
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::API::Autocomplete; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$MetaCPAN::API::Autocomplete::VERSION = '0.44'; |
6
|
15
|
|
|
15
|
|
75
|
use Carp; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
870
|
|
7
|
15
|
|
|
15
|
|
440
|
use Any::Moose 'Role'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
86
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub autocomplete { |
11
|
4
|
|
|
4
|
1
|
4488
|
my $self = shift; |
12
|
4
|
100
|
|
|
|
21
|
my %opts = @_ ? @_ : (); |
13
|
4
|
|
|
|
|
7
|
my $url = ''; |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
|
|
6
|
my $error = "You have to provide a search term"; |
16
|
4
|
|
|
|
|
7
|
my $size_error = "The size has to be between 0 and 100"; |
17
|
|
|
|
|
|
|
|
18
|
4
|
100
|
|
|
|
335
|
%opts or croak $error; |
19
|
3
|
100
|
66
|
|
|
113
|
$opts{search} && ref $opts{search} eq 'HASH' or croak $error; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
4
|
my %extra_opts; |
22
|
|
|
|
|
|
|
|
23
|
2
|
50
|
|
|
|
10
|
if ( defined ( my $term = $opts{search}->{query} ) ) { |
24
|
2
|
|
|
|
|
5
|
$url = 'search/autocomplete'; |
25
|
2
|
|
|
|
|
5
|
$extra_opts{q} = $term; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
6
|
my $size = $opts{search}->{size}; |
28
|
2
|
100
|
33
|
|
|
21
|
if ( defined $size && $size >= 0 && $size <= 100 ) { |
|
|
|
66
|
|
|
|
|
29
|
1
|
|
|
|
|
3
|
$extra_opts{size} = $size; |
30
|
|
|
|
|
|
|
} else { |
31
|
1
|
|
|
|
|
178
|
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__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
MetaCPAN::API::Autocomplete - Autocompletion info for MetaCPAN::API |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 VERSION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
version 0.44 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This role provides MetaCPAN::API with fetching autocomplete information |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 autocomplete |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $result = $mcpan->autocomplete( |
63
|
|
|
|
|
|
|
search => { |
64
|
|
|
|
|
|
|
query => 'Moose', |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
By default, you get 20 results (at maximum). If you need more, you |
69
|
|
|
|
|
|
|
can also pass C<size>: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $result = $mcpan->autocomplete( |
72
|
|
|
|
|
|
|
search => { |
73
|
|
|
|
|
|
|
query => 'Moose', |
74
|
|
|
|
|
|
|
size => 30, |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
There is a hardcoded limit of 100 results (hardcoded in MetaCPAN). |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Searches MetaCPAN for autocompletion info. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Sawyer X <xsawyerx@cpan.org> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Sawyer X. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
91
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|