line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ExtUtils::AutoInstall; |
2
|
|
|
|
|
|
|
$ExtUtils::AutoInstall::VERSION = '0.63'; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2314
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
5
|
1
|
|
|
1
|
|
5
|
use Cwd (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
6
|
1
|
|
|
1
|
|
27
|
use ExtUtils::MakeMaker (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2129
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
ExtUtils::AutoInstall - Automatic install of dependencies via CPAN |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This document describes version 0.63 of B, |
15
|
|
|
|
|
|
|
released September 12, 2005. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
In F, with L available on the author's system: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use inc::Module::Install; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
name ('Joe-Hacker'); |
24
|
|
|
|
|
|
|
abstract ('Perl Interface to Joe Hacker'); |
25
|
|
|
|
|
|
|
author ('Joe Hacker '); |
26
|
|
|
|
|
|
|
include ('ExtUtils::AutoInstall'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
requires ('Module0'); # mandatory modules |
29
|
|
|
|
|
|
|
features ( |
30
|
|
|
|
|
|
|
-config => { |
31
|
|
|
|
|
|
|
make_args => '--hello', # option(s) for CPAN::Config |
32
|
|
|
|
|
|
|
force => 1, # pseudo-option to force install |
33
|
|
|
|
|
|
|
do_once => 1, # skip previously failed modules |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
'Feature1' => [ |
36
|
|
|
|
|
|
|
'Module2' => '0.1', |
37
|
|
|
|
|
|
|
], |
38
|
|
|
|
|
|
|
'Feature2' => [ |
39
|
|
|
|
|
|
|
'Module3' => '1.0', |
40
|
|
|
|
|
|
|
], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
auto_install(); |
43
|
|
|
|
|
|
|
&WriteAll; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Invoking the resulting F: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
% perl Makefile.PL # interactive behaviour |
48
|
|
|
|
|
|
|
% perl Makefile.PL --defaultdeps # accept default value on prompts |
49
|
|
|
|
|
|
|
% perl Makefile.PL --checkdeps # check only, no Makefile produced |
50
|
|
|
|
|
|
|
% perl Makefile.PL --skipdeps # ignores all dependencies |
51
|
|
|
|
|
|
|
% perl Makefile.PL --testonly # don't write installation targets |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Note that the trailing 'deps' of arguments may be omitted, too. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Using C<--defaultdeps> will make F behave similarly to a regular |
56
|
|
|
|
|
|
|
Makefile.PL file with C dependencies. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
One can use environment variables (see "ENVIRONMENT") below to set a default |
59
|
|
|
|
|
|
|
behavior instead of specifying it in the command line for every invocation |
60
|
|
|
|
|
|
|
of F. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Using F (or F): |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
% make [all|test|install] # install dependencies first |
65
|
|
|
|
|
|
|
% make checkdeps # same as the --checkdeps above |
66
|
|
|
|
|
|
|
% make installdeps # install dependencies only |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 DESCRIPTION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
B lets module writers to specify a more |
71
|
|
|
|
|
|
|
sophisticated form of dependency information than the C |
72
|
|
|
|
|
|
|
option offered by B. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This module works best with the B framework, |
75
|
|
|
|
|
|
|
a drop-in replacement for MakeMaker. However, this module also |
76
|
|
|
|
|
|
|
supports F files based on MakeMaker; see L |
77
|
|
|
|
|
|
|
for instructions. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 Prerequisites and Features |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Prerequisites are grouped into B, and the user could choose |
82
|
|
|
|
|
|
|
yes/no on each one's dependencies; the module writer may also supply a |
83
|
|
|
|
|
|
|
boolean value via C<-default> to specify the default choice. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The B marked by the name C<-core> will double-check with |
86
|
|
|
|
|
|
|
the user, if the user chooses not to install the mandatory modules. |
87
|
|
|
|
|
|
|
This differs from the pre-0.26 'silent install' behaviour. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Starting from version 0.27, if C<-core> is set to the string C |
90
|
|
|
|
|
|
|
(case-insensitive), every feature will be considered mandatory. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The dependencies are expressed as pairs of C => C |
93
|
|
|
|
|
|
|
inside an array reference. If the order does not matter, and there |
94
|
|
|
|
|
|
|
are no C<-default>, C<-tests> or C<-skiptests> directives for that |
95
|
|
|
|
|
|
|
feature, you may also use a hash reference. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 The Installation Process |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Once B has determined which module(s) are needed, |
100
|
|
|
|
|
|
|
it checks whether it's running under the B shell and should |
101
|
|
|
|
|
|
|
therefore let B handle the dependency. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Finally, the C is overridden to perform some additional |
104
|
|
|
|
|
|
|
checks, as well as skips tests associated with disabled features by the |
105
|
|
|
|
|
|
|
C<-tests> option. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The actual installation happens at the end of the C target; |
108
|
|
|
|
|
|
|
both C and C will trigger the installation of |
109
|
|
|
|
|
|
|
required modules. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
If it's not running under B, the installer will probe for an |
112
|
|
|
|
|
|
|
active connection by trying to resolve the domain C, and check |
113
|
|
|
|
|
|
|
for the user's permission to use B. If all went well, a separate |
114
|
|
|
|
|
|
|
B instance is created to install the required modules. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
If you have the B package installed in your system, it is |
117
|
|
|
|
|
|
|
preferred by default over B; it also accepts some extra options |
118
|
|
|
|
|
|
|
(e.g. C<-target =E 'skiptest', -skiptest =E 1> to skip testing). |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
All modules scheduled to be installed will be deleted from C<%INC> |
121
|
|
|
|
|
|
|
first, so B will check the newly installed modules. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Additionally, you could use the C target to install |
124
|
|
|
|
|
|
|
the modules, and the C target to check dependencies |
125
|
|
|
|
|
|
|
without actually installing them; the C |
126
|
|
|
|
|
|
|
command has an equivalent effect. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
If the F itself needs to use an independent module (e.g. |
129
|
|
|
|
|
|
|
B, v1.21 or greater), then use something like below: |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
BEGIN { |
132
|
|
|
|
|
|
|
require ExtUtils::AutoInstall; |
133
|
|
|
|
|
|
|
# the first argument is an arrayref of the -config flags |
134
|
|
|
|
|
|
|
ExtUtils::AutoInstall->install([], 'Acme::KillerApp' => 1.21); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
use Acme::KillerApp 1.21; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
ExtUtils::AutoInstall->import( |
139
|
|
|
|
|
|
|
# ... arguments as usual ... |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Note the version test in the use clause; if you are so close to the |
143
|
|
|
|
|
|
|
cutting edge that B 1.20 is the latest version on CPAN, |
144
|
|
|
|
|
|
|
this will prevent your module from going awry. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 User-Defined Hooks |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
User-defined I and I hooks are |
149
|
|
|
|
|
|
|
available via C and C subroutines, |
150
|
|
|
|
|
|
|
as shown below: |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# pre-install handler; takes $module_name and $version |
153
|
|
|
|
|
|
|
sub MY::preinstall { return 1; } # return false to skip install |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# post-install handler; takes $module_name, $version, $success |
156
|
|
|
|
|
|
|
sub MY::postinstall { return; } # the return value doesn't matter |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Note that since B performs installation at the |
159
|
|
|
|
|
|
|
time of C |
160
|
|
|
|
|
|
|
F), you have to declare those two handlers I the |
161
|
|
|
|
|
|
|
C |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
If the user did not choose to install a module or it already exists on |
164
|
|
|
|
|
|
|
the system, neither of the handlers is invoked. Both handlers are invoked |
165
|
|
|
|
|
|
|
exactly once for each module when installation is attempted. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
C takes two arguments, C<$module_name> and C<$version>; |
168
|
|
|
|
|
|
|
if it returns a false value, installation for that module will be |
169
|
|
|
|
|
|
|
skipped, and C won't be called at all. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
C takes three arguments, C<$module_name>, C<$version> |
172
|
|
|
|
|
|
|
and C<$success>. The last one denotes whether the installation |
173
|
|
|
|
|
|
|
succeeded or not: C<1> means installation completed successfully, C<0> |
174
|
|
|
|
|
|
|
means failure during install, and C means that the installation |
175
|
|
|
|
|
|
|
was not attempted at all, possibly due to connection problems, or that |
176
|
|
|
|
|
|
|
module does not exist on CPAN at all. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 Customized C |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Starting from version 0.43, B supports modules |
181
|
|
|
|
|
|
|
that require a C subroutine in their F. |
182
|
|
|
|
|
|
|
The user-defined C, if present, is responsible for |
183
|
|
|
|
|
|
|
calling C and include the output in |
184
|
|
|
|
|
|
|
its return value. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
For example, the B (database driver) modules for the Perl DBI |
187
|
|
|
|
|
|
|
are required to include the postamble generated by the function |
188
|
|
|
|
|
|
|
C, so their F may contain lines like this: |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub MY::postamble { |
191
|
|
|
|
|
|
|
return &ExtUtils::AutoInstall::postamble . &dbd_postamble; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Note that the B module does not export the |
195
|
|
|
|
|
|
|
C function, so the name should always be fully qualified. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 CAVEATS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
B will add C to your B |
200
|
|
|
|
|
|
|
flags if your effective uid is 0 (root), unless you explicitly disable |
201
|
|
|
|
|
|
|
it by setting B's C configuration option (or the |
202
|
|
|
|
|
|
|
C option of B) to include C. This I |
203
|
|
|
|
|
|
|
cause dependency problems if you are using a fine-tuned directory |
204
|
|
|
|
|
|
|
structure for your site. Please consult L for an explanation |
205
|
|
|
|
|
|
|
in detail. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
If either B or B is available, they will be |
208
|
|
|
|
|
|
|
used to compare the required version with the existing module's version |
209
|
|
|
|
|
|
|
and the CPAN module's. Otherwise it silently falls back to use I. |
210
|
|
|
|
|
|
|
This may cause inconsistent behaviours in pathetic situations. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 NOTES |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Since this module is needed before writing F, it makes little |
215
|
|
|
|
|
|
|
use as a CPAN module; hence each distribution must include it in full. |
216
|
|
|
|
|
|
|
The only alternative I'm aware of, namely prompting in F to |
217
|
|
|
|
|
|
|
force user install it (cf. the B's dependency on |
218
|
|
|
|
|
|
|
B) is not very desirable either. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
The current compromise is to add the bootstrap code listed in the |
221
|
|
|
|
|
|
|
L before every script, but that does not look pretty, and |
222
|
|
|
|
|
|
|
will not work without an Internet connection. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Since we do not want all future options of B to |
225
|
|
|
|
|
|
|
be painfully detected manually like above, this module provides a |
226
|
|
|
|
|
|
|
I mechanism via the C<-version> flag. If a newer version |
227
|
|
|
|
|
|
|
is needed by the F, it will go ahead to fetch a new |
228
|
|
|
|
|
|
|
version, reload it into memory, and pass the arguments forward. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
If you have any suggestions, please let me know. Thanks. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
B uses a single environment variable, |
235
|
|
|
|
|
|
|
C. It is taken as the command line argument |
236
|
|
|
|
|
|
|
passed to F; you could set it to either C<--defaultdeps> or |
237
|
|
|
|
|
|
|
C<--skipdeps> to avoid interactive behaviour. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 EXAMPLES |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 Using MakeMaker with AutoInstall |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
To use this module with L, first make a |
244
|
|
|
|
|
|
|
F subdirectory in the directory containing your |
245
|
|
|
|
|
|
|
L, and put a copy this module under it as |
246
|
|
|
|
|
|
|
F. You can find out where this module |
247
|
|
|
|
|
|
|
has been installed by typing C |
248
|
|
|
|
|
|
|
in the command line. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Your F should look like this: |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# pull in ExtUtils/AutoInstall.pm from 'inc' |
253
|
|
|
|
|
|
|
use lib 'inc'; |
254
|
|
|
|
|
|
|
use ExtUtils::AutoInstall ( |
255
|
|
|
|
|
|
|
-core => [ # mandatory modules |
256
|
|
|
|
|
|
|
'Module0' => '', # any version would suffice |
257
|
|
|
|
|
|
|
], |
258
|
|
|
|
|
|
|
'Feature1' => [ |
259
|
|
|
|
|
|
|
# do we want to install this feature by default? |
260
|
|
|
|
|
|
|
-default => ( system('feature1 --version') == 0 ), |
261
|
|
|
|
|
|
|
Module1 => '0.01', |
262
|
|
|
|
|
|
|
], |
263
|
|
|
|
|
|
|
'Feature2' => [ |
264
|
|
|
|
|
|
|
# associate tests to be disabled if this feature is missing |
265
|
|
|
|
|
|
|
-tests => [ ], |
266
|
|
|
|
|
|
|
# associate tests to be disabled if this feature is present |
267
|
|
|
|
|
|
|
-skiptests => [ ], |
268
|
|
|
|
|
|
|
Module2 => '0.02', |
269
|
|
|
|
|
|
|
], |
270
|
|
|
|
|
|
|
'Feature3' => { # hash reference works, too |
271
|
|
|
|
|
|
|
# force installation even if tests fail |
272
|
|
|
|
|
|
|
Module2 => '0.03', |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
); |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
WriteMakefile( |
277
|
|
|
|
|
|
|
AUTHOR => 'Joe Hacker ', |
278
|
|
|
|
|
|
|
ABSTRACT => 'Perl Interface to Joe Hacker', |
279
|
|
|
|
|
|
|
NAME => 'Joe::Hacker', |
280
|
|
|
|
|
|
|
VERSION_FROM => 'Hacker.pm', |
281
|
|
|
|
|
|
|
DISTNAME => 'Joe-Hacker', |
282
|
|
|
|
|
|
|
); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 Self-Download Code |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
If you do not wish to put a copy of L under |
287
|
|
|
|
|
|
|
F, and are confident that users will have internet access, you |
288
|
|
|
|
|
|
|
may replace the C |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# ExtUtils::AutoInstall Bootstrap Code, version 7. |
291
|
|
|
|
|
|
|
BEGIN{my$p='ExtUtils::AutoInstall';my$v=0.45;$p->VERSION||0>=$v |
292
|
|
|
|
|
|
|
or+eval"use $p $v;1"or+do{my$e=$ENV{PERL_EXTUTILS_AUTOINSTALL}; |
293
|
|
|
|
|
|
|
(!defined($e)||$e!~m/--(?:default|skip|testonly)/and-t STDIN or |
294
|
|
|
|
|
|
|
eval"use ExtUtils::MakeMaker;WriteMakefile(PREREQ_PM=>{'$p',$v} |
295
|
|
|
|
|
|
|
);1"and exit)and print"==> $p $v required. Install it from CP". |
296
|
|
|
|
|
|
|
"AN? [Y/n] "and!~/^n/i and print"*** Installing $p\n"and |
297
|
|
|
|
|
|
|
do{if (eval '$>' and lc(`sudo -V`) =~ /version/){system('sudo', |
298
|
|
|
|
|
|
|
$^X,"-MCPANPLUS","-e","CPANPLUS::install $p");eval"use $p $v;1" |
299
|
|
|
|
|
|
|
||system('sudo', $^X, "-MCPAN", "-e", "CPAN::install $p")}eval{ |
300
|
|
|
|
|
|
|
require CPANPLUS;CPANPLUS::install$p};eval"use $p $v;1"or eval{ |
301
|
|
|
|
|
|
|
require CPAN;CPAN::install$p};eval"use $p $v;1"||die"*** Please |
302
|
|
|
|
|
|
|
manually install $p $v from cpan.org first...\n"}}} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
If the user did not have L installed, the |
305
|
|
|
|
|
|
|
block of code above will automatically download and install it. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
However, due to its space-compressed (and obfuscated) nature, you |
308
|
|
|
|
|
|
|
should think twice before employing this block of code; it is usually |
309
|
|
|
|
|
|
|
much more desirable to just use L instead. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=cut |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
# special map on pre-defined feature sets |
314
|
|
|
|
|
|
|
my %FeatureMap = ( |
315
|
|
|
|
|
|
|
'' => 'Core Features', # XXX: deprecated |
316
|
|
|
|
|
|
|
'-core' => 'Core Features', |
317
|
|
|
|
|
|
|
); |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
# various lexical flags |
320
|
|
|
|
|
|
|
my (@Missing, @Existing, %DisabledTests, $UnderCPAN, $HasCPANPLUS); |
321
|
|
|
|
|
|
|
my ($Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly); |
322
|
|
|
|
|
|
|
my ($PostambleActions, $PostambleUsed); |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
_accept_default(!-t STDIN); # see if it's a non-interactive session |
325
|
|
|
|
|
|
|
_init(); |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub _accept_default { |
328
|
2
|
|
|
2
|
|
9
|
$AcceptDefault = shift; |
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
sub missing_modules { |
332
|
0
|
|
|
0
|
0
|
0
|
return @Missing; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub do_install { |
336
|
0
|
|
|
|
|
0
|
__PACKAGE__->install( |
337
|
0
|
0
|
|
0
|
0
|
0
|
[ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}], |
|
0
|
|
|
|
|
0
|
|
338
|
|
|
|
|
|
|
@Missing, |
339
|
|
|
|
|
|
|
); |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
# initialize various flags, and/or perform install |
343
|
|
|
|
|
|
|
sub _init { |
344
|
1
|
|
50
|
1
|
|
97
|
foreach my $arg (@ARGV, split(/[\s\t]+/, $ENV{PERL_EXTUTILS_AUTOINSTALL} || '')) { |
345
|
0
|
0
|
|
|
|
0
|
if ($arg =~ /^--config=(.*)$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
346
|
0
|
|
|
|
|
0
|
$Config = [ split(',', $1) ]; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
elsif ($arg =~ /^--installdeps=(.*)$/) { |
349
|
0
|
|
|
|
|
0
|
__PACKAGE__->install($Config, @Missing = split(/,/, $1)); |
350
|
0
|
|
|
|
|
0
|
exit 0; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
elsif ($arg =~ /^--default(?:deps)?$/) { |
353
|
0
|
|
|
|
|
0
|
$AcceptDefault = 1; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
elsif ($arg =~ /^--check(?:deps)?$/) { |
356
|
0
|
|
|
|
|
0
|
$CheckOnly = 1; |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
elsif ($arg =~ /^--skip(?:deps)?$/) { |
359
|
0
|
|
|
|
|
0
|
$SkipInstall = 1; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
elsif ($arg =~ /^--test(?:only)?$/) { |
362
|
0
|
|
|
|
|
0
|
$TestOnly = 1; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
# overrides MakeMaker's prompt() to automatically accept the default choice |
368
|
|
|
|
|
|
|
sub _prompt { |
369
|
|
|
|
|
|
|
goto &ExtUtils::MakeMaker::prompt unless $AcceptDefault; |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
my ($prompt, $default) = @_; |
372
|
|
|
|
|
|
|
my $y = ($default =~ /^[Yy]/); |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
print $prompt, ' [', ($y ? 'Y' : 'y'), '/', ($y ? 'n' : 'N'), '] '; |
375
|
|
|
|
|
|
|
print "$default\n"; |
376
|
|
|
|
|
|
|
return $default; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
# the workhorse |
380
|
|
|
|
|
|
|
sub import { |
381
|
1
|
|
|
1
|
|
139
|
my $class = shift; |
382
|
1
|
50
|
|
|
|
7
|
my @args = @_ or return; |
383
|
1
|
|
|
|
|
2
|
my $core_all; |
384
|
|
|
|
|
|
|
|
385
|
1
|
|
|
|
|
24
|
print "*** $class version ".$class->VERSION."\n"; |
386
|
1
|
|
|
|
|
15
|
print "*** Checking for dependencies...\n"; |
387
|
|
|
|
|
|
|
|
388
|
1
|
|
|
|
|
5819
|
my $cwd = Cwd::cwd(); |
389
|
|
|
|
|
|
|
|
390
|
1
|
|
|
|
|
19
|
$Config = []; |
391
|
|
|
|
|
|
|
|
392
|
4
|
|
|
|
|
16
|
my $maxlen = length((sort { length($b) <=> length($a) } |
|
6
|
|
|
|
|
37
|
|
393
|
3
|
|
|
|
|
38
|
grep { /^[^\-]/ } |
394
|
4
|
100
|
|
|
|
33
|
map { ref($_) ? keys %{ref($_) eq 'HASH' ? $_ : +{@{$_}}} : '' } |
|
4
|
50
|
|
|
|
22
|
|
|
4
|
|
|
|
|
24
|
|
395
|
6
|
100
|
|
|
|
58
|
map { +{@args}->{$_} } |
396
|
1
|
|
|
|
|
15
|
grep { /^[^\-]/ or /^-core$/i } keys %{+{@args}})[0]); |
|
1
|
|
|
|
|
31
|
|
397
|
|
|
|
|
|
|
|
398
|
1
|
|
|
|
|
13
|
while (my ($feature, $modules) = splice(@args, 0, 2)) { |
399
|
6
|
|
|
|
|
9
|
my (@required, @tests, @skiptests); |
400
|
6
|
|
|
|
|
7
|
my $default = 1; |
401
|
6
|
|
|
|
|
6
|
my $conflict = 0; |
402
|
|
|
|
|
|
|
|
403
|
6
|
100
|
|
|
|
19
|
if ($feature =~ m/^-(\w+)$/) { |
404
|
3
|
|
|
|
|
13
|
my $option = lc($1); |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
# check for a newer version of myself |
407
|
3
|
100
|
50
|
|
|
18
|
_update_to($modules, @_) and return if $option eq 'version'; |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
# sets CPAN configuration options |
410
|
3
|
100
|
|
|
|
11
|
$Config = $modules if $option eq 'config'; |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
# promote every features to core status |
413
|
3
|
100
|
50
|
|
|
13
|
$core_all = ($modules =~ /^all$/i) and next |
414
|
|
|
|
|
|
|
if $option eq 'core'; |
415
|
|
|
|
|
|
|
|
416
|
3
|
100
|
|
|
|
15
|
next unless $option eq 'core'; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
4
|
|
66
|
|
|
52
|
print "[".($FeatureMap{lc($feature)} || $feature)."]\n"; |
420
|
|
|
|
|
|
|
|
421
|
4
|
100
|
|
|
|
36
|
$modules = [ %{$modules} ] if UNIVERSAL::isa($modules, 'HASH'); |
|
1
|
|
|
|
|
4
|
|
422
|
|
|
|
|
|
|
|
423
|
4
|
50
|
|
|
|
12
|
unshift @$modules, -default => &{shift(@$modules)} |
|
0
|
|
|
|
|
0
|
|
424
|
|
|
|
|
|
|
if (ref($modules->[0]) eq 'CODE'); # XXX: bugward combatability |
425
|
|
|
|
|
|
|
|
426
|
4
|
|
|
|
|
25
|
while (my ($mod, $arg) = splice(@$modules, 0, 2)) { |
427
|
6
|
100
|
|
|
|
59
|
if ($mod =~ m/^-(\w+)$/) { |
428
|
2
|
|
|
|
|
5
|
my $option = lc($1); |
429
|
|
|
|
|
|
|
|
430
|
2
|
100
|
|
|
|
13
|
$default = $arg if ($option eq 'default'); |
431
|
2
|
50
|
|
|
|
6
|
$conflict = $arg if ($option eq 'conflict'); |
432
|
2
|
100
|
|
|
|
5
|
@tests = @{$arg} if ($option eq 'tests'); |
|
1
|
|
|
|
|
8
|
|
433
|
2
|
50
|
|
|
|
6
|
@skiptests = @{$arg} if ($option eq 'skiptests'); |
|
0
|
|
|
|
|
0
|
|
434
|
|
|
|
|
|
|
|
435
|
2
|
|
|
|
|
16
|
next; |
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
|
438
|
4
|
|
|
|
|
21
|
printf("- %-${maxlen}s ...", $mod); |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
# XXX: check for conflicts and uninstalls(!) them. |
441
|
4
|
50
|
100
|
|
|
27
|
if (defined(my $cur = _version_check(_load($mod), $arg ||= 0))) { |
442
|
0
|
0
|
|
|
|
0
|
print "loaded. ($cur".($arg ? " >= $arg" : '').")\n"; |
443
|
0
|
|
|
|
|
0
|
push @Existing, $mod => $arg; |
444
|
0
|
|
|
|
|
0
|
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests; |
|
0
|
|
|
|
|
0
|
|
445
|
|
|
|
|
|
|
} |
446
|
|
|
|
|
|
|
else { |
447
|
4
|
100
|
|
|
|
21
|
print "missing." . ($arg ? " (would need $arg)" : '') . "\n"; |
448
|
4
|
|
|
|
|
41
|
push @required, $mod => $arg; |
449
|
|
|
|
|
|
|
} |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
4
|
50
|
|
|
|
11
|
next unless @required; |
453
|
|
|
|
|
|
|
|
454
|
4
|
|
66
|
|
|
17
|
my $mandatory = ($feature eq '-core' or $core_all); |
455
|
|
|
|
|
|
|
|
456
|
4
|
50
|
33
|
|
|
62
|
if (!$SkipInstall and ($CheckOnly or _prompt( |
|
|
100
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
457
|
|
|
|
|
|
|
qq{==> Auto-install the }. (@required / 2). |
458
|
|
|
|
|
|
|
($mandatory ? ' mandatory' : ' optional'). |
459
|
|
|
|
|
|
|
qq{ module(s) from CPAN?}, $default ? 'y' : 'n', |
460
|
|
|
|
|
|
|
) =~ /^[Yy]/)) { |
461
|
0
|
|
|
|
|
0
|
push (@Missing, @required); |
462
|
0
|
|
|
|
|
0
|
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests; |
|
0
|
|
|
|
|
0
|
|
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
elsif (!$SkipInstall and $default and $mandatory and _prompt( |
466
|
|
|
|
|
|
|
qq{==> The module(s) are mandatory! Really skip?}, 'n', |
467
|
|
|
|
|
|
|
) =~ /^[Nn]/) { |
468
|
1
|
|
|
|
|
194
|
push (@Missing, @required); |
469
|
1
|
|
|
|
|
7
|
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests; |
|
0
|
|
|
|
|
0
|
|
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
else { |
473
|
3
|
|
|
|
|
166
|
$DisabledTests{$_} = 1 for map { glob($_) } @tests; |
|
1
|
|
|
|
|
71
|
|
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
1
|
|
|
|
|
7
|
_check_lock(); # check for $UnderCPAN |
478
|
|
|
|
|
|
|
|
479
|
1
|
50
|
33
|
|
|
19
|
if (@Missing and not ($CheckOnly or $UnderCPAN)) { |
|
|
|
33
|
|
|
|
|
480
|
1
|
|
|
|
|
17
|
require Config; |
481
|
1
|
|
|
|
|
51
|
print "*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n"; |
482
|
|
|
|
|
|
|
# make an educated guess of whether we'll need root permission. |
483
|
1
|
50
|
|
|
|
103
|
print " (You may need to do that as the 'root' user.)\n" if eval '$>'; |
484
|
|
|
|
|
|
|
} |
485
|
1
|
|
|
|
|
11
|
print "*** $class configuration finished.\n"; |
486
|
|
|
|
|
|
|
|
487
|
1
|
|
|
|
|
34
|
chdir $cwd; |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# import to main:: |
490
|
1
|
|
|
1
|
|
9
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3457
|
|
491
|
1
|
50
|
|
|
|
11
|
*{'main::WriteMakefile'} = \&Write if caller(0) eq 'main'; |
|
1
|
|
|
|
|
165
|
|
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
# CPAN.pm is non-reentrant, so check if we're under it and have no CPANPLUS |
495
|
|
|
|
|
|
|
sub _check_lock { |
496
|
1
|
50
|
|
1
|
|
3
|
return unless @Missing; |
497
|
1
|
50
|
|
|
|
3
|
return if _has_cpanplus(); |
498
|
|
|
|
|
|
|
|
499
|
1
|
|
|
|
|
21480
|
require CPAN; CPAN::Config->load; |
|
1
|
|
|
|
|
278474
|
|
500
|
1
|
|
|
|
|
635
|
my $lock = MM->catfile($CPAN::Config->{cpan_home}, ".lock"); |
501
|
|
|
|
|
|
|
|
502
|
1
|
0
|
33
|
|
|
102
|
if (-f $lock and open(LOCK, $lock) |
|
|
0
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
503
|
|
|
|
|
|
|
and ($^O eq 'MSWin32' ? _under_cpan() : == getppid()) |
504
|
|
|
|
|
|
|
and ($CPAN::Config->{prerequisites_policy} || '') ne 'ignore' |
505
|
|
|
|
|
|
|
) { |
506
|
0
|
|
|
|
|
0
|
print << '.'; |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
*** Since we're running under CPAN, I'll just let it take care |
509
|
|
|
|
|
|
|
of the dependency's installation later. |
510
|
|
|
|
|
|
|
. |
511
|
0
|
|
|
|
|
0
|
$UnderCPAN = 1; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
1
|
|
|
|
|
9
|
close LOCK; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
sub install { |
518
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
519
|
|
|
|
|
|
|
|
520
|
0
|
|
|
|
|
0
|
my $i; # used below to strip leading '-' from config keys |
521
|
0
|
0
|
|
|
|
0
|
my @config = (map { s/^-// if ++$i; $_ } @{+shift}); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
522
|
|
|
|
|
|
|
|
523
|
0
|
|
|
|
|
0
|
my (@modules, @installed); |
524
|
0
|
|
|
|
|
0
|
while (my ($pkg, $ver) = splice(@_, 0, 2)) { |
525
|
|
|
|
|
|
|
# grep out those already installed |
526
|
0
|
0
|
|
|
|
0
|
if (defined(_version_check(_load($pkg), $ver))) { |
527
|
0
|
|
|
|
|
0
|
push @installed, $pkg; |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
else { |
530
|
0
|
|
|
|
|
0
|
push @modules, $pkg, $ver; |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
0
|
0
|
|
|
|
0
|
return @installed unless @modules; # nothing to do |
535
|
|
|
|
|
|
|
|
536
|
0
|
|
|
|
|
0
|
print "*** Installing dependencies...\n"; |
537
|
|
|
|
|
|
|
|
538
|
0
|
0
|
|
|
|
0
|
return unless _connected_to('cpan.org'); |
539
|
|
|
|
|
|
|
|
540
|
0
|
|
|
|
|
0
|
my %args = @config; |
541
|
0
|
|
|
|
|
0
|
my %failed; |
542
|
0
|
|
|
|
|
0
|
local *FAILED; |
543
|
0
|
0
|
0
|
|
|
0
|
if ($args{do_once} and open(FAILED, '.#autoinstall.failed')) { |
544
|
0
|
|
|
|
|
0
|
while () { chomp; $failed{$_}++ } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
545
|
0
|
|
|
|
|
0
|
close FAILED; |
546
|
|
|
|
|
|
|
|
547
|
0
|
|
|
|
|
0
|
my @newmod; |
548
|
0
|
|
|
|
|
0
|
while (my ($k, $v) = splice(@modules, 0, 2)) { |
549
|
0
|
0
|
|
|
|
0
|
push @newmod, ($k => $v) unless $failed{$k}; |
550
|
|
|
|
|
|
|
} |
551
|
0
|
|
|
|
|
0
|
@modules = @newmod; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
0
|
0
|
|
|
|
0
|
if (_has_cpanplus()) { |
555
|
0
|
|
|
|
|
0
|
_install_cpanplus(\@modules, \@config); |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
else { |
558
|
0
|
|
|
|
|
0
|
_install_cpan(\@modules, \@config); |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
0
|
|
|
|
|
0
|
print "*** $class installation finished.\n"; |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
# see if we have successfully installed them |
564
|
0
|
|
|
|
|
0
|
while (my ($pkg, $ver) = splice(@modules, 0, 2)) { |
565
|
0
|
0
|
0
|
|
|
0
|
if (defined(_version_check(_load($pkg), $ver))) { |
|
|
0
|
|
|
|
|
|
566
|
0
|
|
|
|
|
0
|
push @installed, $pkg; |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
elsif ($args{do_once} and open(FAILED, '>> .#autoinstall.failed')) { |
569
|
0
|
|
|
|
|
0
|
print FAILED "$pkg\n"; |
570
|
|
|
|
|
|
|
} |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
0
|
0
|
|
|
|
0
|
close FAILED if $args{do_once}; |
574
|
|
|
|
|
|
|
|
575
|
0
|
|
|
|
|
0
|
return @installed; |
576
|
|
|
|
|
|
|
} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
sub _install_cpanplus { |
579
|
0
|
|
|
0
|
|
0
|
my @modules = @{+shift}; |
|
0
|
|
|
|
|
0
|
|
580
|
0
|
|
|
|
|
0
|
my @config = @{+shift}; |
|
0
|
|
|
|
|
0
|
|
581
|
0
|
|
|
|
|
0
|
my $installed = 0; |
582
|
|
|
|
|
|
|
|
583
|
0
|
|
|
|
|
0
|
require CPANPLUS::Backend; |
584
|
0
|
|
|
|
|
0
|
my $cp = CPANPLUS::Backend->new; |
585
|
0
|
|
|
|
|
0
|
my $conf = $cp->configure_object; |
586
|
|
|
|
|
|
|
|
587
|
0
|
0
|
|
|
|
0
|
return unless _can_write( |
|
|
0
|
|
|
|
|
|
588
|
|
|
|
|
|
|
$conf->can('conf') |
589
|
|
|
|
|
|
|
? $conf->get_conf('base') # 0.05x+ |
590
|
|
|
|
|
|
|
: $conf->_get_build('base') # 0.04x |
591
|
|
|
|
|
|
|
); |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
# if we're root, set UNINST=1 to avoid trouble unless user asked for it. |
594
|
0
|
|
0
|
|
|
0
|
my $makeflags = $conf->get_conf('makeflags') || ''; |
595
|
0
|
0
|
|
|
|
0
|
if (UNIVERSAL::isa($makeflags, 'HASH')) { |
596
|
|
|
|
|
|
|
# 0.03+ uses a hashref here |
597
|
0
|
0
|
|
|
|
0
|
$makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST}; |
598
|
|
|
|
|
|
|
} |
599
|
|
|
|
|
|
|
else { |
600
|
|
|
|
|
|
|
# 0.02 and below uses a scalar |
601
|
0
|
0
|
0
|
|
|
0
|
$makeflags = join(' ', split(' ', $makeflags), 'UNINST=1') |
602
|
|
|
|
|
|
|
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' }); |
603
|
|
|
|
|
|
|
} |
604
|
0
|
|
|
|
|
0
|
$conf->set_conf(makeflags => $makeflags); |
605
|
0
|
|
|
|
|
0
|
$conf->set_conf(prereqs => 1); |
606
|
|
|
|
|
|
|
|
607
|
0
|
|
|
|
|
0
|
while (my ($key, $val) = splice(@config, 0, 2)) { |
608
|
0
|
|
|
|
|
0
|
eval { $conf->set_conf($key, $val) }; |
|
0
|
|
|
|
|
0
|
|
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
|
611
|
0
|
|
|
|
|
0
|
my $modtree = $cp->module_tree; |
612
|
0
|
|
|
|
|
0
|
while (my ($pkg, $ver) = splice(@modules, 0, 2)) { |
613
|
0
|
|
|
|
|
0
|
print "*** Installing $pkg...\n"; |
614
|
|
|
|
|
|
|
|
615
|
0
|
0
|
0
|
|
|
0
|
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall; |
616
|
|
|
|
|
|
|
|
617
|
0
|
|
|
|
|
0
|
my $success; |
618
|
0
|
|
|
|
|
0
|
my $obj = $modtree->{$pkg}; |
619
|
|
|
|
|
|
|
|
620
|
0
|
0
|
0
|
|
|
0
|
if ($obj and defined(_version_check($obj->{version}, $ver))) { |
621
|
0
|
|
|
|
|
0
|
my $pathname = $pkg; $pathname =~ s/::/\\W/; |
|
0
|
|
|
|
|
0
|
|
622
|
|
|
|
|
|
|
|
623
|
0
|
|
|
|
|
0
|
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) { |
|
0
|
|
|
|
|
0
|
|
624
|
0
|
|
|
|
|
0
|
delete $INC{$inc}; |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
0
|
|
|
|
|
0
|
my $rv = $cp->install( modules => [ $obj->{module} ]); |
628
|
|
|
|
|
|
|
|
629
|
0
|
0
|
0
|
|
|
0
|
if ($rv and ($rv->{$obj->{module}} or $rv->{ok})) { |
|
|
|
0
|
|
|
|
|
630
|
0
|
|
|
|
|
0
|
print "*** $pkg successfully installed.\n"; |
631
|
0
|
|
|
|
|
0
|
$success = 1; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
else { |
634
|
0
|
|
|
|
|
0
|
print "*** $pkg installation cancelled.\n"; |
635
|
0
|
|
|
|
|
0
|
$success = 0; |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
|
638
|
0
|
|
|
|
|
0
|
$installed += $success; |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
else { |
641
|
0
|
|
|
|
|
0
|
print << "."; |
642
|
|
|
|
|
|
|
*** Could not find a version $ver or above for $pkg; skipping. |
643
|
|
|
|
|
|
|
. |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
|
646
|
0
|
0
|
|
|
|
0
|
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
0
|
|
|
|
|
0
|
return $installed; |
650
|
|
|
|
|
|
|
} |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
sub _install_cpan { |
653
|
0
|
|
|
0
|
|
0
|
my @modules = @{+shift}; |
|
0
|
|
|
|
|
0
|
|
654
|
0
|
|
|
|
|
0
|
my @config = @{+shift}; |
|
0
|
|
|
|
|
0
|
|
655
|
0
|
|
|
|
|
0
|
my $installed = 0; |
656
|
0
|
|
|
|
|
0
|
my %args; |
657
|
|
|
|
|
|
|
|
658
|
0
|
|
|
|
|
0
|
require CPAN; CPAN::Config->load; |
|
0
|
|
|
|
|
0
|
|
659
|
0
|
|
|
|
|
0
|
require Config; |
660
|
|
|
|
|
|
|
|
661
|
0
|
0
|
0
|
|
|
0
|
return unless _can_write(MM->catfile($CPAN::Config->{cpan_home}, 'sources')) |
662
|
|
|
|
|
|
|
and _can_write($Config::Config{sitelib}); |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
# if we're root, set UNINST=1 to avoid trouble unless user asked for it. |
665
|
0
|
|
0
|
|
|
0
|
my $makeflags = $CPAN::Config->{make_install_arg} || ''; |
666
|
0
|
0
|
0
|
|
|
0
|
$CPAN::Config->{make_install_arg} = join(' ', split(' ', $makeflags), 'UNINST=1') |
667
|
|
|
|
|
|
|
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' }); |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
# don't show start-up info |
670
|
0
|
|
|
|
|
0
|
$CPAN::Config->{inhibit_startup_message} = 1; |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
# set additional options |
673
|
0
|
|
|
|
|
0
|
while (my ($opt, $arg) = splice(@config, 0, 2)) { |
674
|
0
|
0
|
|
|
|
0
|
($args{$opt} = $arg, next) |
675
|
|
|
|
|
|
|
if $opt =~ /^force$/; # pseudo-option |
676
|
0
|
|
|
|
|
0
|
$CPAN::Config->{$opt} = $arg; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
0
|
|
|
|
|
0
|
local $CPAN::Config->{prerequisites_policy} = 'follow'; |
680
|
|
|
|
|
|
|
|
681
|
0
|
|
|
|
|
0
|
while (my ($pkg, $ver) = splice(@modules, 0, 2)) { |
682
|
0
|
0
|
0
|
|
|
0
|
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall; |
683
|
|
|
|
|
|
|
|
684
|
0
|
|
|
|
|
0
|
print "*** Installing $pkg...\n"; |
685
|
|
|
|
|
|
|
|
686
|
0
|
|
|
|
|
0
|
my $obj = CPAN::Shell->expand(Module => $pkg); |
687
|
0
|
|
|
|
|
0
|
my $success = 0; |
688
|
|
|
|
|
|
|
|
689
|
0
|
0
|
0
|
|
|
0
|
if ($obj and defined(_version_check($obj->cpan_version, $ver))) { |
690
|
0
|
|
|
|
|
0
|
my $pathname = $pkg; $pathname =~ s/::/\\W/; |
|
0
|
|
|
|
|
0
|
|
691
|
|
|
|
|
|
|
|
692
|
0
|
|
|
|
|
0
|
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) { |
|
0
|
|
|
|
|
0
|
|
693
|
0
|
|
|
|
|
0
|
delete $INC{$inc}; |
694
|
|
|
|
|
|
|
} |
695
|
|
|
|
|
|
|
|
696
|
0
|
0
|
|
|
|
0
|
$obj->force('install') if $args{force}; |
697
|
|
|
|
|
|
|
|
698
|
0
|
|
0
|
|
|
0
|
my $rv = $obj->install || eval { |
699
|
|
|
|
|
|
|
$CPAN::META->instance( |
700
|
|
|
|
|
|
|
'CPAN::Distribution', |
701
|
|
|
|
|
|
|
$obj->cpan_file, |
702
|
|
|
|
|
|
|
)->{install} if $CPAN::META |
703
|
|
|
|
|
|
|
}; |
704
|
|
|
|
|
|
|
|
705
|
0
|
0
|
|
|
|
0
|
if ($rv eq 'YES') { |
706
|
0
|
|
|
|
|
0
|
print "*** $pkg successfully installed.\n"; |
707
|
0
|
|
|
|
|
0
|
$success = 1; |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
else { |
710
|
0
|
|
|
|
|
0
|
print "*** $pkg installation failed.\n"; |
711
|
0
|
|
|
|
|
0
|
$success = 0; |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
|
714
|
0
|
|
|
|
|
0
|
$installed += $success; |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
else { |
717
|
0
|
|
|
|
|
0
|
print << "."; |
718
|
|
|
|
|
|
|
*** Could not find a version $ver or above for $pkg; skipping. |
719
|
|
|
|
|
|
|
. |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
|
722
|
0
|
0
|
|
|
|
0
|
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall; |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
|
725
|
0
|
|
|
|
|
0
|
return $installed; |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
sub _has_cpanplus { |
729
|
|
|
|
|
|
|
return ( |
730
|
1
|
|
33
|
1
|
|
7
|
$HasCPANPLUS = ( |
731
|
|
|
|
|
|
|
$INC{'CPANPLUS/Config.pm'} or |
732
|
|
|
|
|
|
|
_load('CPANPLUS::Shell::Default') |
733
|
|
|
|
|
|
|
) |
734
|
|
|
|
|
|
|
); |
735
|
|
|
|
|
|
|
} |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
# make guesses on whether we're under the CPAN installation directory |
738
|
|
|
|
|
|
|
sub _under_cpan { |
739
|
0
|
|
|
0
|
|
0
|
require Cwd; |
740
|
0
|
|
|
|
|
0
|
require File::Spec; |
741
|
|
|
|
|
|
|
|
742
|
0
|
|
|
|
|
0
|
my $cwd = File::Spec->canonpath(Cwd::cwd()); |
743
|
0
|
|
|
|
|
0
|
my $cpan = File::Spec->canonpath($CPAN::Config->{cpan_home}); |
744
|
|
|
|
|
|
|
|
745
|
0
|
|
|
|
|
0
|
return (index($cwd, $cpan) > -1); |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
sub _update_to { |
749
|
1
|
|
|
1
|
|
5
|
my $class = __PACKAGE__; |
750
|
1
|
|
|
|
|
4
|
my $ver = shift; |
751
|
|
|
|
|
|
|
|
752
|
1
|
50
|
|
|
|
7
|
return if defined(_version_check(_load($class), $ver)); # no need to upgrade |
753
|
|
|
|
|
|
|
|
754
|
0
|
0
|
|
|
|
0
|
if (_prompt( |
755
|
|
|
|
|
|
|
"==> A newer version of $class ($ver) is required. Install?", 'y' |
756
|
|
|
|
|
|
|
) =~ /^[Nn]/) { |
757
|
0
|
|
|
|
|
0
|
die "*** Please install $class $ver manually.\n"; |
758
|
|
|
|
|
|
|
} |
759
|
|
|
|
|
|
|
|
760
|
0
|
|
|
|
|
0
|
print << "."; |
761
|
|
|
|
|
|
|
*** Trying to fetch it from CPAN... |
762
|
|
|
|
|
|
|
. |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
# install ourselves |
765
|
0
|
0
|
0
|
|
|
0
|
_load($class) and return $class->import(@_) |
766
|
|
|
|
|
|
|
if $class->install([], $class, $ver); |
767
|
|
|
|
|
|
|
|
768
|
0
|
|
|
|
|
0
|
print << '.'; exit 1; |
|
0
|
|
|
|
|
0
|
|
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
*** Cannot bootstrap myself. :-( Installation terminated. |
771
|
|
|
|
|
|
|
. |
772
|
|
|
|
|
|
|
} |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
# check if we're connected to some host, using inet_aton |
775
|
|
|
|
|
|
|
sub _connected_to { |
776
|
0
|
|
|
0
|
|
0
|
my $site = shift; |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
return ( |
779
|
0
|
|
0
|
|
|
0
|
( _load('Socket') and Socket::inet_aton($site) ) or _prompt(qq( |
780
|
|
|
|
|
|
|
*** Your host cannot resolve the domain name '$site', which |
781
|
|
|
|
|
|
|
probably means the Internet connections are unavailable. |
782
|
|
|
|
|
|
|
==> Should we try to install the required module(s) anyway?), 'n' |
783
|
|
|
|
|
|
|
) =~ /^[Yy]/ |
784
|
|
|
|
|
|
|
); |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
# check if a directory is writable; may create it on demand |
788
|
|
|
|
|
|
|
sub _can_write { |
789
|
0
|
|
|
0
|
|
0
|
my $path = shift; |
790
|
0
|
0
|
|
|
|
0
|
mkdir ($path, 0755) unless -e $path; |
791
|
|
|
|
|
|
|
|
792
|
0
|
0
|
|
|
|
0
|
return 1 if -w $path; |
793
|
|
|
|
|
|
|
|
794
|
0
|
|
|
|
|
0
|
print << "."; |
795
|
|
|
|
|
|
|
*** You are not allowed to write to the directory '$path'; |
796
|
|
|
|
|
|
|
the installation may fail due to insufficient permissions. |
797
|
|
|
|
|
|
|
. |
798
|
|
|
|
|
|
|
|
799
|
0
|
0
|
0
|
|
|
0
|
if (eval '$>' and lc(`sudo -V`) =~ /version/ and _prompt(qq( |
|
|
|
0
|
|
|
|
|
800
|
|
|
|
|
|
|
==> Should we try to re-execute the autoinstall process with 'sudo'?), 'y' |
801
|
|
|
|
|
|
|
) =~ /^[Yy]/) { |
802
|
|
|
|
|
|
|
# try to bootstrap ourselves from sudo |
803
|
0
|
|
|
|
|
0
|
print << "."; |
804
|
|
|
|
|
|
|
*** Trying to re-execute the autoinstall process with 'sudo'... |
805
|
|
|
|
|
|
|
. |
806
|
0
|
|
|
|
|
0
|
my $missing = join(',', @Missing); |
807
|
0
|
|
|
|
|
0
|
my $config = join(',', |
808
|
0
|
0
|
|
|
|
0
|
UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config} |
|
0
|
0
|
|
|
|
0
|
|
809
|
|
|
|
|
|
|
) if $Config; |
810
|
|
|
|
|
|
|
|
811
|
0
|
0
|
|
|
|
0
|
return unless system('sudo', $^X, $0, "--config=$config", "--installdeps=$missing"); |
812
|
|
|
|
|
|
|
|
813
|
0
|
|
|
|
|
0
|
print << "."; |
814
|
|
|
|
|
|
|
*** The 'sudo' command exited with error! Resuming... |
815
|
|
|
|
|
|
|
. |
816
|
|
|
|
|
|
|
} |
817
|
|
|
|
|
|
|
|
818
|
0
|
|
|
|
|
0
|
return _prompt(qq( |
819
|
|
|
|
|
|
|
==> Should we try to install the required module(s) anyway?), 'n' |
820
|
|
|
|
|
|
|
) =~ /^[Yy]/ |
821
|
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
# load a module and return the version it reports |
824
|
|
|
|
|
|
|
sub _load { |
825
|
6
|
|
|
6
|
|
9
|
my $mod = pop; # class/instance doesn't matter |
826
|
6
|
|
|
|
|
7
|
my $file = $mod; |
827
|
|
|
|
|
|
|
|
828
|
6
|
|
|
|
|
21
|
$file =~ s|::|/|g; |
829
|
6
|
|
|
|
|
10
|
$file .= '.pm'; |
830
|
|
|
|
|
|
|
|
831
|
6
|
|
|
|
|
6
|
local $@; |
832
|
6
|
|
66
|
|
|
16
|
return eval { require $file; $mod->VERSION } || ($@ ? undef : 0); |
833
|
|
|
|
|
|
|
} |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
# compare two versions, either use Sort::Versions or plain comparison |
836
|
|
|
|
|
|
|
sub _version_check { |
837
|
5
|
|
|
5
|
|
9
|
my ($cur, $min) = @_; |
838
|
5
|
100
|
|
|
|
21
|
return unless defined $cur; |
839
|
|
|
|
|
|
|
|
840
|
1
|
|
|
|
|
4
|
$cur =~ s/\s+$//; |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
# check for version numbers that are not in decimal format |
843
|
1
|
50
|
33
|
|
|
44
|
if (ref($cur) or ref($min) or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
844
|
0
|
0
|
0
|
|
|
0
|
if ($version::VERSION or defined(_load('version'))) { |
|
|
0
|
0
|
|
|
|
|
845
|
|
|
|
|
|
|
# use version.pm if it is installed. |
846
|
0
|
0
|
|
|
|
0
|
return ((version->new($cur) >= version->new($min)) ? $cur : undef); |
847
|
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
|
elsif ($Sort::Versions::VERSION or defined(_load('Sort::Versions'))) { |
849
|
|
|
|
|
|
|
# use Sort::Versions as the sorting algorithm for a.b.c versions |
850
|
0
|
0
|
|
|
|
0
|
return ((Sort::Versions::versioncmp($cur, $min) != -1) ? $cur : undef); |
851
|
|
|
|
|
|
|
} |
852
|
|
|
|
|
|
|
|
853
|
0
|
|
|
|
|
0
|
warn "Cannot reliably compare non-decimal formatted versions.\n". |
854
|
|
|
|
|
|
|
"Please install version.pm or Sort::Versions.\n"; |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
# plain comparison |
858
|
1
|
|
|
|
|
8
|
local $^W = 0; # shuts off 'not numeric' bugs |
859
|
1
|
50
|
|
|
|
17
|
return ($cur >= $min ? $cur : undef); |
860
|
|
|
|
|
|
|
} |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
# nothing; this usage is deprecated. |
863
|
0
|
|
|
0
|
|
0
|
sub main::PREREQ_PM { return {}; } |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
sub _make_args { |
866
|
1
|
|
|
1
|
|
28
|
my %args = @_; |
867
|
|
|
|
|
|
|
|
868
|
1
|
0
|
33
|
|
|
8
|
$args{PREREQ_PM} = { %{$args{PREREQ_PM} || {} }, @Existing, @Missing } |
|
0
|
50
|
|
|
|
0
|
|
869
|
|
|
|
|
|
|
if $UnderCPAN or $TestOnly; |
870
|
|
|
|
|
|
|
|
871
|
1
|
50
|
|
|
|
8
|
if ($args{EXE_FILES}) { |
872
|
1
|
|
|
|
|
1112
|
require ExtUtils::Manifest; |
873
|
1
|
|
|
|
|
6772
|
my $manifest = ExtUtils::Manifest::maniread('MANIFEST'); |
874
|
|
|
|
|
|
|
|
875
|
3
|
|
|
|
|
17
|
$args{EXE_FILES} = [ |
876
|
1
|
|
|
|
|
1136
|
grep { exists $manifest->{$_} } @{$args{EXE_FILES}} |
|
1
|
|
|
|
|
6
|
|
877
|
|
|
|
|
|
|
]; |
878
|
|
|
|
|
|
|
} |
879
|
|
|
|
|
|
|
|
880
|
1
|
|
50
|
|
|
25
|
$args{test}{TESTS} ||= 't/*.t'; |
881
|
1
|
|
|
|
|
8
|
$args{test}{TESTS} = join(' ', grep { |
882
|
1
|
|
|
|
|
106
|
!exists($DisabledTests{$_}) |
883
|
1
|
|
|
|
|
6
|
} map { glob($_) } split(/\s+/, $args{test}{TESTS})); |
884
|
|
|
|
|
|
|
|
885
|
1
|
|
|
|
|
9
|
my $missing = join(',', @Missing); |
886
|
1
|
|
|
|
|
11
|
my $config = join(',', |
887
|
1
|
50
|
|
|
|
9
|
UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config} |
|
0
|
50
|
|
|
|
0
|
|
888
|
|
|
|
|
|
|
) if $Config; |
889
|
|
|
|
|
|
|
|
890
|
1
|
50
|
|
|
|
8
|
$PostambleActions = ( |
891
|
|
|
|
|
|
|
$missing ? "\$(PERL) $0 --config=$config --installdeps=$missing" |
892
|
|
|
|
|
|
|
: "\@\$(NOOP)" |
893
|
|
|
|
|
|
|
); |
894
|
|
|
|
|
|
|
|
895
|
1
|
|
|
|
|
13
|
return %args; |
896
|
|
|
|
|
|
|
} |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
# a wrapper to ExtUtils::MakeMaker::WriteMakefile |
899
|
|
|
|
|
|
|
sub Write { |
900
|
1
|
|
|
1
|
0
|
190
|
require Carp; |
901
|
1
|
50
|
|
|
|
7
|
Carp::croak "WriteMakefile: Need even number of args" if @_ % 2; |
902
|
|
|
|
|
|
|
|
903
|
1
|
50
|
|
|
|
7
|
if ($CheckOnly) { |
904
|
0
|
|
|
|
|
0
|
print << "."; |
905
|
|
|
|
|
|
|
*** Makefile not written in check-only mode. |
906
|
|
|
|
|
|
|
. |
907
|
0
|
|
|
|
|
0
|
return; |
908
|
|
|
|
|
|
|
} |
909
|
|
|
|
|
|
|
|
910
|
1
|
|
|
|
|
4
|
my %args = _make_args(@_); |
911
|
|
|
|
|
|
|
|
912
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
171
|
|
913
|
|
|
|
|
|
|
|
914
|
1
|
|
|
|
|
3
|
$PostambleUsed = 0; |
915
|
1
|
50
|
|
|
|
8
|
local *MY::postamble = \&postamble unless defined &MY::postamble; |
916
|
1
|
|
|
|
|
9
|
ExtUtils::MakeMaker::WriteMakefile(%args); |
917
|
|
|
|
|
|
|
|
918
|
1
|
50
|
|
|
|
14
|
print << "." unless $PostambleUsed; |
919
|
|
|
|
|
|
|
*** WARNING: Makefile written with customized MY::postamble() without |
920
|
|
|
|
|
|
|
including contents from ExtUtils::AutoInstall::postamble() -- |
921
|
|
|
|
|
|
|
auto installation features disabled. Please contact the author. |
922
|
|
|
|
|
|
|
. |
923
|
|
|
|
|
|
|
|
924
|
1
|
|
|
|
|
21
|
return 1; |
925
|
|
|
|
|
|
|
} |
926
|
|
|
|
|
|
|
|
927
|
|
|
|
|
|
|
sub postamble { |
928
|
0
|
|
|
0
|
1
|
|
$PostambleUsed = 1; |
929
|
|
|
|
|
|
|
|
930
|
0
|
|
|
|
|
|
return << "."; |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
config :: installdeps |
933
|
|
|
|
|
|
|
\t\@\$(NOOP) |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
checkdeps :: |
936
|
|
|
|
|
|
|
\t\$(PERL) $0 --checkdeps |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
installdeps :: |
939
|
|
|
|
|
|
|
\t$PostambleActions |
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
. |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
} |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
1; |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
__END__ |