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