File Coverage

blib/lib/ExtUtils/AutoInstall.pm
Criterion Covered Total %
statement 125 301 41.5
branch 53 178 29.7
condition 30 121 24.7
subroutine 15 25 60.0
pod 1 5 20.0
total 224 630 35.5


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 (i.e. before perl parses the remainder of
160             F), you have to declare those two handlers I the
161             C statement for them to take effect.
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