line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PPM::Make::Util; |
2
|
6
|
|
|
6
|
|
22
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
144
|
|
3
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
124
|
|
4
|
6
|
|
|
6
|
|
20
|
use base qw(Exporter); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
609
|
|
5
|
6
|
|
|
6
|
|
27
|
use File::Basename; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
345
|
|
6
|
6
|
|
|
6
|
|
439
|
use Safe; |
|
6
|
|
|
|
|
29885
|
|
|
6
|
|
|
|
|
178
|
|
7
|
6
|
|
|
6
|
|
6276
|
use XML::Parser; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Digest::MD5; |
9
|
|
|
|
|
|
|
use Config; |
10
|
|
|
|
|
|
|
use CPAN::DistnameInfo; |
11
|
|
|
|
|
|
|
use File::Spec; |
12
|
|
|
|
|
|
|
use PPM::Make::Config qw(WIN32 HAS_CPAN ACTIVEPERL); |
13
|
|
|
|
|
|
|
use HTTP::Tiny; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
PPM::Make::Util - Utility functions for PPM::Make |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use PPM::Make::Util qw(:all); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module contains a number of utility functions used by PPM::Make. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 2 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = '0.9903'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our (@EXPORT_OK, %EXPORT_TAGS, $protocol, $ext, $src_dir, $build_dir, |
34
|
|
|
|
|
|
|
@url_list, $ERROR); |
35
|
|
|
|
|
|
|
$protocol = qr{^(http|ftp)://}; |
36
|
|
|
|
|
|
|
$ext = qr{\.(tar\.gz|tgz|tar\.Z|zip)}; |
37
|
|
|
|
|
|
|
@url_list = url_list(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @exports = qw(load_cs verifyMD5 verifySHA256 parse_version $ERROR |
40
|
|
|
|
|
|
|
is_core is_ap_core url_list |
41
|
|
|
|
|
|
|
parse_ppd parse_abstract |
42
|
|
|
|
|
|
|
ppd2cpan_version cpan2ppd_version |
43
|
|
|
|
|
|
|
file_to_dist cpan_file fix_path |
44
|
|
|
|
|
|
|
mirror |
45
|
|
|
|
|
|
|
$src_dir $build_dir @url_list); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => [@exports]); |
48
|
|
|
|
|
|
|
@EXPORT_OK = (@exports); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my %ap_core = map {$_ => 1} qw( |
51
|
|
|
|
|
|
|
Archive-Tar |
52
|
|
|
|
|
|
|
Archive-Zip |
53
|
|
|
|
|
|
|
Compress-Zlib |
54
|
|
|
|
|
|
|
Data-Dump |
55
|
|
|
|
|
|
|
Digest-HMAC |
56
|
|
|
|
|
|
|
Digest-MD2 |
57
|
|
|
|
|
|
|
Digest-MD4 |
58
|
|
|
|
|
|
|
Digest-SHA1 |
59
|
|
|
|
|
|
|
File-CounterFile |
60
|
|
|
|
|
|
|
Font-AFM |
61
|
|
|
|
|
|
|
HTML-Parser |
62
|
|
|
|
|
|
|
HTML-Tagset |
63
|
|
|
|
|
|
|
HTML-Tree |
64
|
|
|
|
|
|
|
IO-String |
65
|
|
|
|
|
|
|
IO-Zlib |
66
|
|
|
|
|
|
|
libwin32 |
67
|
|
|
|
|
|
|
libwww-perl |
68
|
|
|
|
|
|
|
MD5 |
69
|
|
|
|
|
|
|
MIME-Base64-Scripts |
70
|
|
|
|
|
|
|
SOAP-Lite |
71
|
|
|
|
|
|
|
Term-ReadLine-Perl |
72
|
|
|
|
|
|
|
TermReadKey |
73
|
|
|
|
|
|
|
Text-Autoformat |
74
|
|
|
|
|
|
|
Text-Reform |
75
|
|
|
|
|
|
|
Tk |
76
|
|
|
|
|
|
|
Unicode-String |
77
|
|
|
|
|
|
|
URI |
78
|
|
|
|
|
|
|
XML-Parser |
79
|
|
|
|
|
|
|
XML-Simple ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if (WIN32 and ACTIVEPERL and eval { Win32::BuildNumber() > 818 }) { |
82
|
|
|
|
|
|
|
$ap_core{'DBI'}++; $ap_core{'DBD-SQLite'}++; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
src_and_build(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my %dists; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item fix_path |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Ensures a path is a Unix-type path, with no spaces. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $path = 'C:\Program Files\'; |
93
|
|
|
|
|
|
|
my $unix_version = fix_path($path); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub fix_path { |
98
|
|
|
|
|
|
|
my $path = shift; |
99
|
|
|
|
|
|
|
$path = Win32::GetShortPathName($path); |
100
|
|
|
|
|
|
|
$path =~ s!\\!/!g; |
101
|
|
|
|
|
|
|
$path =~ s!/$!!; |
102
|
|
|
|
|
|
|
return $path; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item load_cs |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Loads a CHECKSUMS file into $cksum |
108
|
|
|
|
|
|
|
(adapted from the MD5 check of CPAN.pm) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $cksum = load_cs('CHECKSUMS'); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub load_cs { |
115
|
|
|
|
|
|
|
my $cs = shift; |
116
|
|
|
|
|
|
|
open(my $fh, '<', $cs); |
117
|
|
|
|
|
|
|
unless ($fh) { |
118
|
|
|
|
|
|
|
$ERROR = qq{Could not open "$cs": $!}; |
119
|
|
|
|
|
|
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
local($/); |
122
|
|
|
|
|
|
|
my $eval = <$fh>; |
123
|
|
|
|
|
|
|
close $fh; |
124
|
|
|
|
|
|
|
$eval =~ s/\015?\012/\n/g; |
125
|
|
|
|
|
|
|
my $comp = Safe->new(); |
126
|
|
|
|
|
|
|
my $cksum = $comp->reval($eval); |
127
|
|
|
|
|
|
|
if ($@) { |
128
|
|
|
|
|
|
|
$ERROR = qq{eval of "$cs" failed: $@}; |
129
|
|
|
|
|
|
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
return $cksum; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item verifyMD5 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Verify a CHECKSUM for a $file |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $ok = verifyMD5($cksum, $file); |
139
|
|
|
|
|
|
|
print "$file checked out OK" if $ok; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub verifyMD5 { |
144
|
|
|
|
|
|
|
my ($cksum, $file) = @_; |
145
|
|
|
|
|
|
|
my ($is, $should); |
146
|
|
|
|
|
|
|
open (my $fh, '<', $file); |
147
|
|
|
|
|
|
|
unless ($fh) { |
148
|
|
|
|
|
|
|
$ERROR = qq{Cannot open "$file": $!}; |
149
|
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
binmode($fh); |
152
|
|
|
|
|
|
|
unless ($is = Digest::MD5->new->addfile($fh)->hexdigest) { |
153
|
|
|
|
|
|
|
$ERROR = qq{Could not compute checksum for "$file": $!}; |
154
|
|
|
|
|
|
|
close $fh; |
155
|
|
|
|
|
|
|
return; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
close $fh; |
158
|
|
|
|
|
|
|
if ($should = $cksum->{$file}->{md5}) { |
159
|
|
|
|
|
|
|
my $test = ($is eq $should); |
160
|
|
|
|
|
|
|
if (!$test && ($should = $cksum->{$file}->{'md5-ungz'})) { |
161
|
|
|
|
|
|
|
$test = ($is eq $should); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
printf qq{ Checksum for "$file" is %s\n}, |
164
|
|
|
|
|
|
|
($test) ? 'OK.' : 'NOT OK.'; |
165
|
|
|
|
|
|
|
return $test; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else { |
168
|
|
|
|
|
|
|
$ERROR = qq{Checksum data for "$file" not present.}; |
169
|
|
|
|
|
|
|
return; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item verifySHA256 |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Verify a CHECKSUM for a $file |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $ok = verifySHA256($cksum, $file); |
178
|
|
|
|
|
|
|
print "$file checked out OK" if $ok; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub verifySHA256 { |
183
|
|
|
|
|
|
|
my ($cksum, $file) = @_; |
184
|
|
|
|
|
|
|
my ($is, $should); |
185
|
|
|
|
|
|
|
open (my $fh, '<', $file); |
186
|
|
|
|
|
|
|
unless ($fh) { |
187
|
|
|
|
|
|
|
$ERROR = qq{Cannot open "$file": $!}; |
188
|
|
|
|
|
|
|
return; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
require Digest::SHA; |
191
|
|
|
|
|
|
|
binmode($fh); |
192
|
|
|
|
|
|
|
unless ($is = Digest::SHA->new(256)->addfile($fh)->hexdigest) { |
193
|
|
|
|
|
|
|
$ERROR = qq{Could not compute checksum for "$file": $!}; |
194
|
|
|
|
|
|
|
close $fh; |
195
|
|
|
|
|
|
|
return; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
close $fh; |
198
|
|
|
|
|
|
|
if ($should = $cksum->{$file}->{sha256}) { |
199
|
|
|
|
|
|
|
my $test = ($is eq $should); |
200
|
|
|
|
|
|
|
if (!$test && ($should = $cksum->{$file}->{'sha256-ungz'})) { |
201
|
|
|
|
|
|
|
$test = ($is eq $should); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
printf qq{ SHA256-Checksum for "$file" is %s\n}, |
204
|
|
|
|
|
|
|
($test) ? 'OK.' : 'NOT OK.'; |
205
|
|
|
|
|
|
|
return $test; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
|
|
|
|
|
|
$ERROR = qq{Checksum data for "$file" not present.}; |
209
|
|
|
|
|
|
|
return; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item is_core |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Tests to see if a module is part of the core, based on |
216
|
|
|
|
|
|
|
whether or not the file is found within a I type |
217
|
|
|
|
|
|
|
of directory. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
my $is_core = is_core('Net::FTP'); |
220
|
|
|
|
|
|
|
print "Net::FTP is a core module" if $is_core; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub is_core { |
225
|
|
|
|
|
|
|
my $m = shift; |
226
|
|
|
|
|
|
|
return unless $m; |
227
|
|
|
|
|
|
|
$m =~ s!::|-!/!g; |
228
|
|
|
|
|
|
|
$m .= '.pm'; |
229
|
|
|
|
|
|
|
my $is_core = (-e File::Spec->catfile($Config{privlibexp}, $m)) ? 1 : 0; |
230
|
|
|
|
|
|
|
return $is_core; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item is_ap_core |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Tests to see if a package is part of the ActivePerl core (at |
236
|
|
|
|
|
|
|
least for recent ActivePerl versions). |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $is_ap_core = is_ap_core('libwin32'); |
239
|
|
|
|
|
|
|
print "libwin32 is a core package" if $is_ap_core; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub is_ap_core { |
244
|
|
|
|
|
|
|
my $p = shift; |
245
|
|
|
|
|
|
|
return unless defined $p; |
246
|
|
|
|
|
|
|
return defined $ap_core{$p} ? 1 : 0; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item file_to_dist |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
In scalar context, returns a CPAN distribution name I based |
252
|
|
|
|
|
|
|
on an input file I: |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $file = 'A/AB/ABC/defg-1.23.tar.gz'; |
255
|
|
|
|
|
|
|
my $dist = file_to_dist($file); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
In a list context, returns both the distribution name I |
258
|
|
|
|
|
|
|
and the version number I<1.23>: |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my $file = 'A/AB/ABC/defg-1.23.tar.gz'; |
261
|
|
|
|
|
|
|
my ($dist, $version) = file_to_dist($cpan_file); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub file_to_dist { |
267
|
|
|
|
|
|
|
my $cpan_file = shift; |
268
|
|
|
|
|
|
|
return unless $cpan_file; |
269
|
|
|
|
|
|
|
my $d = CPAN::DistnameInfo->new($cpan_file); |
270
|
|
|
|
|
|
|
my ($dist, $version) = ($d->dist, $d->version); |
271
|
|
|
|
|
|
|
unless ($dist and $version) { |
272
|
|
|
|
|
|
|
$ERROR = qq{Could not find distribution name from $cpan_file.}; |
273
|
|
|
|
|
|
|
return; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
return wantarray? ($dist, $version) : $dist; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item ppd2cpan_version |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Converts a ppd-type of version string (eg, I<1,23,0,0>) into a ppd one |
281
|
|
|
|
|
|
|
of the form I<1.23>: |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
my $s = "1,23,0,0"; |
284
|
|
|
|
|
|
|
my $v = ppd2cpan_version($v); |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub ppd2cpan_version { |
289
|
|
|
|
|
|
|
local $_ = shift; |
290
|
|
|
|
|
|
|
s/(,0)*$//; |
291
|
|
|
|
|
|
|
tr/,/./; |
292
|
|
|
|
|
|
|
return $_; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item cpan2ppd_version |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Converts a cpan-type of version string (eg, I<1.23>) into a ppd one |
298
|
|
|
|
|
|
|
of the form I<1,23,0,0>: |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
my $v = 1.23; |
301
|
|
|
|
|
|
|
my $s = cpan2ppd_version($v); |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub cpan2ppd_version { |
306
|
|
|
|
|
|
|
local $_ = shift; |
307
|
|
|
|
|
|
|
return join ',', (split (/\./, $_), (0)x4)[0..3]; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=item parse_ppd |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
Parse a I file or a string. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
my $ppd = 'package.ppd'; |
316
|
|
|
|
|
|
|
my $d = parse_ppd($ppd); |
317
|
|
|
|
|
|
|
print $d->{ABSTRACT}; |
318
|
|
|
|
|
|
|
print $d->{OS}->{NAME}; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
my $e = parse_ppd($ppd, 'MSWin32-x86-multi-thread'); |
321
|
|
|
|
|
|
|
print $e->{ABSTRACT}; |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
This routine takes a required argument of a I file containing |
324
|
|
|
|
|
|
|
a I<.ppd> extension or a string and, |
325
|
|
|
|
|
|
|
optionally, an ARCHITECTURE name to restrict the results to. |
326
|
|
|
|
|
|
|
It returns a data structure containing the information of |
327
|
|
|
|
|
|
|
the ppd file or string: |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
$d->{SOFTPKG}->{NAME} |
330
|
|
|
|
|
|
|
$d->{SOFTPKG}->{VERSION} |
331
|
|
|
|
|
|
|
$d->{TITLE} |
332
|
|
|
|
|
|
|
$d->{AUTHOR} |
333
|
|
|
|
|
|
|
$d->{ABSTRACT} |
334
|
|
|
|
|
|
|
$d->{PROVIDE} |
335
|
|
|
|
|
|
|
$d->{DEPENDENCY} |
336
|
|
|
|
|
|
|
$d->{REQUIRE} |
337
|
|
|
|
|
|
|
$d->{OS}->{NAME} |
338
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} |
339
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} |
340
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} |
341
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} |
342
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
The I, I and I tags are array references |
345
|
|
|
|
|
|
|
containing lists of, respectively, the prerequisites required and |
346
|
|
|
|
|
|
|
the modules supplied by the package, with keys of I and |
347
|
|
|
|
|
|
|
I. |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
If there is more than one I section in the |
350
|
|
|
|
|
|
|
ppd file, all the results except for the I elements and |
351
|
|
|
|
|
|
|
I, I, and I will be placed in |
352
|
|
|
|
|
|
|
a I<$d-E{IMPLENTATION}> array |
353
|
|
|
|
|
|
|
reference. If an optional second argument is passed to |
354
|
|
|
|
|
|
|
I, this will filter out all implementation |
355
|
|
|
|
|
|
|
sections except for the specified I given by I<$arch>. |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=cut |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
my $i; |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub parse_ppd { |
362
|
|
|
|
|
|
|
my $file = shift; |
363
|
|
|
|
|
|
|
my $arch = shift; |
364
|
|
|
|
|
|
|
my $is_a_file = ($file =~ /\.ppd/); |
365
|
|
|
|
|
|
|
if ($is_a_file) { |
366
|
|
|
|
|
|
|
unless (-e $file) { |
367
|
|
|
|
|
|
|
$ERROR = qq{$file not found.}; |
368
|
|
|
|
|
|
|
return; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
my $p = XML::Parser->new(Style => 'Subs', |
372
|
|
|
|
|
|
|
Handlers => {Char => \&ppd_char, |
373
|
|
|
|
|
|
|
Start => \&ppd_start, |
374
|
|
|
|
|
|
|
End => \&ppd_end, |
375
|
|
|
|
|
|
|
Init => \&ppd_init, |
376
|
|
|
|
|
|
|
Final => \&ppd_final, |
377
|
|
|
|
|
|
|
}, |
378
|
|
|
|
|
|
|
); |
379
|
|
|
|
|
|
|
my $d = $is_a_file ? $p->parsefile($file) : $p->parse($file); |
380
|
|
|
|
|
|
|
my $implem = $d->{IMPLEMENTATION}; |
381
|
|
|
|
|
|
|
my $size = scalar @$implem; |
382
|
|
|
|
|
|
|
if ($size == 1) { |
383
|
|
|
|
|
|
|
$d->{PROVIDE} = $implem->[0]->{PROVIDE} || []; |
384
|
|
|
|
|
|
|
$d->{DEPENDENCY} = $implem->[0]->{DEPENDENCY} || []; |
385
|
|
|
|
|
|
|
$d->{REQUIRE} = $implem->[0]->{DEPENDENCY} || []; |
386
|
|
|
|
|
|
|
$d->{OS}->{NAME} = $implem->[0]->{OS}->{NAME} || ''; |
387
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} = $implem->[0]->{ARCHITECTURE}->{NAME} || ''; |
388
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} = $implem->[0]->{CODEBASE}->{HREF}; |
389
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} = $implem->[0]->{INSTALL}->{EXEC}; |
390
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} = $implem->[0]->{INSTALL}->{SCRIPT}; |
391
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} = $implem->[0]->{INSTALL}->{HREF}; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
elsif (defined $arch) { |
394
|
|
|
|
|
|
|
my $flag = 0; |
395
|
|
|
|
|
|
|
my $i; |
396
|
|
|
|
|
|
|
for ($i=0; $i<$size; $i++) { |
397
|
|
|
|
|
|
|
if ($implem->[$i]->{ARCHITECTURE}->{NAME} eq $arch) { |
398
|
|
|
|
|
|
|
$flag++; |
399
|
|
|
|
|
|
|
last; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
return unless $flag; |
403
|
|
|
|
|
|
|
$d->{PROVIDE} = $implem->[$i]->{PROVIDE} || []; |
404
|
|
|
|
|
|
|
$d->{DEPENDENCY} = $implem->[$i]->{DEPENDENCY} || []; |
405
|
|
|
|
|
|
|
$d->{REQUIRE} = $implem->[$i]->{DEPENDENCY} || []; |
406
|
|
|
|
|
|
|
$d->{OS}->{NAME} = $implem->[$i]->{OS}->{NAME} || ''; |
407
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} = $implem->[$i]->{ARCHITECTURE}->{NAME} || ''; |
408
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} = $implem->[$i]->{CODEBASE}->{HREF}; |
409
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} = $implem->[$i]->{INSTALL}->{EXEC}; |
410
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} = $implem->[$i]->{INSTALL}->{SCRIPT}; |
411
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} = $implem->[$i]->{INSTALL}->{HREF}; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
return $d; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
sub ppd_init { |
417
|
|
|
|
|
|
|
my $self = shift; |
418
|
|
|
|
|
|
|
$i = 0; |
419
|
|
|
|
|
|
|
$self->{_mydata} = { |
420
|
|
|
|
|
|
|
SOFTPKG => {NAME => '', VERSION => ''}, |
421
|
|
|
|
|
|
|
TITLE => '', |
422
|
|
|
|
|
|
|
AUTHOR => '', |
423
|
|
|
|
|
|
|
ABSTRACT => '', |
424
|
|
|
|
|
|
|
PROVIDE => [], |
425
|
|
|
|
|
|
|
IMPLEMENTATION => [], |
426
|
|
|
|
|
|
|
OS => {NAME => ''}, |
427
|
|
|
|
|
|
|
ARCHITECTURE => {NAME => ''}, |
428
|
|
|
|
|
|
|
CODEBASE => {HREF => ''}, |
429
|
|
|
|
|
|
|
DEPENDENCY => [], |
430
|
|
|
|
|
|
|
REQUIRE => [], |
431
|
|
|
|
|
|
|
INSTALL => {EXEC => '', SCRIPT => '', HREF => ''}, |
432
|
|
|
|
|
|
|
wanted => {TITLE => 1, ABSTRACT => 1, AUTHOR => 1}, |
433
|
|
|
|
|
|
|
_current => '', |
434
|
|
|
|
|
|
|
}; |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
sub ppd_start { |
438
|
|
|
|
|
|
|
my ($self, $tag, %attrs) = @_; |
439
|
|
|
|
|
|
|
my $internal = $self->{_mydata}; |
440
|
|
|
|
|
|
|
$internal->{_current} = $tag; |
441
|
|
|
|
|
|
|
SWITCH: { |
442
|
|
|
|
|
|
|
($tag eq 'SOFTPKG') and do { |
443
|
|
|
|
|
|
|
$internal->{SOFTPKG}->{NAME} = $attrs{NAME}; |
444
|
|
|
|
|
|
|
$internal->{SOFTPKG}->{VERSION} = $attrs{VERSION}; |
445
|
|
|
|
|
|
|
last SWITCH; |
446
|
|
|
|
|
|
|
}; |
447
|
|
|
|
|
|
|
($tag eq 'PROVIDE') and do { |
448
|
|
|
|
|
|
|
my $name = $attrs{NAME}; |
449
|
|
|
|
|
|
|
my $version = $attrs{VERSION}; |
450
|
|
|
|
|
|
|
if ($version) { |
451
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{PROVIDE}}, |
452
|
|
|
|
|
|
|
{NAME => $name, VERSION => $version}; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
else { |
455
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{PROVIDE}}, |
456
|
|
|
|
|
|
|
{NAME => $name}; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
last SWITCH; |
459
|
|
|
|
|
|
|
}; |
460
|
|
|
|
|
|
|
($tag eq 'CODEBASE') and do { |
461
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{CODEBASE}->{HREF} = |
462
|
|
|
|
|
|
|
$attrs{HREF}; |
463
|
|
|
|
|
|
|
last SWITCH; |
464
|
|
|
|
|
|
|
}; |
465
|
|
|
|
|
|
|
($tag eq 'OS') and do { |
466
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{OS}->{NAME} = |
467
|
|
|
|
|
|
|
$attrs{NAME}; |
468
|
|
|
|
|
|
|
last SWITCH; |
469
|
|
|
|
|
|
|
}; |
470
|
|
|
|
|
|
|
($tag eq 'ARCHITECTURE') and do { |
471
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{ARCHITECTURE}->{NAME} = |
472
|
|
|
|
|
|
|
$attrs{NAME}; |
473
|
|
|
|
|
|
|
last SWITCH; |
474
|
|
|
|
|
|
|
}; |
475
|
|
|
|
|
|
|
($tag eq 'INSTALL') and do { |
476
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{EXEC} = |
477
|
|
|
|
|
|
|
$attrs{EXEC}; |
478
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{HREF} = |
479
|
|
|
|
|
|
|
$attrs{HREF}; |
480
|
|
|
|
|
|
|
last SWITCH; |
481
|
|
|
|
|
|
|
}; |
482
|
|
|
|
|
|
|
($tag eq 'DEPENDENCY') and do { |
483
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{DEPENDENCY}}, |
484
|
|
|
|
|
|
|
{NAME => $attrs{NAME}, VERSION => $attrs{VERSION}}; |
485
|
|
|
|
|
|
|
last SWITCH; |
486
|
|
|
|
|
|
|
}; |
487
|
|
|
|
|
|
|
($tag eq 'REQUIRE') and do { |
488
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{REQUIRE}}, |
489
|
|
|
|
|
|
|
{NAME => $attrs{NAME}, VERSION => $attrs{VERSION}}; |
490
|
|
|
|
|
|
|
last SWITCH; |
491
|
|
|
|
|
|
|
}; |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
} |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
sub ppd_char { |
496
|
|
|
|
|
|
|
my ($self, $string) = @_; |
497
|
|
|
|
|
|
|
my $internal = $self->{_mydata}; |
498
|
|
|
|
|
|
|
my $tag = $internal->{_current}; |
499
|
|
|
|
|
|
|
if ($tag and $internal->{wanted}->{$tag}) { |
500
|
|
|
|
|
|
|
$internal->{$tag} .= $string; |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
elsif ($tag and $tag eq 'INSTALL') { |
503
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{SCRIPT} .= $string; |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
else { |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
sub ppd_end { |
510
|
|
|
|
|
|
|
my ($self, $tag) = @_; |
511
|
|
|
|
|
|
|
$i++ if ($tag eq 'IMPLEMENTATION'); |
512
|
|
|
|
|
|
|
delete $self->{_mydata}->{_current}; |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
sub ppd_final { |
516
|
|
|
|
|
|
|
my $self = shift; |
517
|
|
|
|
|
|
|
return $self->{_mydata}; |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=item src_and_build |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
Returns the source and build directories used with |
523
|
|
|
|
|
|
|
CPAN.pm, if present. If not, returns those used with PPM, |
524
|
|
|
|
|
|
|
if those are present. If neither of these are available, |
525
|
|
|
|
|
|
|
returns the system temp directory. |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
my ($src_dir, $build_dir)= src_and_build; |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=cut |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
sub src_and_build { |
532
|
|
|
|
|
|
|
return if ($src_dir and $build_dir); |
533
|
|
|
|
|
|
|
SWITCH: { |
534
|
|
|
|
|
|
|
HAS_CPAN and do { |
535
|
|
|
|
|
|
|
$src_dir = $CPAN::Config->{keep_source_where}; |
536
|
|
|
|
|
|
|
$build_dir = $CPAN::Config->{build_dir}; |
537
|
|
|
|
|
|
|
last SWITCH if ($src_dir and $build_dir); |
538
|
|
|
|
|
|
|
}; |
539
|
|
|
|
|
|
|
$src_dir = File::Spec->tmpdir() || '.'; |
540
|
|
|
|
|
|
|
$build_dir = $src_dir; |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=item parse_version |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
Extracts a version string from a module file. |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
my $version = parse_version('C:/Perl/lib/CPAN.pm'); |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=cut |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
# from ExtUtils::MM_Unix |
553
|
|
|
|
|
|
|
sub parse_version { |
554
|
|
|
|
|
|
|
my $parsefile = shift; |
555
|
|
|
|
|
|
|
return unless -e $parsefile; |
556
|
|
|
|
|
|
|
my $version; |
557
|
|
|
|
|
|
|
local $/ = "\n"; |
558
|
|
|
|
|
|
|
my $fh; |
559
|
|
|
|
|
|
|
unless (open($fh, '<', $parsefile)) { |
560
|
|
|
|
|
|
|
$ERROR = "Could not open '$parsefile': $!"; |
561
|
|
|
|
|
|
|
return; |
562
|
|
|
|
|
|
|
} |
563
|
|
|
|
|
|
|
my $inpod = 0; |
564
|
|
|
|
|
|
|
while (<$fh>) { |
565
|
|
|
|
|
|
|
$inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; |
566
|
|
|
|
|
|
|
next if $inpod || /^\s*\#/; |
567
|
|
|
|
|
|
|
chop; |
568
|
|
|
|
|
|
|
# next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/; |
569
|
|
|
|
|
|
|
next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/; |
570
|
|
|
|
|
|
|
my $eval = qq{ |
571
|
|
|
|
|
|
|
package # hide from PAUSE |
572
|
|
|
|
|
|
|
ExtUtils::MakeMaker::_version; |
573
|
|
|
|
|
|
|
no strict; |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
local $1$2; |
576
|
|
|
|
|
|
|
\$$2=undef; do { |
577
|
|
|
|
|
|
|
$_; |
578
|
|
|
|
|
|
|
return \$$2; |
579
|
|
|
|
|
|
|
}; |
580
|
|
|
|
|
|
|
}; |
581
|
|
|
|
|
|
|
local $^W = 0; |
582
|
|
|
|
|
|
|
$version = eval($eval); |
583
|
|
|
|
|
|
|
warn "Could not eval '$eval' in $parsefile: $@" if $@; |
584
|
|
|
|
|
|
|
last; |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
close $fh; |
587
|
|
|
|
|
|
|
return $version; |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
=item parse_abstract |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
Attempt to obtain an abstract from a module file. |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
my $package = 'CPAN'; |
595
|
|
|
|
|
|
|
my $file = 'C:/Perl/lib/CPAN.pm'; |
596
|
|
|
|
|
|
|
my $abstract = parse_abstract($package, $file); |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=cut |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
sub parse_abstract { |
601
|
|
|
|
|
|
|
my ($package, $file) = @_; |
602
|
|
|
|
|
|
|
my $basename = basename($file, qr/\.\w+$/); |
603
|
|
|
|
|
|
|
(my $stripped = $basename) =~ s!\.\w+$!!; |
604
|
|
|
|
|
|
|
(my $trans = $package) =~ s!-!::!g; |
605
|
|
|
|
|
|
|
my $result; |
606
|
|
|
|
|
|
|
my $inpod = 0; |
607
|
|
|
|
|
|
|
open(my $fh, '<', $file) or die "Couldn't open $file: $!"; |
608
|
|
|
|
|
|
|
while (<$fh>) { |
609
|
|
|
|
|
|
|
$inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; |
610
|
|
|
|
|
|
|
next if !$inpod; |
611
|
|
|
|
|
|
|
chop; |
612
|
|
|
|
|
|
|
next unless /^\s*($package|$basename|$stripped|$trans)\s+--*\s+(.*)/; |
613
|
|
|
|
|
|
|
$result = $2; |
614
|
|
|
|
|
|
|
last; |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
close($fh); |
617
|
|
|
|
|
|
|
return unless $result; |
618
|
|
|
|
|
|
|
chomp($result); |
619
|
|
|
|
|
|
|
return $result; |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=item cpan_file { |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
Given a file of the form C and a CPAN id |
625
|
|
|
|
|
|
|
of the form , will return the CPAN file |
626
|
|
|
|
|
|
|
C. |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
my $cpanid = 'GBARR'; |
629
|
|
|
|
|
|
|
my $file = 'libnet-1.23.tar.gz'; |
630
|
|
|
|
|
|
|
my $cpan_file = cpan_file($cpanid, $file); |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=cut |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
sub cpan_file { |
635
|
|
|
|
|
|
|
my ($cpanid, $file) = @_; |
636
|
|
|
|
|
|
|
return $file if $file =~ m!/!; |
637
|
|
|
|
|
|
|
(my $cpan_loc = $cpanid) =~ s{^(\w)(\w)(.*)}{$1/$1$2/$1$2$3}; |
638
|
|
|
|
|
|
|
return qq{$cpan_loc/$file}; |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item url_list |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
Gets a list of CPAN mirrors, incorporating any from CPAN.pm. |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
my @list = url_list(); |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=cut |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
sub url_list { |
650
|
|
|
|
|
|
|
my @urls; |
651
|
|
|
|
|
|
|
if (HAS_CPAN and defined $CPAN::Config->{urllist} and |
652
|
|
|
|
|
|
|
ref($CPAN::Config->{urllist}) eq 'ARRAY') { |
653
|
|
|
|
|
|
|
push @urls, @{$CPAN::Config->{urllist}}; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
push @urls, 'ftp://ftp.cpan.org', 'http://www.cpan.org'; |
656
|
|
|
|
|
|
|
return @urls; |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
=item mirror |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
Gets a file from a remote source and store it to a local file. |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
my $success = getstore($url, $file); |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
=cut |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
sub mirror { |
668
|
|
|
|
|
|
|
my ($url, $file) = @_; |
669
|
|
|
|
|
|
|
my $ua = HTTP::Tiny->new(agent => "PPM-Make/$VERSION"); |
670
|
|
|
|
|
|
|
my $res = $ua->mirror($url, $file); |
671
|
|
|
|
|
|
|
$res->{success} ? 1 : 0; |
672
|
|
|
|
|
|
|
} |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
1; |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
__END__ |