1
- # !/usr/bin/perl
1
+ package App::Cpan ;
2
2
3
- # $Id$
4
3
use strict;
5
-
6
- # BEGIN{ unshift @INC, sub { print "Trying to load $_[1]\n"; 0 }; }
4
+ use warnings;
7
5
8
6
=head1 NAME
9
7
10
- cpan - easily interact with CPAN from the command line
8
+ App::Cpan - easily interact with CPAN from the command line
11
9
12
10
=head1 SYNOPSIS
13
11
@@ -154,53 +152,16 @@ Runs a `make test` on the specified modules.
154
152
Most behaviour, including environment variables and configuration,
155
153
comes directly from CPAN.pm.
156
154
157
- =head1 SOURCE AVAILABILITY
158
-
159
- This source is part of a SourceForge project which always has the
160
- latest sources in CVS, as well as all of the previous releases.
161
-
162
- http://sourceforge.net/projects/brian-d-foy/
163
-
164
- If, for some reason, I disappear from the world, one of the other
165
- members of the project can shepherd this module appropriately.
166
-
167
- =head1 CREDITS
168
-
169
- Japheth Cleaver added the bits to allow a forced install (-f).
170
-
171
- Jim Brandt suggest and provided the initial implementation for the
172
- up-to-date and Changes features.
173
-
174
- Adam Kennedy pointed out that exit() causes problems on Windows
175
- where this script ends up with a .bat extension
176
-
177
- =head1 AUTHOR
178
-
179
- brian d foy, C<< <[email protected] > >>
180
-
181
- =head1 COPYRIGHT
182
-
183
- Copyright (c) 2001-2006, brian d foy, All Rights Reserved.
184
-
185
- You may redistribute this under the same terms as Perl itself.
186
-
187
155
=cut
188
156
189
157
use CPAN ();
190
158
use Getopt::Std;
191
159
192
- my $VERSION = sprintf " %d .%d " , qw( 1 56 ) ;
193
-
194
- if ( $ARGV [0] eq ' install' and @ARGV > 1 )
195
- {
196
- shift @ARGV ;
197
- }
198
-
199
- if ( 0 == @ARGV ) { CPAN::shell(); exit 0 }
160
+ our $VERSION = ' 1.55_01' ;
200
161
201
162
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
202
163
# set up the order of options that we layer over CPAN::Shell
203
- my @META_OPTIONS = qw( h v C A D O L a r j J) ;
164
+ my @META_OPTIONS = qw( h v C A D O L a r j J ) ;
204
165
205
166
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
206
167
# map switches to method names in CPAN::Shell
@@ -221,25 +182,25 @@ my @CPAN_OPTIONS = grep { $_ ne $Default } sort keys %CPAN_METHODS;
221
182
# use this stuff instead of hard-coded indices and values
222
183
my %Method_table = (
223
184
# key => [ sub ref, takes args?, exit value, description ]
224
- h => [ \&_print_help, 0, 0, ' Printing help' ],
225
- v => [ \&_print_version, 0, 0, ' Printing version' ],
226
-
227
- j => [ \&_load_config, 1, 0, ' Use specified config file' ],
228
- J => [ \&_dump_config, 0, 0, ' Dump configuration to stdout' ],
229
-
230
- C => [ \&_show_Changes, 1, 0, ' Showing Changes file' ],
231
- A => [ \&_show_Author, 1, 0, ' Showing Author' ],
232
- D => [ \&_show_Details, 1, 0, ' Showing Details' ],
233
- O => [ \&_show_out_of_date, 0, 0, ' Showing Out of date' ],
234
- L => [ \&_show_author_mods, 1, 0, ' Showing author mods' ],
235
- a => [ \&_create_autobundle, 0, 0, ' Creating autobundle' ],
236
- r => [ \&_recompile, 0, 0, ' Recompiling' ],
237
-
238
- c => [ \&_default, 1, 0, ' Running `make clean`' ],
239
- f => [ \&_default, 1, 0, ' Installing with force' ],
240
- i => [ \&_default, 1, 0, ' Running `make install`' ],
241
- ' m' => [ \&_default, 1, 0, ' Running `make`' ],
242
- t => [ \&_default, 1, 0, ' Running `make test`' ],
185
+ h => [ \&_print_help, 0, 0, ' Printing help' ],
186
+ v => [ \&_print_version, 0, 0, ' Printing version' ],
187
+
188
+ j => [ \&_load_config, 1, 0, ' Use specified config file' ],
189
+ J => [ \&_dump_config, 0, 0, ' Dump configuration to stdout' ],
190
+
191
+ C => [ \&_show_Changes, 1, 0, ' Showing Changes file' ],
192
+ A => [ \&_show_Author, 1, 0, ' Showing Author' ],
193
+ D => [ \&_show_Details, 1, 0, ' Showing Details' ],
194
+ O => [ \&_show_out_of_date, 0, 0, ' Showing Out of date' ],
195
+ L => [ \&_show_author_mods, 1, 0, ' Showing author mods' ],
196
+ a => [ \&_create_autobundle, 0, 0, ' Creating autobundle' ],
197
+ r => [ \&_recompile, 0, 0, ' Recompiling' ],
198
+
199
+ c => [ \&_default, 1, 0, ' Running `make clean`' ],
200
+ f => [ \&_default, 1, 0, ' Installing with force' ],
201
+ i => [ \&_default, 1, 0, ' Running `make install`' ],
202
+ ' m' => [ \&_default, 1, 0, ' Running `make`' ],
203
+ t => [ \&_default, 1, 0, ' Running `make test`' ],
243
204
244
205
);
245
206
@@ -254,69 +215,97 @@ my %Method_table_index = (
254
215
# finally, do some argument processing
255
216
my @option_order = ( @META_OPTIONS , @CPAN_OPTIONS );
256
217
257
- my %options ;
258
- Getopt::Std::getopts(
259
- join ( ' ' ,
260
- map {
261
- $Method_table { $_ }[ $Method_table_index {takes_args } ] ? " $_ :" : $_
262
- } @option_order ), \%options );
263
-
264
-
265
- print Dumper( \%options , \@ARGV );
266
-
267
-
268
- if ( $options {j } )
218
+ sub _stupid_interface_hack_for_non_rtfmers
269
219
{
270
- $Method_table {j }[ $Method_table_index {code } ]-> ( $options {j } );
271
- delete $options {j };
220
+ shift @ARGV if ( $ARGV [0] eq ' install' and @ARGV > 1 )
272
221
}
273
- else
222
+
223
+ sub _process_options
274
224
{
275
- # this is what CPAN.pm would do otherwise
276
- CPAN::HandleConfig-> load(
277
- be_silent => 1,
278
- write_file => 0,
225
+ my %options ;
226
+
227
+ # if no arguments, just drop into the shell
228
+ if ( 0 == @ARGV ) { CPAN::shell(); exit 0 }
229
+
230
+ Getopt::Std::getopts(
231
+ join ( ' ' ,
232
+ map {
233
+ $Method_table { $_ }[ $Method_table_index {takes_args } ] ? " $_ :" : $_
234
+ } @option_order
235
+ ),
236
+
237
+ \%options
279
238
);
239
+
240
+ \%options ;
241
+ }
242
+
243
+ sub _process_setup_options
244
+ {
245
+ my ( $class , $options ) = @_ ;
246
+
247
+ if ( $options -> {j } )
248
+ {
249
+
250
+
251
+ }
252
+ else
253
+ {
254
+ CPAN::HandleConfig-> load;
255
+ }
256
+
257
+ my $option_count = grep { $options -> {$_ } } @option_order ;
258
+ $option_count -= $options -> {' f' }; # don't count force
259
+
260
+ $options -> {i }++ unless $option_count ;
280
261
}
281
262
282
263
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
283
264
# if there are no options, set -i (this line fixes RT ticket 16915)
284
- my $option_count = grep { $options {$_ } } @option_order ;
285
- $option_count -= $options {' f' }; # don't count force
286
265
287
- $options {i }++ unless $option_count ;
266
+
267
+
268
+ =item run()
269
+
270
+ Just do it
271
+
272
+ =cut
273
+
274
+ sub run
275
+ {
276
+ my $class = shift ;
288
277
289
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
290
- # try each of the possible switches until we find one to handle
291
- # print an error message if there are too many switches
292
- # print an error message if there are arguments when there shouldn't be any
293
- foreach my $option ( @option_order )
294
- {
295
- next unless $options {$option };
296
- die unless
297
- ref $Method_table {$option }[ $Method_table_index {code } ] eq ref sub {};
298
-
299
- print " $Method_table {$option }[ $Method_table_index {description} ] " .
300
- " -- ignoring other opitions\n " if $option_count > 1;
301
- print " $Method_table {$option }[ $Method_table_index {description} ] " .
302
- " -- ignoring other arguments\n "
303
- if ( @ARGV && ! $Method_table {$option }[ $Method_table_index {takes_args } ] );
304
-
305
- print " 1. option $option : CPAN home is $CPAN::Config ->{cpan_home}\n " ;
306
- $Method_table {$option }[ $Method_table_index {code } ]-> ( \@ARGV );
307
- print " 2. option $option : CPAN home is $CPAN::Config ->{cpan_home}\n " ;
278
+ $class -> _stupid_interface_hack_for_non_rtfmers;
279
+
280
+ my $options = $class -> _process_options;
308
281
309
- last ;
282
+ $class -> _process_setup_options( $options );
283
+
284
+ foreach my $option ( @option_order )
285
+ {
286
+ next unless $options -> {$option };
287
+ die unless
288
+ ref $Method_table {$option }[ $Method_table_index {code } ] eq ref sub {};
289
+
290
+ # print "$Method_table{$option}[ $Method_table_index{description} ] " .
291
+ # "-- ignoring other opitions\n" if $option_count > 1;
292
+ print " $Method_table {$option }[ $Method_table_index {description} ] " .
293
+ " -- ignoring other arguments\n "
294
+ if ( @ARGV && ! $Method_table {$option }[ $Method_table_index {takes_args } ] );
295
+
296
+ $Method_table {$option }[ $Method_table_index {code } ]-> ( \ @ARGV , $options );
297
+
298
+ last ;
299
+ }
310
300
}
311
301
312
-
313
302
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
314
303
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
315
304
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
316
305
317
306
sub _default
318
307
{
319
- my $args = shift ;
308
+ my ( $args , $options ) = @_ ;
320
309
321
310
my $switch = ' ' ;
322
311
@@ -325,7 +314,7 @@ sub _default
325
314
foreach my $option ( @CPAN_OPTIONS )
326
315
{
327
316
next if $option eq ' f' ;
328
- next unless $options {$option };
317
+ next unless $options -> {$option };
329
318
$switch = $option ;
330
319
last ;
331
320
}
@@ -343,13 +332,12 @@ sub _default
343
332
die " CPAN.pm cannot $method !\n " unless CPAN::Shell-> can( $method );
344
333
345
334
# call the CPAN::Shell method, with force if specified
346
- print " 3. option $method : CPAN home is $CPAN::Config ->{cpan_home}\n " ;
347
335
foreach my $arg ( @$args )
348
336
{
349
- if ( $options {f } ) { CPAN::Shell-> force( $method , $arg ) }
350
- else { CPAN::Shell-> $method ( $arg ) }
337
+ if ( $options -> {f } ) { CPAN::Shell-> force( $method , $arg ) }
338
+ else { CPAN::Shell-> $method ( $arg ) }
351
339
}
352
- print " 4. option $method : CPAN home is $CPAN::Config ->{cpan_home} \n " ;
340
+
353
341
}
354
342
355
343
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -539,3 +527,31 @@ sub _show_author_mods
539
527
}
540
528
541
529
1;
530
+
531
+ =head1 SOURCE AVAILABILITY
532
+
533
+ This code is in Github:
534
+
535
+ git://github.com/briandfoy/cpan_script.git
536
+
537
+ =head1 CREDITS
538
+
539
+ Japheth Cleaver added the bits to allow a forced install (-f).
540
+
541
+ Jim Brandt suggest and provided the initial implementation for the
542
+ up-to-date and Changes features.
543
+
544
+ Adam Kennedy pointed out that exit() causes problems on Windows
545
+ where this script ends up with a .bat extension
546
+
547
+ =head1 AUTHOR
548
+
549
+ brian d foy, C<< <[email protected] > >>
550
+
551
+ =head1 COPYRIGHT
552
+
553
+ Copyright (c) 2001-2008, brian d foy, All Rights Reserved.
554
+
555
+ You may redistribute this under the same terms as Perl itself.
556
+
557
+ =cut
0 commit comments