| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::CPAN::Get::MetaCPAN; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
134012
|
use strict; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
312
|
|
|
4
|
8
|
|
|
8
|
|
41
|
use warnings; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
467
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
4470
|
use Class::Utils qw(set_params); |
|
|
8
|
|
|
|
|
118029
|
|
|
|
8
|
|
|
|
|
249
|
|
|
7
|
8
|
|
|
8
|
|
9429
|
use Cpanel::JSON::XS; |
|
|
8
|
|
|
|
|
57135
|
|
|
|
8
|
|
|
|
|
757
|
|
|
8
|
8
|
|
|
8
|
|
64
|
use English; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
60
|
|
|
9
|
8
|
|
|
8
|
|
4486
|
use Error::Pure qw(err); |
|
|
8
|
|
|
|
|
24
|
|
|
|
8
|
|
|
|
|
434
|
|
|
10
|
8
|
|
|
8
|
|
4070
|
use IO::Barf qw(barf); |
|
|
8
|
|
|
|
|
6654
|
|
|
|
8
|
|
|
|
|
144
|
|
|
11
|
8
|
|
|
8
|
|
6729
|
use LWP::UserAgent; |
|
|
8
|
|
|
|
|
575884
|
|
|
|
8
|
|
|
|
|
425
|
|
|
12
|
8
|
|
|
8
|
|
82
|
use Readonly; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
566
|
|
|
13
|
8
|
|
|
8
|
|
42
|
use Scalar::Util qw(blessed); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
361
|
|
|
14
|
8
|
|
|
8
|
|
40
|
use URI; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
7530
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar our $FASTAPI => qw(https://fastapi.metacpan.org/v1/download_url/); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.14; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
18
|
|
|
18
|
1
|
673106
|
my ($class, @params) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Create object. |
|
24
|
18
|
|
|
|
|
45
|
my $self = bless {}, $class; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# LWP::User agent object. |
|
27
|
18
|
|
|
|
|
80
|
$self->{'lwp_user_agent'} = undef; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Process parameters. |
|
30
|
18
|
|
|
|
|
78
|
set_params($self, @params); |
|
31
|
|
|
|
|
|
|
|
|
32
|
17
|
100
|
|
|
|
235
|
if (defined $self->{'lwp_user_agent'}) { |
|
33
|
16
|
100
|
100
|
|
|
153
|
if (! blessed($self->{'lwp_user_agent'}) |
|
34
|
|
|
|
|
|
|
|| ! $self->{'lwp_user_agent'}->isa('LWP::UserAgent')) { |
|
35
|
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
37
|
err "Parameter 'lwp_user_agent' must be a ". |
|
37
|
|
|
|
|
|
|
'LWP::UserAgent instance.'; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} else { |
|
40
|
1
|
|
|
|
|
16
|
$self->{'lwp_user_agent'} = LWP::UserAgent->new; |
|
41
|
1
|
|
|
|
|
3619
|
$self->{'lwp_user_agent'}->agent(__PACKAGE__.'/'.$VERSION); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
15
|
|
|
|
|
165
|
return $self; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub search { |
|
48
|
8
|
|
|
8
|
1
|
75
|
my ($self, $args_hr) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
8
|
100
|
100
|
|
|
41
|
if (! defined $args_hr |
|
51
|
|
|
|
|
|
|
|| ref $args_hr ne 'HASH') { |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
9
|
err 'Bad search options.'; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
6
|
100
|
|
|
|
28
|
if (! exists $args_hr->{'package'}) { |
|
56
|
1
|
|
|
|
|
5
|
err "Package doesn't present."; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
42
|
my $uri = $self->_construct_uri($args_hr); |
|
60
|
5
|
|
|
|
|
45
|
my $content = eval { |
|
61
|
5
|
|
|
|
|
23
|
$self->_fetch($uri); |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
5
|
100
|
|
|
|
3163
|
if ($EVAL_ERROR) { |
|
64
|
2
|
50
|
|
|
|
28
|
if ($EVAL_ERROR =~ m/^Cannot fetch/ms) { |
|
65
|
2
|
|
|
|
|
14
|
err "Module '$args_hr->{'package'}' doesn't exist."; |
|
66
|
|
|
|
|
|
|
} else { |
|
67
|
0
|
|
|
|
|
0
|
err $EVAL_ERROR; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
3
|
|
|
|
|
104
|
my $content_hr = decode_json($content); |
|
71
|
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
16
|
return $content_hr; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub save { |
|
76
|
1
|
|
|
1
|
1
|
4
|
my ($self, $uri, $file, $opts_hr) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
2
|
my $force = 0; |
|
79
|
1
|
50
|
33
|
|
|
12
|
if (defined $opts_hr |
|
|
|
|
33
|
|
|
|
|
|
80
|
|
|
|
|
|
|
&& exists $opts_hr->{'f'} |
|
81
|
|
|
|
|
|
|
&& $opts_hr->{'f'}) { |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
$force = 1; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
50
|
33
|
|
|
60
|
if (-r $file && ! $force) { |
|
87
|
0
|
|
|
|
|
0
|
err "File '$file' exists."; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
4
|
my $content = $self->_fetch($uri); |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
22
|
barf($file, $content); |
|
93
|
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
229
|
return; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _construct_uri { |
|
98
|
5
|
|
|
5
|
|
13
|
my ($self, $args_hr) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
5
|
|
|
|
|
12
|
my %query = (); |
|
101
|
5
|
50
|
|
|
|
15
|
if ($args_hr->{'include_dev'}) { |
|
102
|
0
|
|
|
|
|
0
|
$query{'dev'} = 1; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
5
|
100
|
|
|
|
30
|
if ($args_hr->{'version'}) { |
|
|
|
50
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
5
|
$query{'version'} = '== '.$args_hr->{'version'}; |
|
106
|
|
|
|
|
|
|
} elsif ($args_hr->{'version_range'}) { |
|
107
|
0
|
|
|
|
|
0
|
$query{'version'} = $args_hr->{'version_range'}; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
5
|
|
|
|
|
55
|
my $uri = URI->new($FASTAPI.$args_hr->{'package'}); |
|
111
|
5
|
|
|
|
|
22544
|
$uri->query_form(each %query); |
|
112
|
|
|
|
|
|
|
|
|
113
|
5
|
|
|
|
|
414
|
return $uri->as_string; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _fetch { |
|
117
|
6
|
|
|
6
|
|
18
|
my ($self, $uri) = @_; |
|
118
|
|
|
|
|
|
|
|
|
119
|
6
|
|
|
|
|
70
|
my $res = $self->{'lwp_user_agent'}->get($uri); |
|
120
|
6
|
100
|
|
|
|
15537
|
if (! $res->is_success) { |
|
121
|
2
|
|
|
|
|
25
|
my $err_hr = { |
|
122
|
|
|
|
|
|
|
'HTTP code' => $res->code, |
|
123
|
|
|
|
|
|
|
'HTTP message' => $res->message, |
|
124
|
|
|
|
|
|
|
}; |
|
125
|
2
|
50
|
|
|
|
39
|
if ($res->is_client_error) { |
|
|
|
0
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
20
|
err "Cannot fetch '$uri' URI.", %{$err_hr}; |
|
|
2
|
|
|
|
|
16
|
|
|
127
|
|
|
|
|
|
|
} elsif ($res->is_server_error) { |
|
128
|
0
|
|
|
|
|
0
|
err "Cannot connect to CPAN server.", %{$err_hr}; |
|
|
0
|
|
|
|
|
0
|
|
|
129
|
|
|
|
|
|
|
} else { |
|
130
|
0
|
|
|
|
|
0
|
err "Cannot fetch '$uri'.", %{$err_hr}; |
|
|
0
|
|
|
|
|
0
|
|
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
4
|
|
|
|
|
59
|
return $res->content; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |