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