This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to CPAN-1.76_61
[perl5.git] / lib / CPAN / bin / cpan
1 #!/usr/bin/perl
2 # $Id: cpan,v 1.3 2002/08/30 08:55:15 k Exp $
3 use strict;
4
5 =head1 NAME
6
7 cpan - easily interact with CPAN from the command line
8
9 =head1 SYNOPSIS
10
11         # with arguments, installs specified modules
12         cpan module_name [ module_name ... ]
13         
14         # with switches, installs modules with extra behavior
15         cpan [-cimt] module_name [ module_name ... ]
16         
17         # without arguments, starts CPAN shell
18         cpan
19         
20         # without arguments, but some switches
21         cpan [-ahrv]
22
23 =head1 DESCRIPTION
24
25 This script provides a command interface (not a shell) to CPAN.pm.
26
27 =head2 Meta Options
28
29 These options are mutually exclusive, and the script processes
30 them in this order: [ahvr].  Once the script finds one, it ignores
31 the others, and then exits after it finishes the task.  The script
32 ignores any other command line options.
33
34 =over 4
35
36 =item -a
37
38 Creates the CPAN.pm autobundle with CPAN::Shell->autobundle.  
39
40 =item -h
41
42 Prints a help message.
43
44 =item -r
45
46 Recompiles dynamically loaded modules with CPAN::Shell->recompile.
47
48 =item -v
49
50 Print the script version and CPAN.pm version.
51
52 =back
53
54 =head2 Module options
55
56 These options are mutually exclusive, and the script processes
57 them in alphabetical order. 
58
59 =over 4
60
61 =item c
62
63 Runs a `make clean` in the specified module's directories.
64
65 =item i
66
67 Installed the specified modules.
68
69 =item m
70
71 Makes the specified modules.
72
73 =item t
74
75 Runs a `make test` on the specified modules.
76
77 =back
78
79 =head2 Examples
80
81         # print a help message
82         cpan -h
83         
84         # print the version numbers
85         cpan -v
86         
87         # create an autobundle
88         cpan -a
89         
90         # recompile modules
91         cpan -r 
92         
93         # install modules
94         cpan -i Netscape::Booksmarks Business::ISBN
95
96 =head1 TO DO
97
98 * add options for other CPAN::Shell functions
99 autobundle, clean, make, recompile, test
100
101 =head1 BUGS
102
103 * none noted
104
105 =head1 SEE ALSO
106
107 Most behaviour, including environment variables and configuration,
108 comes directly from CPAN.pm.
109
110 =head1 AUTHOR
111
112 brian d foy <bdfoy@cpan.org>
113
114 =cut
115
116 use CPAN ();
117 use Getopt::Std;
118
119 my $VERSION = sprintf "%.3f", 1.2 + substr(q$Rev: 228 $,4)/1000;
120
121 my $Default = 'default';
122
123 my $META_OPTIONS = 'ahvr';
124
125 my %CPAN_METHODS = (
126         $Default => 'install',
127         'c'      => 'clean',
128         'i'      => 'install',
129         'm'      => 'make',
130         't'      => 'test',
131         );
132
133 my @cpan_options = grep { $_ ne $Default } sort keys %CPAN_METHODS;
134
135 my $arg_count = @ARGV;
136 my %options;
137
138 Getopt::Std::getopts( 
139         join( '', @cpan_options, $META_OPTIONS ), \%options );
140         
141 if( $options{h} )
142         {
143         print STDERR "Printing help message -- ignoring other arguments\n"
144                 if $arg_count > 1;
145
146         print STDERR "Use perldoc to read the documentation\n";
147         exit 0;
148         }
149 elsif( $options{v} )
150         {
151         print STDERR "Printing version message -- ignoring other arguments\n"
152         
153                 if $arg_count > 1;
154
155         my $CPAN_VERSION = CPAN->VERSION;
156         print STDERR "cpan script version $VERSION\n" .
157                 "CPAN.pm version $CPAN_VERSION\n";
158         exit 0;
159         }
160 elsif( $options{a} )
161         {
162         print "Creating autobundle in ", $CPAN::Config->{cpan_home}, 
163                 "/Bundle\n";
164         print STDERR "Creating autobundle -- ignoring other arguments\n"
165                 if $arg_count > 1;
166
167         CPAN::Shell->autobundle;
168         exit 0;
169         }
170 elsif( $options{r} )
171         {
172         print STDERR "Creating autobundle -- ignoring other arguments\n"
173                 if $arg_count > 1;
174                 
175         CPAN::Shell->recompile;
176         }
177 else
178         {
179         my $switch = '';
180         
181         foreach my $option ( @cpan_options )
182                 {
183                 next unless $options{$option};
184                 $switch = $option;
185                 last;
186                 }
187         
188            if( not $switch and     @ARGV ) { $switch = $Default;     }
189         elsif( not $switch and not @ARGV ) { CPAN::shell(); exit 0;  }  
190         elsif(     $switch and not @ARGV ) 
191                 { die "Nothing to $CPAN_METHODS{$switch}!\n"; }
192
193         my $method = $CPAN_METHODS{$switch};
194         die "CPAN.pm cannot $method!\n" unless CPAN::Shell->can( $method );
195         
196         foreach my $arg ( @ARGV )
197                 {
198                 CPAN::Shell->$method( $arg );
199                 }
200         }
201         
202 1;