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