Installer: Early check whether the installation directory is writable
[msysgit.git] / bin / cpan
bloba2c678de84597236a2c5ba00cf711b8d80871518
1 #!/usr/bin/perl
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4 #!/usr/bin/perl
5 # $Id: cpan,v 1.3 2002/08/30 08:55:15 k Exp $
6 use strict;
8 =head1 NAME
10 cpan - easily interact with CPAN from the command line
12 =head1 SYNOPSIS
14 # with arguments, installs specified modules
15 cpan module_name [ module_name ... ]
17 # with switches, installs modules with extra behavior
18 cpan [-cimt] module_name [ module_name ... ]
20 # without arguments, starts CPAN shell
21 cpan
23 # without arguments, but some switches
24 cpan [-ahrv]
26 =head1 DESCRIPTION
28 This script provides a command interface (not a shell) to CPAN.pm.
30 =head2 Meta Options
32 These options are mutually exclusive, and the script processes
33 them in this order: [ahvr]. Once the script finds one, it ignores
34 the others, and then exits after it finishes the task. The script
35 ignores any other command line options.
37 =over 4
39 =item -a
41 Creates the CPAN.pm autobundle with CPAN::Shell->autobundle.
43 =item -h
45 Prints a help message.
47 =item -r
49 Recompiles dynamically loaded modules with CPAN::Shell->recompile.
51 =item -v
53 Print the script version and CPAN.pm version.
55 =back
57 =head2 Module options
59 These options are mutually exclusive, and the script processes
60 them in alphabetical order.
62 =over 4
64 =item c
66 Runs a `make clean` in the specified module's directories.
68 =item i
70 Installed the specified modules.
72 =item m
74 Makes the specified modules.
76 =item t
78 Runs a `make test` on the specified modules.
80 =back
82 =head2 Examples
84 # print a help message
85 cpan -h
87 # print the version numbers
88 cpan -v
90 # create an autobundle
91 cpan -a
93 # recompile modules
94 cpan -r
96 # install modules
97 cpan -i Netscape::Booksmarks Business::ISBN
99 =head1 TO DO
101 * add options for other CPAN::Shell functions
102 autobundle, clean, make, recompile, test
104 =head1 BUGS
106 * none noted
108 =head1 SEE ALSO
110 Most behaviour, including environment variables and configuration,
111 comes directly from CPAN.pm.
113 =head1 AUTHOR
115 brian d foy <bdfoy@cpan.org>
117 =cut
119 use CPAN ();
120 use Getopt::Std;
122 my $VERSION =
123 sprintf "%d.%02d", q$Revision: 1.3 $ =~ m/ (\d+) \. (\d+) /xg;
125 my $Default = 'default';
127 my $META_OPTIONS = 'ahvr';
129 my %CPAN_METHODS = (
130 $Default => 'install',
131 'c' => 'clean',
132 'i' => 'install',
133 'm' => 'make',
134 't' => 'test',
137 my @cpan_options = grep { $_ ne $Default } sort keys %CPAN_METHODS;
139 my $arg_count = @ARGV;
140 my %options;
142 Getopt::Std::getopts(
143 join( '', @cpan_options, $META_OPTIONS ), \%options );
145 if( $options{h} )
147 print STDERR "Printing help message -- ignoring other arguments\n"
148 if $arg_count > 1;
150 print STDERR "Use perldoc to read the documentation\n";
151 exit 0;
153 elsif( $options{v} )
155 print STDERR "Printing version message -- ignoring other arguments\n"
157 if $arg_count > 1;
159 my $CPAN_VERSION = CPAN->VERSION;
160 print STDERR "cpan script version $VERSION\n" .
161 "CPAN.pm version $CPAN_VERSION\n";
162 exit 0;
164 elsif( $options{a} )
166 print "Creating autobundle in ", $CPAN::Config->{cpan_home},
167 "/Bundle\n";
168 print STDERR "Creating autobundle -- ignoring other arguments\n"
169 if $arg_count > 1;
171 CPAN::Shell->autobundle;
172 exit 0;
174 elsif( $options{r} )
176 print STDERR "Creating autobundle -- ignoring other arguments\n"
177 if $arg_count > 1;
179 CPAN::Shell->recompile;
181 else
183 my $switch = '';
185 foreach my $option ( @cpan_options )
187 next unless $options{$option};
188 $switch = $option;
189 last;
192 if( not $switch and @ARGV ) { $switch = $Default; }
193 elsif( not $switch and not @ARGV ) { CPAN::shell(); exit 0; }
194 elsif( $switch and not @ARGV )
195 { die "Nothing to $CPAN_METHODS{$switch}!\n"; }
197 my $method = $CPAN_METHODS{$switch};
198 die "CPAN.pm cannot $method!\n" unless CPAN::Shell->can( $method );
200 foreach my $arg ( @ARGV )
202 CPAN::Shell->$method( $arg );