File Coverage

blib/script/cpan
Criterion Covered Total %
statement 18 19 94.7
branch 2 4 50.0
condition 2 2 100.0
subroutine 5 5 100.0
pod n/a
total 27 30 90.0


line stmt bran cond sub pod time code
1             #!/usr/local/bin/perl
2              
3 8 50   8   42463 BEGIN { pop @INC if $INC[-1] eq '.' }
4 8     8   60 use strict;
  8         13  
  8         226  
5 8     8   39 use vars qw($VERSION);
  8         55  
  8         457  
6              
7 8     8   4583 use App::Cpan;
  8         110  
  8         838  
8 8     8   74 use CPAN::Version;
  8         14  
  8         1354598  
9 8         785391 my $minver = '1.64';
10 8 50       120 if ( CPAN::Version->vlt($App::Cpan::VERSION, $minver) ) {
11 0         0 warn "WARNING: your version of App::Cpan is $App::Cpan::VERSION while we would expect at least $minver";
12             }
13 8         28 $VERSION = '1.64';
14              
15 8         98 my $rc = App::Cpan->run( @ARGV );
16              
17             # will this work under Strawberry Perl?
18 6   100     879 exit( $rc || 0 );
19              
20             =head1 NAME
21              
22             cpan - easily interact with CPAN from the command line
23              
24             =head1 SYNOPSIS
25              
26             # with arguments and no switches, installs specified modules
27             cpan module_name [ module_name ... ]
28              
29             # with switches, installs modules with extra behavior
30             cpan [-cfFimtTw] module_name [ module_name ... ]
31              
32             # use local::lib
33             cpan -I module_name [ module_name ... ]
34              
35             # one time mirror override for faster mirrors
36             cpan -p ...
37              
38             # with just the dot, install from the distribution in the
39             # current directory
40             cpan .
41              
42             # without arguments, starts CPAN.pm shell
43             cpan
44              
45             # without arguments, but some switches
46             cpan [-ahpruvACDLOPX]
47              
48             =head1 DESCRIPTION
49              
50             This script provides a command interface (not a shell) to CPAN. At the
51             moment it uses CPAN.pm to do the work, but it is not a one-shot command
52             runner for CPAN.pm.
53              
54             =head2 Options
55              
56             =over 4
57              
58             =item -a
59              
60             Creates a CPAN.pm autobundle with CPAN::Shell->autobundle.
61              
62             =item -A module [ module ... ]
63              
64             Shows the primary maintainers for the specified modules.
65              
66             =item -c module
67              
68             Runs a `make clean` in the specified module's directories.
69              
70             =item -C module [ module ... ]
71              
72             Show the F files for the specified modules
73              
74             =item -D module [ module ... ]
75              
76             Show the module details. This prints one line for each out-of-date module
77             (meaning, modules locally installed but have newer versions on CPAN).
78             Each line has three columns: module name, local version, and CPAN
79             version.
80              
81             =item -f
82              
83             Force the specified action, when it normally would have failed. Use this
84             to install a module even if its tests fail. When you use this option,
85             -i is not optional for installing a module when you need to force it:
86              
87             % cpan -f -i Module::Foo
88              
89             =item -F
90              
91             Turn off CPAN.pm's attempts to lock anything. You should be careful with
92             this since you might end up with multiple scripts trying to muck in the
93             same directory. This isn't so much of a concern if you're loading a special
94             config with C<-j>, and that config sets up its own work directories.
95              
96             =item -g module [ module ... ]
97              
98             Downloads to the current directory the latest distribution of the module.
99              
100             =item -G module [ module ... ]
101              
102             UNIMPLEMENTED
103              
104             Download to the current directory the latest distribution of the
105             modules, unpack each distribution, and create a git repository for each
106             distribution.
107              
108             If you want this feature, check out Yanick Champoux's C
109             distribution.
110              
111             =item -h
112              
113             Print a help message and exit. When you specify C<-h>, it ignores all
114             of the other options and arguments.
115              
116             =item -i module [ module ... ]
117              
118             Install the specified modules. With no other switches, this switch
119             is implied.
120              
121             =item -I
122              
123             Load C (think like C<-I> for loading lib paths). Too bad
124             C<-l> was already taken.
125              
126             =item -j Config.pm
127              
128             Load the file that has the CPAN configuration data. This should have the
129             same format as the standard F file, which defines
130             C<$CPAN::Config> as an anonymous hash.
131              
132             =item -J
133              
134             Dump the configuration in the same format that CPAN.pm uses. This is useful
135             for checking the configuration as well as using the dump as a starting point
136             for a new, custom configuration.
137              
138             =item -l
139              
140             List all installed modules with their versions
141              
142             =item -L author [ author ... ]
143              
144             List the modules by the specified authors.
145              
146             =item -m
147              
148             Make the specified modules.
149              
150             =item -M mirror1,mirror2,...
151              
152             A comma-separated list of mirrors to use for just this run. The C<-P>
153             option can find them for you automatically.
154              
155             =item -n
156              
157             Do a dry run, but don't actually install anything. (unimplemented)
158              
159             =item -O
160              
161             Show the out-of-date modules.
162              
163             =item -p
164              
165             Ping the configured mirrors and print a report
166              
167             =item -P
168              
169             Find the best mirrors you could be using and use them for the current
170             session.
171              
172             =item -r
173              
174             Recompiles dynamically loaded modules with CPAN::Shell->recompile.
175              
176             =item -s
177              
178             Drop in the CPAN.pm shell. This command does this automatically if you don't
179             specify any arguments.
180              
181             =item -t module [ module ... ]
182              
183             Run a `make test` on the specified modules.
184              
185             =item -T
186              
187             Do not test modules. Simply install them.
188              
189             =item -u
190              
191             Upgrade all installed modules. Blindly doing this can really break things,
192             so keep a backup.
193              
194             =item -v
195              
196             Print the script version and CPAN.pm version then exit.
197              
198             =item -V
199              
200             Print detailed information about the cpan client.
201              
202             =item -w
203              
204             UNIMPLEMENTED
205              
206             Turn on cpan warnings. This checks various things, like directory permissions,
207             and tells you about problems you might have.
208              
209             =item -x module [ module ... ]
210              
211             Find close matches to the named modules that you think you might have
212             mistyped. This requires the optional installation of Text::Levenshtein or
213             Text::Levenshtein::Damerau.
214              
215             =item -X
216              
217             Dump all the namespaces to standard output.
218              
219             =back
220              
221             =head2 Examples
222              
223             # print a help message
224             cpan -h
225              
226             # print the version numbers
227             cpan -v
228              
229             # create an autobundle
230             cpan -a
231              
232             # recompile modules
233             cpan -r
234              
235             # upgrade all installed modules
236             cpan -u
237              
238             # install modules ( sole -i is optional )
239             cpan -i Netscape::Booksmarks Business::ISBN
240              
241             # force install modules ( must use -i )
242             cpan -fi CGI::Minimal URI
243              
244             # install modules but without testing them
245             cpan -Ti CGI::Minimal URI
246              
247             =head2 Environment variables
248              
249             There are several components in CPAN.pm that use environment variables.
250             The build tools, L and L use some,
251             while others matter to the levels above them. Some of these are specified
252             by the Perl Toolchain Gang:
253              
254             Lancaster Consensus: L
255              
256             Oslo Consensus: L
257              
258             =over 4
259              
260             =item NONINTERACTIVE_TESTING
261              
262             Assume no one is paying attention and skips prompts for distributions
263             that do that correctly. C sets this to C<1> unless it already
264             has a value (even if that value is false).
265              
266             =item PERL_MM_USE_DEFAULT
267              
268             Use the default answer for a prompted questions. C sets this
269             to C<1> unless it already has a value (even if that value is false).
270              
271             =item CPAN_OPTS
272              
273             As with C, a string of additional C options to
274             add to those you specify on the command line.
275              
276             =item CPANSCRIPT_LOGLEVEL
277              
278             The log level to use, with either the embedded, minimal logger or
279             L if it is installed. Possible values are the same as
280             the C levels: C, C, C, C,
281             C, and C. The default is C.
282              
283             =item GIT_COMMAND
284              
285             The path to the C binary to use for the Git features. The default
286             is C.
287              
288             =back
289              
290             =head1 EXIT VALUES
291              
292             The script exits with zero if it thinks that everything worked, or a
293             positive number if it thinks that something failed. Note, however, that
294             in some cases it has to divine a failure by the output of things it does
295             not control. For now, the exit codes are vague:
296              
297             1 An unknown error
298              
299             2 The was an external problem
300              
301             4 There was an internal problem with the script
302              
303             8 A module failed to install
304              
305             =head1 TO DO
306              
307             * one shot configuration values from the command line
308              
309             =head1 BUGS
310              
311             * none noted
312              
313             =head1 SEE ALSO
314              
315             Most behaviour, including environment variables and configuration,
316             comes directly from CPAN.pm.
317              
318             =head1 SOURCE AVAILABILITY
319              
320             This code is in Github in the CPAN.pm repository:
321              
322             https://github.com/andk/cpanpm
323              
324             The source used to be tracked separately in another GitHub repo,
325             but the canonical source is now in the above repo.
326              
327             =head1 CREDITS
328              
329             Japheth Cleaver added the bits to allow a forced install (-f).
330              
331             Jim Brandt suggest and provided the initial implementation for the
332             up-to-date and Changes features.
333              
334             Adam Kennedy pointed out that exit() causes problems on Windows
335             where this script ends up with a .bat extension
336              
337             =head1 AUTHOR
338              
339             brian d foy, C<< >>
340              
341             =head1 COPYRIGHT
342              
343             Copyright (c) 2001-2015, brian d foy, All Rights Reserved.
344              
345             You may redistribute this under the same terms as Perl itself.
346              
347             =cut
348              
349             1;