develooper Front page | perl.perl5.porters | Postings from March 2003

[patch] utils/cpan => utils/cpan.PL

Thread Next
From:
Stas Bekman
Date:
March 21, 2003 20:25
Subject:
[patch] utils/cpan => utils/cpan.PL
Message ID:
3E7BE55D.8040305@stason.org
bin/cpan gets the wrong path to the perl if it's not /usr/bin/perl. I've 
created utils/cpan.PL copying the perldoc.PL's functionality and updated 
utils/Makefile

(the patch is attached as well as inlined)

of course you will have to nuke utils/cpan if this patch is applied.

This patch is made against maintperl 19041, but I think it should apply 
against blead as well.

--- /dev/null	1970-01-01 10:00:00.000000000 +1000
+++ utils/cpan.PL	2003-03-22 15:18:46.000000000 +1100
@@ -0,0 +1,258 @@
+#!/usr/local/bin/perl
+
+# This is for generating the cpan executable.
+# It may eventually be expanded to generate many executables, as
+# explained in the preface of /Programming Perl/ 3e.
+
+require 5;
+use strict;
+use Config;
+use File::Basename qw(&basename &dirname);
+use Cwd;
+
+# List explicitly here the variables you want Configure to
+# generate.  Metaconfig only looks for shell variables, so you
+# have to mention them as if they were shell variables, not
+# %Config entries.  Thus you write
+#  $startperl
+# to ensure Configure will look for $Config{startperl}.
+
+# This forces PL files to create target in same directory as PL file.
+# This is so that make depend always knows where to find PL derivatives.
+
+my $origdir = cwd;
+chdir dirname($0);
+my $file = basename($0, '.PL');
+my $file_shortname = $file;  # should be like "cpan", maybe "perlsyn", etc.
+warn "How odd, I'm going to generate $file_shortname?!"
+ unless $file_shortname =~ m/^\w+$/;
+
+$file .= '.com' if $^O eq 'VMS';
+
+open OUT,">$file" or die "Can't create $file: $!";
+
+print "Extracting \"$file\" (with variable substitutions)\n";
+
+# In this section, perl variables will be expanded during extraction.
+# You can use $Config{...} to use Configure variables.
+
+print OUT <<"!GROK!THIS!";
+$Config{startperl}
+    eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
+	if 0;
+
+# This "$file" file was generated by "$0"
+!GROK!THIS!
+
+print OUT <<'!GROK!THIS!2';
+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;
+
+
+!GROK!THIS!2
+
+
+close OUT or die "Can't close $file: $!";
+chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
+exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
+chdir $origdir;
+
--- utils/Makefile	2003-03-22 15:11:44.000000000 +1100
+++ utils/Makefile.orig	2003-03-22 15:09:23.000000000 +1100
@@ -5,15 +5,14 @@
  # Files to be built with variable substitution after miniperl is
  # available.  Dependencies handled manually below (for now).

-pl = c2ph.PL cpan.PL h2ph.PL h2xs.PL perlbug.PL perldoc.PL perlivp.PL 
pl2pm.PL splain.PL perlcc.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL
-plextract  = c2ph cpan h2ph h2xs perlbug perldoc perlivp pl2pm splain perlcc 
dprofpp libnetcfg piconv enc2xs
-plextractexe  = ./c2ph ./cpan ./h2ph ./h2xs ./perlbug ./perldoc ./perlivp 
./pl2pm ./splain ./perlcc ./dprofpp ./libnetcfg ./piconv ./enc2xs
+pl = c2ph.PL h2ph.PL h2xs.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL 
splain.PL perlcc.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL
+plextract  = c2ph h2ph h2xs perlbug perldoc perlivp pl2pm splain perlcc 
dprofpp libnetcfg piconv enc2xs
+plextractexe  = ./c2ph ./h2ph ./h2xs ./perlbug ./perldoc ./perlivp ./pl2pm 
./splain ./perlcc ./dprofpp ./libnetcfg ./piconv ./enc2xs

  all: $(plextract)

  compile: all $(plextract)
  	$(REALPERL) -I../lib perlcc -I .. -L .. c2ph -o c2ph.exe -v 10 -log 
../compilelog;
-	$(REALPERL) -I../lib perlcc -I .. -L .. cpan -o cpan.exe -v 10 -log 
../compilelog;
  	$(REALPERL) -I../lib perlcc -I .. -L .. h2ph -o h2ph.exe -v 10 -log 
../compilelog;
  	$(REALPERL) -I../lib perlcc -I .. -L .. h2xs -o h2xs.exe -v 10 -log 
../compilelog;
  	$(REALPERL) -I../lib perlcc -I .. -L .. perlbug -o perlbug.exe -v 10 -log 
../compilelog;
@@ -30,8 +29,6 @@

  c2ph:		c2ph.PL ../config.sh

-cpan:		cpan.PL ../config.sh
-
  h2ph:		h2ph.PL ../config.sh

  h2xs:		h2xs.PL ../config.sh

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About