line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PPM::Make::Util; |
2
|
6
|
|
|
6
|
|
36
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
244
|
|
3
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
190
|
|
4
|
6
|
|
|
6
|
|
34
|
use base qw(Exporter); |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
827
|
|
5
|
6
|
|
|
6
|
|
37
|
use File::Basename; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
783
|
|
6
|
6
|
|
|
6
|
|
2256
|
use Safe; |
|
6
|
|
|
|
|
59908
|
|
|
6
|
|
|
|
|
242
|
|
7
|
6
|
|
|
6
|
|
25705
|
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 HAS_PPM HAS_MB 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.9902'; |
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 parse_version $ERROR |
40
|
|
|
|
|
|
|
is_core is_ap_core url_list |
41
|
|
|
|
|
|
|
trim parse_ppd parse_abstract |
42
|
|
|
|
|
|
|
ppd2cpan_version cpan2ppd_version tempfile |
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
|
|
|
|
|
|
|
printf qq{ Checksum for "$file" is %s\n}, |
161
|
|
|
|
|
|
|
($test) ? 'OK.' : 'NOT OK.'; |
162
|
|
|
|
|
|
|
return $test; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
else { |
165
|
|
|
|
|
|
|
$ERROR = qq{Checksum data for "$file" not present.}; |
166
|
|
|
|
|
|
|
return; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item is_core |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Tests to see if a module is part of the core, based on |
173
|
|
|
|
|
|
|
whether or not the file is found within a I type |
174
|
|
|
|
|
|
|
of directory. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my $is_core = is_core('Net::FTP'); |
177
|
|
|
|
|
|
|
print "Net::FTP is a core module" if $is_core; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub is_core { |
182
|
|
|
|
|
|
|
my $m = shift; |
183
|
|
|
|
|
|
|
return unless $m; |
184
|
|
|
|
|
|
|
$m =~ s!::|-!/!g; |
185
|
|
|
|
|
|
|
$m .= '.pm'; |
186
|
|
|
|
|
|
|
my $is_core = (-e File::Spec->catfile($Config{privlibexp}, $m)) ? 1 : 0; |
187
|
|
|
|
|
|
|
return $is_core; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item is_ap_core |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Tests to see if a package is part of the ActivePerl core (at |
193
|
|
|
|
|
|
|
least for recent ActivePerl versions). |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $is_ap_core = is_ap_core('libwin32'); |
196
|
|
|
|
|
|
|
print "libwin32 is a core package" if $is_ap_core; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub is_ap_core { |
201
|
|
|
|
|
|
|
my $p = shift; |
202
|
|
|
|
|
|
|
return unless defined $p; |
203
|
|
|
|
|
|
|
return defined $ap_core{$p} ? 1 : 0; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item trim |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Trims white space. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
my $string = ' This is a sentence. '; |
211
|
|
|
|
|
|
|
my $trimmed = trim($string); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub trim { |
216
|
|
|
|
|
|
|
local $_ = shift; |
217
|
|
|
|
|
|
|
s/^\s*//; |
218
|
|
|
|
|
|
|
s/\s*$//; |
219
|
|
|
|
|
|
|
return $_; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item file_to_dist |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
In scalar context, returns a CPAN distribution name I based |
226
|
|
|
|
|
|
|
on an input file I: |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $file = 'A/AB/ABC/defg-1.23.tar.gz'; |
229
|
|
|
|
|
|
|
my $dist = file_to_dist($file); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
In a list context, returns both the distribution name I |
232
|
|
|
|
|
|
|
and the version number I<1.23>: |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
my $file = 'A/AB/ABC/defg-1.23.tar.gz'; |
235
|
|
|
|
|
|
|
my ($dist, $version) = file_to_dist($cpan_file); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub file_to_dist { |
241
|
|
|
|
|
|
|
my $cpan_file = shift; |
242
|
|
|
|
|
|
|
return unless $cpan_file; |
243
|
|
|
|
|
|
|
my $d = CPAN::DistnameInfo->new($cpan_file); |
244
|
|
|
|
|
|
|
my ($dist, $version) = ($d->dist, $d->version); |
245
|
|
|
|
|
|
|
unless ($dist and $version) { |
246
|
|
|
|
|
|
|
$ERROR = qq{Could not find distribution name from $cpan_file.}; |
247
|
|
|
|
|
|
|
return; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
return wantarray? ($dist, $version) : $dist; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item ppd2cpan_version |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Converts a ppd-type of version string (eg, I<1,23,0,0>) into a ppd one |
255
|
|
|
|
|
|
|
of the form I<1.23>: |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
my $s = "1,23,0,0"; |
258
|
|
|
|
|
|
|
my $v = ppd2cpan_version($v); |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=cut |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub ppd2cpan_version { |
263
|
|
|
|
|
|
|
local $_ = shift; |
264
|
|
|
|
|
|
|
s/(,0)*$//; |
265
|
|
|
|
|
|
|
tr/,/./; |
266
|
|
|
|
|
|
|
return $_; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item cpan2ppd_version |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Converts a cpan-type of version string (eg, I<1.23>) into a ppd one |
272
|
|
|
|
|
|
|
of the form I<1,23,0,0>: |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
my $v = 1.23; |
275
|
|
|
|
|
|
|
my $s = cpan2ppd_version($v); |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub cpan2ppd_version { |
280
|
|
|
|
|
|
|
local $_ = shift; |
281
|
|
|
|
|
|
|
return join ',', (split (/\./, $_), (0)x4)[0..3]; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item parse_ppd |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Parse a I file or a string. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my $ppd = 'package.ppd'; |
290
|
|
|
|
|
|
|
my $d = parse_ppd($ppd); |
291
|
|
|
|
|
|
|
print $d->{ABSTRACT}; |
292
|
|
|
|
|
|
|
print $d->{OS}->{NAME}; |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
my $e = parse_ppd($ppd, 'MSWin32-x86-multi-thread'); |
295
|
|
|
|
|
|
|
print $e->{ABSTRACT}; |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
This routine takes a required argument of a I file containing |
298
|
|
|
|
|
|
|
a I<.ppd> extension or a string and, |
299
|
|
|
|
|
|
|
optionally, an ARCHITECTURE name to restrict the results to. |
300
|
|
|
|
|
|
|
It returns a data structure containing the information of |
301
|
|
|
|
|
|
|
the ppd file or string: |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
$d->{SOFTPKG}->{NAME} |
304
|
|
|
|
|
|
|
$d->{SOFTPKG}->{VERSION} |
305
|
|
|
|
|
|
|
$d->{TITLE} |
306
|
|
|
|
|
|
|
$d->{AUTHOR} |
307
|
|
|
|
|
|
|
$d->{ABSTRACT} |
308
|
|
|
|
|
|
|
$d->{PROVIDE} |
309
|
|
|
|
|
|
|
$d->{DEPENDENCY} |
310
|
|
|
|
|
|
|
$d->{REQUIRE} |
311
|
|
|
|
|
|
|
$d->{OS}->{NAME} |
312
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} |
313
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} |
314
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} |
315
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} |
316
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
The I, I and I tags are array references |
319
|
|
|
|
|
|
|
containing lists of, respectively, the prerequisites required and |
320
|
|
|
|
|
|
|
the modules supplied by the package, with keys of I and |
321
|
|
|
|
|
|
|
I. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
If there is more than one I section in the |
324
|
|
|
|
|
|
|
ppd file, all the results except for the I elements and |
325
|
|
|
|
|
|
|
I, I, and I will be placed in |
326
|
|
|
|
|
|
|
a I<$d-E{IMPLENTATION}> array |
327
|
|
|
|
|
|
|
reference. If an optional second argument is passed to |
328
|
|
|
|
|
|
|
I, this will filter out all implementation |
329
|
|
|
|
|
|
|
sections except for the specified I given by I<$arch>. |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=cut |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
my $i; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub parse_ppd { |
336
|
|
|
|
|
|
|
my $file = shift; |
337
|
|
|
|
|
|
|
my $arch = shift; |
338
|
|
|
|
|
|
|
my $is_a_file = ($file =~ /\.ppd/); |
339
|
|
|
|
|
|
|
if ($is_a_file) { |
340
|
|
|
|
|
|
|
unless (-e $file) { |
341
|
|
|
|
|
|
|
$ERROR = qq{$file not found.}; |
342
|
|
|
|
|
|
|
return; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
my $p = XML::Parser->new(Style => 'Subs', |
346
|
|
|
|
|
|
|
Handlers => {Char => \&ppd_char, |
347
|
|
|
|
|
|
|
Start => \&ppd_start, |
348
|
|
|
|
|
|
|
End => \&ppd_end, |
349
|
|
|
|
|
|
|
Init => \&ppd_init, |
350
|
|
|
|
|
|
|
Final => \&ppd_final, |
351
|
|
|
|
|
|
|
}, |
352
|
|
|
|
|
|
|
); |
353
|
|
|
|
|
|
|
my $d = $is_a_file ? $p->parsefile($file) : $p->parse($file); |
354
|
|
|
|
|
|
|
my $implem = $d->{IMPLEMENTATION}; |
355
|
|
|
|
|
|
|
my $size = scalar @$implem; |
356
|
|
|
|
|
|
|
if ($size == 1) { |
357
|
|
|
|
|
|
|
$d->{PROVIDE} = $implem->[0]->{PROVIDE} || []; |
358
|
|
|
|
|
|
|
$d->{DEPENDENCY} = $implem->[0]->{DEPENDENCY} || []; |
359
|
|
|
|
|
|
|
$d->{REQUIRE} = $implem->[0]->{DEPENDENCY} || []; |
360
|
|
|
|
|
|
|
$d->{OS}->{NAME} = $implem->[0]->{OS}->{NAME} || ''; |
361
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} = $implem->[0]->{ARCHITECTURE}->{NAME} || ''; |
362
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} = $implem->[0]->{CODEBASE}->{HREF}; |
363
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} = $implem->[0]->{INSTALL}->{EXEC}; |
364
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} = $implem->[0]->{INSTALL}->{SCRIPT}; |
365
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} = $implem->[0]->{INSTALL}->{HREF}; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
elsif (defined $arch) { |
368
|
|
|
|
|
|
|
my $flag = 0; |
369
|
|
|
|
|
|
|
my $i; |
370
|
|
|
|
|
|
|
for ($i=0; $i<$size; $i++) { |
371
|
|
|
|
|
|
|
if ($implem->[$i]->{ARCHITECTURE}->{NAME} eq $arch) { |
372
|
|
|
|
|
|
|
$flag++; |
373
|
|
|
|
|
|
|
last; |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
return unless $flag; |
377
|
|
|
|
|
|
|
$d->{PROVIDE} = $implem->[$i]->{PROVIDE} || []; |
378
|
|
|
|
|
|
|
$d->{DEPENDENCY} = $implem->[$i]->{DEPENDENCY} || []; |
379
|
|
|
|
|
|
|
$d->{REQUIRE} = $implem->[$i]->{DEPENDENCY} || []; |
380
|
|
|
|
|
|
|
$d->{OS}->{NAME} = $implem->[$i]->{OS}->{NAME} || ''; |
381
|
|
|
|
|
|
|
$d->{ARCHITECTURE}->{NAME} = $implem->[$i]->{ARCHITECTURE}->{NAME} || ''; |
382
|
|
|
|
|
|
|
$d->{CODEBASE}->{HREF} = $implem->[$i]->{CODEBASE}->{HREF}; |
383
|
|
|
|
|
|
|
$d->{INSTALL}->{EXEC} = $implem->[$i]->{INSTALL}->{EXEC}; |
384
|
|
|
|
|
|
|
$d->{INSTALL}->{SCRIPT} = $implem->[$i]->{INSTALL}->{SCRIPT}; |
385
|
|
|
|
|
|
|
$d->{INSTALL}->{HREF} = $implem->[$i]->{INSTALL}->{HREF}; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
return $d; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
sub ppd_init { |
391
|
|
|
|
|
|
|
my $self = shift; |
392
|
|
|
|
|
|
|
$i = 0; |
393
|
|
|
|
|
|
|
$self->{_mydata} = { |
394
|
|
|
|
|
|
|
SOFTPKG => {NAME => '', VERSION => ''}, |
395
|
|
|
|
|
|
|
TITLE => '', |
396
|
|
|
|
|
|
|
AUTHOR => '', |
397
|
|
|
|
|
|
|
ABSTRACT => '', |
398
|
|
|
|
|
|
|
PROVIDE => [], |
399
|
|
|
|
|
|
|
IMPLEMENTATION => [], |
400
|
|
|
|
|
|
|
OS => {NAME => ''}, |
401
|
|
|
|
|
|
|
ARCHITECTURE => {NAME => ''}, |
402
|
|
|
|
|
|
|
CODEBASE => {HREF => ''}, |
403
|
|
|
|
|
|
|
DEPENDENCY => [], |
404
|
|
|
|
|
|
|
REQUIRE => [], |
405
|
|
|
|
|
|
|
INSTALL => {EXEC => '', SCRIPT => '', HREF => ''}, |
406
|
|
|
|
|
|
|
wanted => {TITLE => 1, ABSTRACT => 1, AUTHOR => 1}, |
407
|
|
|
|
|
|
|
_current => '', |
408
|
|
|
|
|
|
|
}; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
sub ppd_start { |
412
|
|
|
|
|
|
|
my ($self, $tag, %attrs) = @_; |
413
|
|
|
|
|
|
|
my $internal = $self->{_mydata}; |
414
|
|
|
|
|
|
|
$internal->{_current} = $tag; |
415
|
|
|
|
|
|
|
SWITCH: { |
416
|
|
|
|
|
|
|
($tag eq 'SOFTPKG') and do { |
417
|
|
|
|
|
|
|
$internal->{SOFTPKG}->{NAME} = $attrs{NAME}; |
418
|
|
|
|
|
|
|
$internal->{SOFTPKG}->{VERSION} = $attrs{VERSION}; |
419
|
|
|
|
|
|
|
last SWITCH; |
420
|
|
|
|
|
|
|
}; |
421
|
|
|
|
|
|
|
($tag eq 'PROVIDE') and do { |
422
|
|
|
|
|
|
|
my $name = $attrs{NAME}; |
423
|
|
|
|
|
|
|
my $version = $attrs{VERSION}; |
424
|
|
|
|
|
|
|
if ($version) { |
425
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{PROVIDE}}, |
426
|
|
|
|
|
|
|
{NAME => $name, VERSION => $version}; |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
else { |
429
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{PROVIDE}}, |
430
|
|
|
|
|
|
|
{NAME => $name}; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
last SWITCH; |
433
|
|
|
|
|
|
|
}; |
434
|
|
|
|
|
|
|
($tag eq 'CODEBASE') and do { |
435
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{CODEBASE}->{HREF} = |
436
|
|
|
|
|
|
|
$attrs{HREF}; |
437
|
|
|
|
|
|
|
last SWITCH; |
438
|
|
|
|
|
|
|
}; |
439
|
|
|
|
|
|
|
($tag eq 'OS') and do { |
440
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{OS}->{NAME} = |
441
|
|
|
|
|
|
|
$attrs{NAME}; |
442
|
|
|
|
|
|
|
last SWITCH; |
443
|
|
|
|
|
|
|
}; |
444
|
|
|
|
|
|
|
($tag eq 'ARCHITECTURE') and do { |
445
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{ARCHITECTURE}->{NAME} = |
446
|
|
|
|
|
|
|
$attrs{NAME}; |
447
|
|
|
|
|
|
|
last SWITCH; |
448
|
|
|
|
|
|
|
}; |
449
|
|
|
|
|
|
|
($tag eq 'INSTALL') and do { |
450
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{EXEC} = |
451
|
|
|
|
|
|
|
$attrs{EXEC}; |
452
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{HREF} = |
453
|
|
|
|
|
|
|
$attrs{HREF}; |
454
|
|
|
|
|
|
|
last SWITCH; |
455
|
|
|
|
|
|
|
}; |
456
|
|
|
|
|
|
|
($tag eq 'DEPENDENCY') and do { |
457
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{DEPENDENCY}}, |
458
|
|
|
|
|
|
|
{NAME => $attrs{NAME}, VERSION => $attrs{VERSION}}; |
459
|
|
|
|
|
|
|
last SWITCH; |
460
|
|
|
|
|
|
|
}; |
461
|
|
|
|
|
|
|
($tag eq 'REQUIRE') and do { |
462
|
|
|
|
|
|
|
push @{$internal->{IMPLEMENTATION}->[$i]->{REQUIRE}}, |
463
|
|
|
|
|
|
|
{NAME => $attrs{NAME}, VERSION => $attrs{VERSION}}; |
464
|
|
|
|
|
|
|
last SWITCH; |
465
|
|
|
|
|
|
|
}; |
466
|
|
|
|
|
|
|
} |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub ppd_char { |
470
|
|
|
|
|
|
|
my ($self, $string) = @_; |
471
|
|
|
|
|
|
|
my $internal = $self->{_mydata}; |
472
|
|
|
|
|
|
|
my $tag = $internal->{_current}; |
473
|
|
|
|
|
|
|
if ($tag and $internal->{wanted}->{$tag}) { |
474
|
|
|
|
|
|
|
$internal->{$tag} .= $string; |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
elsif ($tag and $tag eq 'INSTALL') { |
477
|
|
|
|
|
|
|
$internal->{IMPLEMENTATION}->[$i]->{INSTALL}->{SCRIPT} .= $string; |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
else { |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
sub ppd_end { |
484
|
|
|
|
|
|
|
my ($self, $tag) = @_; |
485
|
|
|
|
|
|
|
$i++ if ($tag eq 'IMPLEMENTATION'); |
486
|
|
|
|
|
|
|
delete $self->{_mydata}->{_current}; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub ppd_final { |
490
|
|
|
|
|
|
|
my $self = shift; |
491
|
|
|
|
|
|
|
return $self->{_mydata}; |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=item src_and_build |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Returns the source and build directories used with |
497
|
|
|
|
|
|
|
CPAN.pm, if present. If not, returns those used with PPM, |
498
|
|
|
|
|
|
|
if those are present. If neither of these are available, |
499
|
|
|
|
|
|
|
returns the system temp directory. |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
my ($src_dir, $build_dir)= src_and_build; |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
=cut |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
sub src_and_build { |
506
|
|
|
|
|
|
|
return if ($src_dir and $build_dir); |
507
|
|
|
|
|
|
|
SWITCH: { |
508
|
|
|
|
|
|
|
HAS_CPAN and do { |
509
|
|
|
|
|
|
|
$src_dir = $CPAN::Config->{keep_source_where}; |
510
|
|
|
|
|
|
|
$build_dir = $CPAN::Config->{build_dir}; |
511
|
|
|
|
|
|
|
last SWITCH if ($src_dir and $build_dir); |
512
|
|
|
|
|
|
|
}; |
513
|
|
|
|
|
|
|
$src_dir = File::Spec->tmpdir() || '.'; |
514
|
|
|
|
|
|
|
$build_dir = $src_dir; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=item tempfile |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
Generates the name of a random temporary file. |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
my $tmpfile = tempfile; |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=cut |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
sub tempfile { |
527
|
|
|
|
|
|
|
my $rand = int(rand $$); |
528
|
|
|
|
|
|
|
return File::Spec->catfile(File::Spec->tmpdir(), |
529
|
|
|
|
|
|
|
'ppm-make.' . $rand); |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=item parse_version |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
Extracts a version string from a module file. |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
my $version = parse_version('C:/Perl/lib/CPAN.pm'); |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
=cut |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
# from ExtUtils::MM_Unix |
541
|
|
|
|
|
|
|
sub parse_version { |
542
|
|
|
|
|
|
|
my $parsefile = shift; |
543
|
|
|
|
|
|
|
return unless -e $parsefile; |
544
|
|
|
|
|
|
|
my $version; |
545
|
|
|
|
|
|
|
local $/ = "\n"; |
546
|
|
|
|
|
|
|
my $fh; |
547
|
|
|
|
|
|
|
unless (open($fh, '<', $parsefile)) { |
548
|
|
|
|
|
|
|
$ERROR = "Could not open '$parsefile': $!"; |
549
|
|
|
|
|
|
|
return; |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
my $inpod = 0; |
552
|
|
|
|
|
|
|
while (<$fh>) { |
553
|
|
|
|
|
|
|
$inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; |
554
|
|
|
|
|
|
|
next if $inpod || /^\s*\#/; |
555
|
|
|
|
|
|
|
chop; |
556
|
|
|
|
|
|
|
# next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/; |
557
|
|
|
|
|
|
|
next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/; |
558
|
|
|
|
|
|
|
my $eval = qq{ |
559
|
|
|
|
|
|
|
package # hide from PAUSE |
560
|
|
|
|
|
|
|
ExtUtils::MakeMaker::_version; |
561
|
|
|
|
|
|
|
no strict; |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
local $1$2; |
564
|
|
|
|
|
|
|
\$$2=undef; do { |
565
|
|
|
|
|
|
|
$_; |
566
|
|
|
|
|
|
|
return \$$2; |
567
|
|
|
|
|
|
|
}; |
568
|
|
|
|
|
|
|
}; |
569
|
|
|
|
|
|
|
local $^W = 0; |
570
|
|
|
|
|
|
|
$version = eval($eval); |
571
|
|
|
|
|
|
|
warn "Could not eval '$eval' in $parsefile: $@" if $@; |
572
|
|
|
|
|
|
|
last; |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
close $fh; |
575
|
|
|
|
|
|
|
return $version; |
576
|
|
|
|
|
|
|
} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=item parse_abstract |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
Attempt to obtain an abstract from a module file. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
my $package = 'CPAN'; |
583
|
|
|
|
|
|
|
my $file = 'C:/Perl/lib/CPAN.pm'; |
584
|
|
|
|
|
|
|
my $abstract = parse_abstract($package, $file); |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=cut |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
sub parse_abstract { |
589
|
|
|
|
|
|
|
my ($package, $file) = @_; |
590
|
|
|
|
|
|
|
my $basename = basename($file, qr/\.\w+$/); |
591
|
|
|
|
|
|
|
(my $stripped = $basename) =~ s!\.\w+$!!; |
592
|
|
|
|
|
|
|
(my $trans = $package) =~ s!-!::!g; |
593
|
|
|
|
|
|
|
my $result; |
594
|
|
|
|
|
|
|
my $inpod = 0; |
595
|
|
|
|
|
|
|
open(my $fh, '<', $file) or die "Couldn't open $file: $!"; |
596
|
|
|
|
|
|
|
while (<$fh>) { |
597
|
|
|
|
|
|
|
$inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; |
598
|
|
|
|
|
|
|
next if !$inpod; |
599
|
|
|
|
|
|
|
chop; |
600
|
|
|
|
|
|
|
next unless /^\s*($package|$basename|$stripped|$trans)\s+--*\s+(.*)/; |
601
|
|
|
|
|
|
|
$result = $2; |
602
|
|
|
|
|
|
|
last; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
close($fh); |
605
|
|
|
|
|
|
|
return unless $result; |
606
|
|
|
|
|
|
|
chomp($result); |
607
|
|
|
|
|
|
|
return $result; |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=item cpan_file { |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
Given a file of the form C and a CPAN id |
613
|
|
|
|
|
|
|
of the form , will return the CPAN file |
614
|
|
|
|
|
|
|
C. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
my $cpanid = 'GBARR'; |
617
|
|
|
|
|
|
|
my $file = 'libnet-1.23.tar.gz'; |
618
|
|
|
|
|
|
|
my $cpan_file = cpan_file($cpanid, $file); |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=cut |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub cpan_file { |
623
|
|
|
|
|
|
|
my ($cpanid, $file) = @_; |
624
|
|
|
|
|
|
|
return $file if $file =~ m!/!; |
625
|
|
|
|
|
|
|
(my $cpan_loc = $cpanid) =~ s{^(\w)(\w)(.*)}{$1/$1$2/$1$2$3}; |
626
|
|
|
|
|
|
|
return qq{$cpan_loc/$file}; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
=item url_list |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
Gets a list of CPAN mirrors, incorporating any from CPAN.pm. |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
my @list = url_list(); |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
=cut |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
sub url_list { |
638
|
|
|
|
|
|
|
my @urls; |
639
|
|
|
|
|
|
|
if (HAS_CPAN and defined $CPAN::Config->{urllist} and |
640
|
|
|
|
|
|
|
ref($CPAN::Config->{urllist}) eq 'ARRAY') { |
641
|
|
|
|
|
|
|
push @urls, @{$CPAN::Config->{urllist}}; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
push @urls, 'ftp://ftp.cpan.org', 'http://www.cpan.org'; |
644
|
|
|
|
|
|
|
return @urls; |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=item mirror |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
Gets a file from a remote source and store it to a local file. |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
my $success = getstore($url, $file); |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=cut |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
sub mirror { |
656
|
|
|
|
|
|
|
my ($url, $file) = @_; |
657
|
|
|
|
|
|
|
my $ua = HTTP::Tiny->new(agent => "PPM-Make/$VERSION"); |
658
|
|
|
|
|
|
|
my $res = $ua->mirror($url, $file); |
659
|
|
|
|
|
|
|
$res->{success} ? 1 : 0; |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
1; |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
__END__ |