summaryrefslogtreecommitdiff
path: root/utils/cpan
blob: 38af90526eed655e5f96a177099149325c5be866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/perl
# $Id: cpan,v 1.3 2002/08/30 08:55:15 k Exp $
use strict;

=head1 NAME

cpan - easily interact with CPAN from the command line

=head1 SYNOPSIS

	# with arguments, installs specified modules
	cpan module_name [ module_name ... ]
	
	# with switches, installs modules with extra behavior
	cpan [-cimt] module_name [ module_name ... ]
	
	# without arguments, starts CPAN shell
	cpan
	
	# without arguments, but some switches
	cpan [-ahrv]

=head1 DESCRIPTION

This script provides a command interface (not a shell) to CPAN.pm.

=head2 Meta Options

These options are mutually exclusive, and the script processes
them in this order: [ahvr].  Once the script finds one, it ignores
the others, and then exits after it finishes the task.  The script
ignores any other command line options.

=over 4

=item -a

Creates the CPAN.pm autobundle with CPAN::Shell->autobundle.  

=item -h

Prints a help message.

=item -r

Recompiles dynamically loaded modules with CPAN::Shell->recompile.

=item -v

Print the script version and CPAN.pm version.

=back

=head2 Module options

These options are mutually exclusive, and the script processes
them in alphabetical order. 

=over 4

=item c

Runs a `make clean` in the specified module's directories.

=item i

Installed the specified modules.

=item m

Makes the specified modules.

=item t

Runs a `make test` on the specified modules.

=back

=head2 Examples

	# print a help message
	cpan -h
	
	# print the version numbers
	cpan -v
	
	# create an autobundle
	cpan -a
	
	# recompile modules
	cpan -r 
	
	# install modules
	cpan -i Netscape::Booksmarks Business::ISBN

=head1 TO DO

* add options for other CPAN::Shell functions
autobundle, clean, make, recompile, test

=head1 BUGS

* none noted

=head1 SEE ALSO

Most behaviour, including environment variables and configuration,
comes directly from CPAN.pm.

=head1 AUTHOR

brian d foy <bdfoy@cpan.org>

=cut

use CPAN ();
use Getopt::Std;

my $VERSION = 
	sprintf "%d.%02d", q$Revision: 1.3 $ =~ m/ (\d+) \. (\d+) /xg;

my $Default = 'default';

my $META_OPTIONS = 'ahvr';

my %CPAN_METHODS = (
	$Default => 'install',
	'c'      => 'clean',
	'i'      => 'install',
	'm'      => 'make',
	't'      => 'test',
	);

my @cpan_options = grep { $_ ne $Default } sort keys %CPAN_METHODS;

my $arg_count = @ARGV;
my %options;

Getopt::Std::getopts( 
	join( '', @cpan_options, $META_OPTIONS ), \%options );
	
if( $options{h} )
	{
	print STDERR "Printing help message -- ignoring other arguments\n"
		if $arg_count > 1;

	print STDERR "Use perldoc to read the documentation\n";
	exit 0;
	}
elsif( $options{v} )
	{
	print STDERR "Printing version message -- ignoring other arguments\n"
	
		if $arg_count > 1;

	my $CPAN_VERSION = CPAN->VERSION;
	print STDERR "cpan script version $VERSION\n" .
		"CPAN.pm version $CPAN_VERSION\n";
	exit 0;
	}
elsif( $options{a} )
	{
	print "Creating autobundle in ", $CPAN::Config->{cpan_home}, 
		"/Bundle\n";
	print STDERR "Creating autobundle -- ignoring other arguments\n"
		if $arg_count > 1;

	CPAN::Shell->autobundle;
	exit 0;
	}
elsif( $options{r} )
	{
	print STDERR "Creating autobundle -- ignoring other arguments\n"
		if $arg_count > 1;
		
	CPAN::Shell->recompile;
	}
else
	{
	my $switch = '';
	
	foreach my $option ( @cpan_options )
		{
		next unless $options{$option};
		$switch = $option;
		last;
		}
	
	   if( not $switch and     @ARGV ) { $switch = $Default;     }
	elsif( not $switch and not @ARGV ) { CPAN::shell(); exit 0;  }	
	elsif(     $switch and not @ARGV ) 
		{ die "Nothing to $CPAN_METHODS{$switch}!\n"; }

	my $method = $CPAN_METHODS{$switch};
	die "CPAN.pm cannot $method!\n" unless CPAN::Shell->can( $method );
	
	foreach my $arg ( @ARGV )
		{
		CPAN::Shell->$method( $arg );
		}
	}
	
1;