line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::CPAN; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16401
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
76095
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
680
|
use MetaCPAN::API::Tiny; |
|
1
|
|
|
|
|
44936
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has prefix => (is => 'ro'); |
12
|
|
|
|
|
|
|
has author => (is => 'ro'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# http://api.metacpan.org/v0/release/_mapping |
15
|
|
|
|
|
|
|
our $RELEASE_FIELDS = [qw( |
16
|
|
|
|
|
|
|
abstract archive author authorized date dependency distribution |
17
|
|
|
|
|
|
|
download_url first id license maturity name provides resources stat status |
18
|
|
|
|
|
|
|
tests version version_numified |
19
|
|
|
|
|
|
|
)]; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has fields => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
default => sub { [ qw(id date distribution version abstract) ] }, |
24
|
|
|
|
|
|
|
coerce => sub { |
25
|
|
|
|
|
|
|
ref $_[0] ? $_[0] |
26
|
|
|
|
|
|
|
: ($_[0] eq 'all' ? $RELEASE_FIELDS |
27
|
|
|
|
|
|
|
: [ split /,/, $_[0] ]); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
|
|
has mcpan => (is => 'ro', builder => sub { MetaCPAN::API::Tiny->new }); |
32
|
|
|
|
|
|
|
has filter => (is => 'ro', lazy => 1, builder => 1); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _build_filter { |
35
|
0
|
|
|
0
|
|
|
my $self = $_[0]; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @filter = { term => { status => 'latest' } }; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ($self->prefix) { |
40
|
0
|
|
|
|
|
|
push @filter, { prefix => { archive => $self->prefix } }; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($self->author) { |
44
|
0
|
|
|
|
|
|
push @filter, { term => { author => $self->author } }; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (@filter > 1) { |
48
|
0
|
|
|
|
|
|
return { and => \@filter }; |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
|
return $filter[0]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub generator { |
55
|
|
|
|
|
|
|
my $self = $_[0]; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $result = $self->mcpan->post( |
58
|
|
|
|
|
|
|
release => { |
59
|
|
|
|
|
|
|
fields => $self->fields, |
60
|
|
|
|
|
|
|
filter => $self->filter, |
61
|
|
|
|
|
|
|
size => 1024, |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my @hits = @{$result->{hits}->{hits}}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return sub { |
68
|
|
|
|
|
|
|
my $hit = shift @hits; |
69
|
|
|
|
|
|
|
return undef unless $hit; |
70
|
|
|
|
|
|
|
return { |
71
|
|
|
|
|
|
|
map { $_ => $hit->{fields}->{$_} } @{$self->fields} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |