Skip to content
This repository was archived by the owner on Jul 18, 2018. It is now read-only.

Commit 0287a99

Browse files
author
brian d foy
committed
* moving things around to make this a modulino
1 parent 4727785 commit 0287a99

File tree

6 files changed

+333
-127
lines changed

6 files changed

+333
-127
lines changed

MANIFEST

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Changes
2-
cpan
2+
lib/Cpan.pm
33
Makefile.PL
44
MANIFEST
5+
script/cpan
56
t/compile.t
67
t/pod.t
78
t/pod_coverage.t

MANIFEST.SKIP

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ cpan-.*
1414
.bak$
1515
.old$
1616
\.#
17-
17+
\.git

Makefile.PL

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@ require 5.006;
66
eval "use Test::Manifest 1.14";
77

88
WriteMakefile(
9-
'NAME' => 'cpan-script',
10-
'VERSION' => '1.54',
9+
'NAME' => 'App::Cpan',
10+
'VERSION_FROM' => 'lib/Cpan.pm',
1111
'ABSTRACT' => 'Interact with CPAN from the command line',
12-
1312
'LICENSE' => 'perl',
1413
'AUTHOR' => 'brian d foy <[email protected]>',
1514

16-
'EXE_FILES' => [ 'cpan' ],
17-
18-
'PREREQ_PM' => {
19-
'Test::More' => '0',
15+
'EXE_FILES' => [ 'script/cpan' ],
16+
17+
'PM' => {
18+
'lib/Cpan.pm' => '$(INST_LIBDIR)/Cpan.pm',
2019
},
21-
22-
'MAN1PODS' => {
23-
'cpan' => '$(INST_MAN1DIR)/cpan.1',
20+
21+
'PREREQ_PM' => {
22+
'Test::More' => '0',
23+
'CPAN' => '0',
2424
},
2525

26-
clean => { FILES => '*.bak cpan-*' },
26+
27+
'MAN1PODS' => {},
28+
'MAN3PODS' => {},
29+
30+
clean => { FILES => '*.bak App-* cpan-*' },
2731
);

cpan renamed to lib/Cpan.pm

Lines changed: 128 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#!/usr/bin/perl
1+
package App::Cpan;
22

3-
# $Id$
43
use strict;
5-
6-
#BEGIN{ unshift @INC, sub { print "Trying to load $_[1]\n"; 0 }; }
4+
use warnings;
75

86
=head1 NAME
97
10-
cpan - easily interact with CPAN from the command line
8+
App::Cpan - easily interact with CPAN from the command line
119
1210
=head1 SYNOPSIS
1311
@@ -154,53 +152,16 @@ Runs a `make test` on the specified modules.
154152
Most behaviour, including environment variables and configuration,
155153
comes directly from CPAN.pm.
156154
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-
187155
=cut
188156

189157
use CPAN ();
190158
use Getopt::Std;
191159

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';
200161

201162
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
202163
# 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 );
204165

205166
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
206167
# map switches to method names in CPAN::Shell
@@ -221,25 +182,25 @@ my @CPAN_OPTIONS = grep { $_ ne $Default } sort keys %CPAN_METHODS;
221182
# use this stuff instead of hard-coded indices and values
222183
my %Method_table = (
223184
# 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`' ],
243204

244205
);
245206

@@ -254,69 +215,97 @@ my %Method_table_index = (
254215
# finally, do some argument processing
255216
my @option_order = ( @META_OPTIONS, @CPAN_OPTIONS );
256217

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
269219
{
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 )
272221
}
273-
else
222+
223+
sub _process_options
274224
{
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
279238
);
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;
280261
}
281262

282263
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
283264
# 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
286265

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;
288277

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;
308281

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+
}
310300
}
311301

312-
313302
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
314303
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
315304
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
316305

317306
sub _default
318307
{
319-
my $args = shift;
308+
my( $args, $options ) = @_;
320309

321310
my $switch = '';
322311

@@ -325,7 +314,7 @@ sub _default
325314
foreach my $option ( @CPAN_OPTIONS )
326315
{
327316
next if $option eq 'f';
328-
next unless $options{$option};
317+
next unless $options->{$option};
329318
$switch = $option;
330319
last;
331320
}
@@ -343,13 +332,12 @@ sub _default
343332
die "CPAN.pm cannot $method!\n" unless CPAN::Shell->can( $method );
344333

345334
# call the CPAN::Shell method, with force if specified
346-
print "3. option $method: CPAN home is $CPAN::Config->{cpan_home}\n";
347335
foreach my $arg ( @$args )
348336
{
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 ) }
351339
}
352-
print "4. option $method: CPAN home is $CPAN::Config->{cpan_home}\n";
340+
353341
}
354342

355343
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -539,3 +527,31 @@ sub _show_author_mods
539527
}
540528

541529
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

Comments
 (0)