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