line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Mini::Inject::Remote; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28288
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
|
|
106
|
use Params::Validate qw/validate |
6
|
1
|
|
|
1
|
|
1297
|
SCALAR/; |
|
1
|
|
|
|
|
10744
|
|
7
|
1
|
|
|
1
|
|
12
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
795
|
use YAML::Any qw/LoadFile/; |
|
1
|
|
|
|
|
859
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
12505
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
64557
|
|
|
1
|
|
|
|
|
116
|
|
10
|
1
|
|
|
1
|
|
11
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
11
|
1
|
|
|
1
|
|
1002
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2104
|
|
|
1
|
|
|
|
|
81
|
|
12
|
1
|
|
|
1
|
|
2060
|
use Data::Dumper; |
|
1
|
|
|
|
|
7711
|
|
|
1
|
|
|
|
|
62
|
|
13
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
812
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
CPAN::Mini::Inject::Remote - Inject into your CPAN mirror from over here |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 0.02 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
describe the module, working code example |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 FUNCTIONS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Class constructor |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
50
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
51
|
0
|
|
|
|
|
|
my $self = {}; |
52
|
0
|
|
|
|
|
|
bless ($self, $class); |
53
|
0
|
|
|
|
|
|
$self->_initialize(@_); |
54
|
0
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} # end of method new |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
###### |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# _initialize |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# Class properties initator |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _initialize { |
66
|
0
|
|
|
0
|
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my %args = validate(@_, |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
config_file => { |
70
|
|
|
|
|
|
|
type => SCALAR, |
71
|
|
|
|
|
|
|
optional => 1, |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
remote_server => { |
74
|
|
|
|
|
|
|
type => SCALAR, |
75
|
|
|
|
|
|
|
optional => 1, |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if (not $args{remote_server}) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
0
|
|
|
|
|
if (not $args{config_file}) |
|
|
0
|
|
|
|
|
|
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
|
$args{config_file} = $self->_find_config(); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif (not -r $args{config_file}) |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
|
croak "Supplied config file is not readable"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $config = LoadFile($args{config_file}); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$self->{remote_server} = $config->{remote_server}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
|
$self->{remote_server} = $args{remote_server}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# get rid of any trailing slash as it will break things |
101
|
0
|
|
|
|
|
|
$self->{remote_server} =~ s/\/$//; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} # end of method _initialize |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
###### |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
# _find_config |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
# Attempts to find the config from a number of locations |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# locations are:- |
113
|
|
|
|
|
|
|
# argument passed in |
114
|
|
|
|
|
|
|
# specified in $ENV{MCPANI_REMOTE_CONFIG}, |
115
|
|
|
|
|
|
|
# $ENV{HOME}/.mcpani_remote |
116
|
|
|
|
|
|
|
# /usr/local/etc/mcpani_remote |
117
|
|
|
|
|
|
|
# /etc/mcpani_remote |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
### |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _find_config { |
122
|
0
|
|
|
0
|
|
|
my $self = shift; |
123
|
0
|
|
|
|
|
|
my %args = validate(@_, |
124
|
|
|
|
|
|
|
{ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
my @config_locations = ( |
130
|
|
|
|
|
|
|
$ENV{MCPANI_REMOTE_CONFIG}, |
131
|
|
|
|
|
|
|
( |
132
|
|
|
|
|
|
|
defined $ENV{HOME} |
133
|
|
|
|
|
|
|
? File::Spec->catfile( $ENV{HOME}, qw/.mcpani_remote/) |
134
|
|
|
|
|
|
|
: () |
135
|
|
|
|
|
|
|
), |
136
|
|
|
|
|
|
|
File::Spec->catfile( |
137
|
|
|
|
|
|
|
File::Spec->rootdir(), |
138
|
|
|
|
|
|
|
qw/usr local etc mcpani_remote/ |
139
|
|
|
|
|
|
|
), |
140
|
|
|
|
|
|
|
File::Spec->catfile( |
141
|
|
|
|
|
|
|
File::Spec->rootdir(), |
142
|
|
|
|
|
|
|
qw/etc mcpani_remote/ |
143
|
|
|
|
|
|
|
), |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
for my $file ( @config_locations) { |
147
|
0
|
0
|
|
|
|
|
next unless defined $file; |
148
|
0
|
0
|
|
|
|
|
next unless -r $file; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return $file; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
croak "No config file was found that existed"; |
154
|
|
|
|
|
|
|
} # end of method _load_config |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
###### |
158
|
|
|
|
|
|
|
# |
159
|
|
|
|
|
|
|
# _useragent |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# loads up the user agent if one exists |
162
|
|
|
|
|
|
|
# |
163
|
|
|
|
|
|
|
### |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _useragent { |
166
|
0
|
|
|
0
|
|
|
my $self = shift; |
167
|
0
|
|
|
|
|
|
my %args = validate(@_, |
168
|
|
|
|
|
|
|
{ |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if (not $self->{useragent}) |
174
|
|
|
|
|
|
|
{ |
175
|
0
|
|
|
|
|
|
$self->{useragent} = LWP::UserAgent->new; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return $self->{useragent}; |
179
|
|
|
|
|
|
|
} # end of method _useragent |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 add |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Calls the add function on the remote server |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub add { |
189
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
190
|
0
|
|
|
|
|
|
my %args = validate(@_, |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
module_name => { |
193
|
|
|
|
|
|
|
type => SCALAR, |
194
|
|
|
|
|
|
|
}, |
195
|
|
|
|
|
|
|
author_id => { |
196
|
|
|
|
|
|
|
type => SCALAR, |
197
|
|
|
|
|
|
|
}, |
198
|
|
|
|
|
|
|
version => { |
199
|
|
|
|
|
|
|
type => SCALAR, |
200
|
|
|
|
|
|
|
}, |
201
|
|
|
|
|
|
|
file_name => { |
202
|
|
|
|
|
|
|
type => SCALAR, |
203
|
|
|
|
|
|
|
}, |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
); |
206
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
|
if (not -r $args{file_name}) |
208
|
|
|
|
|
|
|
{ |
209
|
0
|
|
|
|
|
|
croak "Module file is not readable"; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my $ua = $self->_useragent(); |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $response = $ua->request(POST $self->{remote_server}.'/add', |
216
|
|
|
|
|
|
|
Content_Type => 'form-data', |
217
|
|
|
|
|
|
|
Content => [ |
218
|
|
|
|
|
|
|
module => $args{module_name}, |
219
|
|
|
|
|
|
|
authorid => $args{author_id}, |
220
|
|
|
|
|
|
|
version => $args{version}, |
221
|
|
|
|
|
|
|
file => [$args{file_name}], |
222
|
|
|
|
|
|
|
] |
223
|
|
|
|
|
|
|
); |
224
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
|
if (not $response->is_success()) |
226
|
|
|
|
|
|
|
{ |
227
|
0
|
|
|
|
|
|
croak 'Add failed. ' . Dumper($response); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
return; |
231
|
|
|
|
|
|
|
} # end of method add |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 update |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Calls the update function on the remote server |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub update { |
241
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
242
|
0
|
|
|
|
|
|
my %args = validate(@_, |
243
|
|
|
|
|
|
|
{ |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
); |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $ua = $self->_useragent(); |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $response = $ua->request(POST $self->{remote_server}.'/update'); |
251
|
|
|
|
|
|
|
|
252
|
0
|
0
|
|
|
|
|
if (not $response->is_success()) |
253
|
|
|
|
|
|
|
{ |
254
|
0
|
|
|
|
|
|
croak 'Update failed. ' . Dumper($response); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
return; |
258
|
|
|
|
|
|
|
} # end of method update |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 inject |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Calls the inject function on the remote server |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub inject { |
268
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
269
|
0
|
|
|
|
|
|
my %args = validate(@_, |
270
|
|
|
|
|
|
|
{ |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
); |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
my $ua = $self->_useragent(); |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
my $response = $ua->request(POST $self->{remote_server}.'/inject'); |
278
|
|
|
|
|
|
|
|
279
|
0
|
0
|
|
|
|
|
if (not $response->is_success()) |
280
|
|
|
|
|
|
|
{ |
281
|
0
|
|
|
|
|
|
croak 'Inject failed. ' . Dumper($response); |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
return; |
285
|
|
|
|
|
|
|
} # end of method inject |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head1 AUTHOR |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Christopher Mckay, C<< >> |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 BUGS |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
295
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
296
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 TODO |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Fix up error messages, they currently contain $response dumps |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 SUPPORT |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
perldoc CPAN::Mini::Inject::Remote |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
You can also look for information at: |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=over 4 |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
L |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
L |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=item * CPAN Ratings |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
L |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item * Search CPAN |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
L |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=back |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
Copyright 2009 Christopher Mckay. |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
340
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
341
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=cut |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
1; # End of CPAN::Mini::Inject::Remote |