| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MyCPAN::App::DPAN::CPANUtils; |
|
2
|
1
|
|
|
1
|
|
1537
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
47
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '1.28_11'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
140
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
{ |
|
11
|
|
|
|
|
|
|
package Local::Null::Logger; |
|
12
|
1
|
|
|
1
|
|
11
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
809
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
|
|
sub new { bless \ my $x, $_[0] } |
|
15
|
0
|
|
|
0
|
|
|
sub AUTOLOAD { 1 } |
|
16
|
0
|
|
|
0
|
|
|
sub DESTROY { 1 } |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
MyCPAN::App::DPAN::CPANUtils - various things to interact with CPAN |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use MyCPAN::App::DPAN::CPANUtils; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
MyCPAN::App::DPAN::CPANUtils->pull_latest_whois( $directory ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This is a base class for MyCPAN reporters. It mostly deals with file |
|
34
|
|
|
|
|
|
|
and directory names that it composes from configuration and run details. |
|
35
|
|
|
|
|
|
|
Most things should just use what is already there. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
There is one abstract method that a subclass must implement on its own. |
|
38
|
|
|
|
|
|
|
The C methods allows each reporter to have |
|
39
|
|
|
|
|
|
|
a unique extension by which it can recognize its own reports. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 Methods |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item get_cpan_mirrors() |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Return a list of true CPAN mirrors so you can download canonical index |
|
48
|
|
|
|
|
|
|
files. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_cpan_mirrors |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
0
|
|
|
0
|
1
|
|
my( $class, $logger ) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my @mirrors = (); |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
push @mirrors, qw(http://www.cpan.org http://www.perl.com/CPAN); |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return @mirrors; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item pull_latest_whois( $directory ) |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Grab the latest canonical F<01mailrc.txt.gz> and F<00whois.xml> files |
|
66
|
|
|
|
|
|
|
and put them in C<$directory/authors>. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub pull_latest_whois |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
|
|
0
|
1
|
|
my( $class, $directory, $logger ) = @_; |
|
73
|
0
|
0
|
|
|
|
|
$logger = Local::Null::Logger->new unless eval { $logger->can( 'debug' ) }; |
|
|
0
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
unless( eval { require LWP::Simple } ) |
|
|
0
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
|
|
|
$logger->warn( "You need LWP::Simple to pull files from CPAN" ); |
|
78
|
0
|
|
|
|
|
|
return; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
unless( -d $directory ) |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
0
|
|
|
|
|
|
$logger->warn( "The directory [$directory] does not exist" ); |
|
84
|
0
|
|
|
|
|
|
return; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $author_dir = catfile( $directory, 'authors' ); |
|
88
|
0
|
0
|
0
|
|
|
|
unless( -d $author_dir or mkdir( $author_dir ) ) |
|
89
|
|
|
|
|
|
|
{ |
|
90
|
0
|
|
|
|
|
|
$logger->warn( "Could not create [$author_dir]: $!" ); |
|
91
|
0
|
|
|
|
|
|
return; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my @mirrors = $class->get_cpan_mirrors; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my %success; |
|
97
|
0
|
|
|
|
|
|
FILE: foreach my $file ( |
|
|
0
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
map { catfile( 'authors', $_ ) } |
|
99
|
|
|
|
|
|
|
map { $class->$_() } |
|
100
|
|
|
|
|
|
|
qw(mailrc_filename whois_filename) |
|
101
|
|
|
|
|
|
|
) |
|
102
|
|
|
|
|
|
|
{ |
|
103
|
0
|
0
|
0
|
|
|
|
if( -e $file and -M $file < 10*60 ) { $success{ $file }++; next FILE } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
MIRROR: foreach my $mirror ( $class->get_cpan_mirrors ) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
0
|
|
|
|
|
|
$mirror =~ s|/\z||; |
|
107
|
0
|
|
|
|
|
|
my $url = "$mirror/$file"; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$logger->info( "Trying to get $url" ); |
|
110
|
0
|
|
|
|
|
|
my $http_status = LWP::Simple::getstore( |
|
111
|
|
|
|
|
|
|
$url, |
|
112
|
|
|
|
|
|
|
catfile( $directory, $file ) |
|
113
|
|
|
|
|
|
|
); |
|
114
|
0
|
|
|
|
|
|
$logger->info( "$url returned $http_status" ); |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if( LWP::Simple::is_success( $http_status ) ) |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
0
|
|
|
|
|
|
$success{ $file }++; |
|
119
|
0
|
|
|
|
|
|
last MIRROR; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
keys %success; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item make_fake_whois( $directory ) |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Create stub F<01mailrc.txt.gz> and F<00whois.xml> files |
|
130
|
|
|
|
|
|
|
and put them in C<$directory/authors>. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub make_fake_whois |
|
135
|
|
|
|
|
|
|
{ |
|
136
|
0
|
|
|
0
|
1
|
|
my( $class, $directory, $logger ) = @_; |
|
137
|
0
|
0
|
|
|
|
|
$logger = Local::Null::Logger->new unless eval { $logger->can( 'debug' ) }; |
|
|
0
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
unless( -d $directory ) |
|
140
|
|
|
|
|
|
|
{ |
|
141
|
0
|
|
|
|
|
|
$logger->warn( "The directory [$directory] does not exist" ); |
|
142
|
0
|
|
|
|
|
|
return; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $author_dir = catfile( $directory, 'authors' ); |
|
146
|
0
|
0
|
0
|
|
|
|
unless( -d $author_dir or mkdir( $author_dir ) ) |
|
147
|
|
|
|
|
|
|
{ |
|
148
|
0
|
|
|
|
|
|
$logger->warn( "Could not create [$author_dir]: $!" ); |
|
149
|
0
|
|
|
|
|
|
return; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
1
|
|
|
1
|
|
8
|
no warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
305
|
|
|
153
|
|
|
|
|
|
|
return |
|
154
|
0
|
|
|
|
|
|
$class->make_fake_01mailrc( $author_dir, $logger ) |
|
155
|
|
|
|
|
|
|
+ |
|
156
|
|
|
|
|
|
|
$class->make_fake_00whois( $author_dir, $logger ) |
|
157
|
|
|
|
|
|
|
; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item make_fake_01mailrc( $directory ) |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Create a stub F<01mailrc.txt.gz> in C<$directory>. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub make_fake_01mailrc |
|
167
|
|
|
|
|
|
|
{ |
|
168
|
0
|
|
|
0
|
1
|
|
my( $class, $directory, $logger ) = @_; |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
$class->_shove_in_file( |
|
171
|
|
|
|
|
|
|
catfile( $directory, $class->mailrc_filename ), |
|
172
|
|
|
|
|
|
|
'', |
|
173
|
|
|
|
|
|
|
$logger |
|
174
|
|
|
|
|
|
|
); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item make_fake_00whois( $directory ) |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Create a stub F<00whois.xml> in C<$directory>. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub make_fake_00whois |
|
184
|
|
|
|
|
|
|
{ |
|
185
|
0
|
|
|
0
|
1
|
|
my( $class, $directory, $logger ) = @_; |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
my $date = gmtime() . ' GMT'; |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my $content = <<"HERE"; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
last-generated='$date' |
|
193
|
|
|
|
|
|
|
generated-by='dpan'> |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
HERE |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
$class->_shove_in_file( |
|
198
|
|
|
|
|
|
|
catfile( $directory, $class->whois_filename ), |
|
199
|
|
|
|
|
|
|
$content, |
|
200
|
|
|
|
|
|
|
$logger |
|
201
|
|
|
|
|
|
|
); |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub _shove_in_file |
|
205
|
|
|
|
|
|
|
{ |
|
206
|
0
|
|
|
0
|
|
|
my( $class, $filename, $content, $logger ) = @_; |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
0
|
|
|
|
|
return if -e $filename; |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my $fh; |
|
211
|
0
|
0
|
|
|
|
|
unless( open $fh, '>:utf8', $filename ) |
|
212
|
|
|
|
|
|
|
{ |
|
213
|
0
|
|
|
|
|
|
$logger->warn( "Could not open $filename for writing: $!" ); |
|
214
|
0
|
|
|
|
|
|
return; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
print $fh $content; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item mailrc_filename |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Returns the filename for F<01mailrc.txt.gz>. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
|
225
|
|
|
|
|
|
|
|
|
226
|
0
|
|
|
0
|
1
|
|
sub mailrc_filename { '01mailrc.txt.gz' } |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item whois_filename |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Returns the filename for F<00whois.xml>. |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
|
|
0
|
1
|
|
sub whois_filename { '00whois.xml' } |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This code is in Github: |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
git://github.com/briandfoy/mycpan--app--dpan.git |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 AUTHOR |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
brian d foy, C<< >> |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Copyright (c) 2010, brian d foy, All Rights Reserved. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
1; |