diff options
author | Karl Berry <karl@freefriends.org> | 2012-11-20 18:08:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-11-20 18:08:54 +0000 |
commit | c5add2ea5067382269ae6f19e345fda0b9a7bd21 (patch) | |
tree | 02f512fda46d93079c9dc59c0d76f0e398150f83 /Master/tlpkg/tlperl/lib/App | |
parent | 6c35e87bdc5a3f64833dbbc42e7d42e683db9d5b (diff) |
perl 5.16.2, compiled without optimization for Windows (from siep)
git-svn-id: svn://tug.org/texlive/trunk@28315 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/App')
-rw-r--r-- | Master/tlpkg/tlperl/lib/App/Cpan.pm | 302 |
1 files changed, 151 insertions, 151 deletions
diff --git a/Master/tlpkg/tlperl/lib/App/Cpan.pm b/Master/tlpkg/tlperl/lib/App/Cpan.pm index cfc12908e52..0fce3d3ec15 100644 --- a/Master/tlpkg/tlperl/lib/App/Cpan.pm +++ b/Master/tlpkg/tlperl/lib/App/Cpan.pm @@ -19,11 +19,11 @@ App::Cpan - easily interact with CPAN from the command line # use local::lib cpan -l module_name [ module_name ... ] - + # with just the dot, install from the distribution in the # current directory cpan . - + # without arguments, starts CPAN.pm shell cpan @@ -73,7 +73,7 @@ to install a module even if its tests fail. When you use this option, =item -F -Turn off CPAN.pm's attempts to lock anything. You should be careful with +Turn off CPAN.pm's attempts to lock anything. You should be careful with this since you might end up with multiple scripts trying to muck in the same directory. This isn't so much of a concern if you're loading a special config with C<-j>, and that config sets up its own work directories. @@ -105,7 +105,7 @@ Install the specified modules. =item -j Config.pm Load the file that has the CPAN configuration data. This should have the -same format as the standard F<CPAN/Config.pm> file, which defines +same format as the standard F<CPAN/Config.pm> file, which defines C<$CPAN::Config> as an anonymous hash. =item -J @@ -188,27 +188,27 @@ use File::Basename; use Getopt::Std; -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Internal constants use constant TRUE => 1; use constant FALSE => 0; -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # The return values -use constant HEY_IT_WORKED => 0; +use constant HEY_IT_WORKED => 0; use constant I_DONT_KNOW_WHAT_HAPPENED => 1; # 0b0000_0001 use constant ITS_NOT_MY_FAULT => 2; use constant THE_PROGRAMMERS_AN_IDIOT => 4; use constant A_MODULE_FAILED_TO_INSTALL => 8; -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # set up the order of options that we layer over CPAN::Shell BEGIN { # most of this should be in methods use vars qw( @META_OPTIONS $Default %CPAN_METHODS @CPAN_OPTIONS @option_order %Method_table %Method_table_index ); - + @META_OPTIONS = qw( h v g G C A D O l L a r j: J ); $Default = 'default'; @@ -227,7 +227,7 @@ $Default = 'default'; @option_order = ( @META_OPTIONS, @CPAN_OPTIONS ); -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # map switches to the subroutines in this script, along with other information. # use this stuff instead of hard-coded indices and values sub NO_ARGS () { 0 } @@ -249,7 +249,7 @@ sub GOOD_EXIT () { 0 } # options that do their one thing g => [ \&_download, NO_ARGS, GOOD_EXIT, 'Download the latest distro' ], G => [ \&_gitify, NO_ARGS, GOOD_EXIT, 'Down and gitify the latest distro' ], - + C => [ \&_show_Changes, ARGS, GOOD_EXIT, 'Showing Changes file' ], A => [ \&_show_Author, ARGS, GOOD_EXIT, 'Showing Author' ], D => [ \&_show_Details, ARGS, GOOD_EXIT, 'Showing Details' ], @@ -278,7 +278,7 @@ sub GOOD_EXIT () { 0 } ); } -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # finally, do some argument processing sub _stupid_interface_hack_for_non_rtfmers @@ -286,17 +286,17 @@ sub _stupid_interface_hack_for_non_rtfmers no warnings 'uninitialized'; shift @ARGV if( $ARGV[0] eq 'install' and @ARGV > 1 ) } - + sub _process_options { my %options; - + # if no arguments, just drop into the shell if( 0 == @ARGV ) { CPAN::shell(); exit 0 } else { Getopt::Std::getopts( - join( '', @option_order ), \%options ); + join( '', @option_order ), \%options ); \%options; } } @@ -304,7 +304,7 @@ sub _process_options sub _process_setup_options { my( $class, $options ) = @_; - + if( $options->{j} ) { $Method_table{j}[ $Method_table_index{code} ]->( $options->{j} ); @@ -318,7 +318,7 @@ sub _process_setup_options write_file => 0, ); } - + if( $options->{F} ) { $Method_table{F}[ $Method_table_index{code} ]->( $options->{F} ); @@ -328,7 +328,7 @@ sub _process_setup_options my $option_count = grep { $options->{$_} } @option_order; no warnings 'uninitialized'; $option_count -= $options->{'f'}; # don't count force - + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if there are no options, set -i (this line fixes RT ticket 16915) $options->{i}++ unless $option_count; @@ -339,7 +339,7 @@ sub _process_setup_options Just do it. -The C<run> method returns 0 on success and a postive number on +The C<run> method returns 0 on success and a postive number on failure. See the section on EXIT CODES for details on the values. =cut @@ -367,10 +367,10 @@ sub run $class->_process_setup_options( $options ); OPTION: foreach my $option ( @option_order ) - { + { next unless $options->{$option}; - my( $sub, $takes_args, $description ) = + my( $sub, $takes_args, $description ) = map { $Method_table{$option}[ $Method_table_index{$_} ] } qw( code takes_args ); @@ -382,7 +382,7 @@ sub run $logger->info( "$description -- ignoring other arguments" ) if( @ARGV && ! $takes_args ); - + $return_value = $sub->( \ @ARGV, $options ); last; @@ -402,33 +402,33 @@ sub DESTROY { 1 } sub _init_logger { my $log4perl_loaded = eval "require Log::Log4perl; 1"; - + unless( $log4perl_loaded ) { $logger = Local::Null::Logger->new; return $logger; } - + my $LEVEL = $ENV{CPANSCRIPT_LOGLEVEL} || 'INFO'; - + Log::Log4perl::init( \ <<"HERE" ); log4perl.rootLogger=$LEVEL, A1 log4perl.appender.A1=Log::Log4perl::Appender::Screen log4perl.appender.A1.layout=PatternLayout log4perl.appender.A1.layout.ConversionPattern=%m%n HERE - + $logger = Log::Log4perl->get_logger( 'App::Cpan' ); } - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # sub _default { my( $args, $options ) = @_; - + my $switch = ''; # choose the option that we're going to use @@ -458,12 +458,12 @@ sub _default if( $options->{f} ) { sub { CPAN::Shell->force( $method, @_ ) } } else { sub { CPAN::Shell->$method( @_ ) } } }; - + # How do I handle exit codes for multiple arguments? my $errors = 0; - - foreach my $arg ( @$args ) - { + + foreach my $arg ( @$args ) + { _clear_cpanpm_output(); $action->( $arg ); @@ -473,7 +473,7 @@ sub _default $errors ? I_DONT_KNOW_WHAT_HAPPENED : HEY_IT_WORKED; } -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # =for comment @@ -488,7 +488,7 @@ my $scalar = ''; sub _hook_into_CPANpm_report { no warnings 'redefine'; - + *CPAN::Shell::myprint = sub { my($self,$what) = @_; $scalar .= $what if defined $what; @@ -500,15 +500,15 @@ sub _hook_into_CPANpm_report *CPAN::Shell::mywarn = sub { my($self,$what) = @_; $scalar .= $what if defined $what; - $self->print_ornamented($what, + $self->print_ornamented($what, $CPAN::Config->{colorize_warn}||'bold red on_white' ); }; } - + sub _clear_cpanpm_output { $scalar = '' } - + sub _get_cpanpm_output { $scalar } BEGIN { @@ -522,9 +522,9 @@ my @skip_lines = ( sub _get_cpanpm_last_line { open my($fh), "<", \ $scalar; - + my @lines = <$fh>; - + # This is a bit ugly. Once we examine a line, we have to # examine the line before it and go through all of the same # regexes. I could do something fancy, but this works. @@ -538,9 +538,9 @@ sub _get_cpanpm_last_line } } } - + $logger->debug( "Last interesting line of CPAN.pm output is:\n\t$lines[-1]" ); - + $lines[-1]; } } @@ -548,28 +548,28 @@ sub _get_cpanpm_last_line BEGIN { my $epic_fail_words = join '|', qw( Error stop(?:ping)? problems force not unsupported fail(?:ed)? ); - + sub _cpanpm_output_indicates_failure { my $last_line = _get_cpanpm_last_line(); - + my $result = $last_line =~ /\b(?:$epic_fail_words)\b/i; $result || (); } } - + sub _cpanpm_output_indicates_success { my $last_line = _get_cpanpm_last_line(); - + my $result = $last_line =~ /\b(?:\s+-- OK|PASS)\b/; $result || (); } - + sub _cpanpm_output_is_vague { - return FALSE if - _cpanpm_output_indicates_failure() || + return FALSE if + _cpanpm_output_indicates_failure() || _cpanpm_output_indicates_success(); return TRUE; @@ -577,24 +577,24 @@ sub _cpanpm_output_is_vague } -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # sub _print_help { $logger->info( "Use perldoc to read the documentation" ); exec "perldoc $0"; } - + sub _print_version { - $logger->info( + $logger->info( "$0 script version $VERSION, CPAN.pm version " . CPAN->VERSION ); return HEY_IT_WORKED; } - + sub _create_autobundle { - $logger->info( + $logger->info( "Creating autobundle in $CPAN::Config->{cpan_home}/Bundle" ); CPAN::Shell->autobundle; @@ -621,24 +621,24 @@ sub _upgrade } sub _load_config # -j - { + { my $file = shift || ''; - + # should I clear out any existing config here? $CPAN::Config = {}; delete $INC{'CPAN/Config.pm'}; croak( "Config file [$file] does not exist!\n" ) unless -e $file; - + my $rc = eval "require '$file'"; # CPAN::HandleConfig::require_myconfig_or_config looks for this $INC{'CPAN/MyConfig.pm'} = 'fake out!'; - + # CPAN::HandleConfig::load looks for this $CPAN::Config_loaded = 'fake out'; - + croak( "Could not load [$file]: $@\n") unless $rc; - + return HEY_IT_WORKED; } @@ -646,60 +646,60 @@ sub _dump_config { my $args = shift; require Data::Dumper; - + my $fh = $args->[0] || \*STDOUT; - - my $dd = Data::Dumper->new( - [$CPAN::Config], - ['$CPAN::Config'] + + my $dd = Data::Dumper->new( + [$CPAN::Config], + ['$CPAN::Config'] ); - + print $fh $dd->Dump, "\n1;\n__END__\n"; - + return HEY_IT_WORKED; } sub _lock_lobotomy { no warnings 'redefine'; - + *CPAN::_flock = sub { 1 }; *CPAN::checklock = sub { 1 }; return HEY_IT_WORKED; } - + sub _download - { + { my $args = shift; - + local $CPAN::DEBUG = 1; - + my %paths; - + foreach my $module ( @$args ) { $logger->info( "Checking $module" ); my $path = CPAN::Shell->expand( "Module", $module )->cpan_file; - + $logger->debug( "Inst file would be $path\n" ); - + $paths{$module} = _get_file( _make_path( $path ) ); } - + return \%paths; } sub _make_path { join "/", qw(authors id), $_[0] } - + sub _get_file { my $path = shift; - + my $loaded = eval "require LWP::Simple; 1;"; croak "You need LWP::Simple to use features that fetch files from CPAN\n" unless $loaded; - + my $file = substr $path, rindex( $path, '/' ) + 1; my $store_path = catfile( cwd(), $file ); $logger->debug( "Store path is $store_path" ); @@ -717,13 +717,13 @@ sub _get_file sub _gitify { my $args = shift; - + my $loaded = eval "require Archive::Extract; 1;"; croak "You need Archive::Extract to use features that gitify distributions\n" unless $loaded; - + my $starting_dir = cwd(); - + foreach my $module ( @$args ) { $logger->info( "Checking $module" ); @@ -731,23 +731,23 @@ sub _gitify my $store_paths = _download( [ $module ] ); $logger->debug( "gitify Store path is $store_paths->{$module}" ); - my $dirname = dirname( $store_paths->{$module} ); - + my $dirname = dirname( $store_paths->{$module} ); + my $ae = Archive::Extract->new( archive => $store_paths->{$module} ); $ae->extract( to => $dirname ); - + chdir $ae->extract_path; - + my $git = $ENV{GIT_COMMAND} || '/usr/local/bin/git'; croak "Could not find $git" unless -e $git; croak "$git is not executable" unless -x $git; - + # can we do this in Pure Perl? system( $git, 'init' ); system( $git, qw( add . ) ); system( $git, qw( commit -a -m ), 'initial import' ); } - + chdir $starting_dir; return HEY_IT_WORKED; @@ -756,42 +756,42 @@ sub _gitify sub _show_Changes { my $args = shift; - + foreach my $arg ( @$args ) { $logger->info( "Checking $arg\n" ); - + my $module = eval { CPAN::Shell->expand( "Module", $arg ) }; my $out = _get_cpanpm_output(); - + next unless eval { $module->inst_file }; #next if $module->uptodate; - + ( my $id = $module->id() ) =~ s/::/\-/; - + my $url = "http://search.cpan.org/~" . lc( $module->userid ) . "/" . $id . "-" . $module->cpan_version() . "/"; - + #print "URL: $url\n"; _get_changes_file($url); } return HEY_IT_WORKED; - } - + } + sub _get_changes_file { croak "Reading Changes files requires LWP::Simple and URI\n" unless eval "require LWP::Simple; require URI; 1"; - + my $url = shift; my $content = LWP::Simple::get( $url ); $logger->info( "Got $url ..." ) if defined $content; #print $content; - + my( $change_link ) = $content =~ m|<a href="(.*?)">Changes</a>|gi; - + my $changes_url = URI->new_abs( $change_link, $url ); $logger->debug( "Change link is: $changes_url" ); @@ -801,11 +801,11 @@ sub _get_changes_file return HEY_IT_WORKED; } - + sub _show_Author - { + { my $args = shift; - + foreach my $arg ( @$args ) { my $module = CPAN::Shell->expand( "Module", $arg ); @@ -814,29 +814,29 @@ sub _show_Author $logger->info( "Didn't find a $arg module, so no author!" ); next; } - + my $author = CPAN::Shell->expand( "Author", $module->userid ); - + next unless $module->userid; - - printf "%-25s %-8s %-25s %s\n", + + printf "%-25s %-8s %-25s %s\n", $arg, $module->userid, $author->email, $author->fullname; } return HEY_IT_WORKED; - } + } sub _show_Details { my $args = shift; - + foreach my $arg ( @$args ) { my $module = CPAN::Shell->expand( "Module", $arg ); my $author = CPAN::Shell->expand( "Author", $module->userid ); - + next unless $module->userid; - + print "$arg\n", "-" x 73, "\n\t"; print join "\n\t", $module->description ? $module->description : "(no description)", @@ -848,26 +848,26 @@ sub _show_Details $author->fullname . " (" . $module->userid . ")", $author->email; print "\n\n"; - + } - + return HEY_IT_WORKED; - } + } sub _show_out_of_date { my @modules = CPAN::Shell->expand( "Module", "/./" ); - + printf "%-40s %6s %6s\n", "Module Name", "Local", "CPAN"; print "-" x 73, "\n"; - + foreach my $module ( @modules ) { next unless $module->inst_file; next if $module->uptodate; printf "%-40s %.4f %.4f\n", - $module->id, - $module->inst_version ? $module->inst_version : '', + $module->id, + $module->inst_version ? $module->inst_version : '', $module->cpan_version; } @@ -879,71 +879,71 @@ sub _show_author_mods my $args = shift; my %hash = map { lc $_, 1 } @$args; - + my @modules = CPAN::Shell->expand( "Module", "/./" ); - + foreach my $module ( @modules ) { next unless exists $hash{ lc $module->userid }; print $module->id, "\n"; } - + return HEY_IT_WORKED; } - + sub _list_all_mods { require File::Find; - + my $args = shift; - - + + my $fh = \*STDOUT; - + INC: foreach my $inc ( @INC ) - { + { my( $wanted, $reporter ) = _generator(); File::Find::find( { wanted => $wanted }, $inc ); - + my $count = 0; FILE: foreach my $file ( @{ $reporter->() } ) { my $version = _parse_version_safely( $file ); - + my $module_name = _path_to_module( $inc, $file ); next FILE unless defined $module_name; - + print $fh "$module_name\t$version\n"; - + #last if $count++ > 5; } } return HEY_IT_WORKED; } - + sub _generator - { + { my @files = (); - - sub { push @files, - File::Spec->canonpath( $File::Find::name ) + + sub { push @files, + File::Spec->canonpath( $File::Find::name ) if m/\A\w+\.pm\z/ }, sub { \@files }, } - + sub _parse_version_safely # stolen from PAUSE's mldistwatch, but refactored { my( $file ) = @_; - + local $/ = "\n"; local $_; # don't mess with the $_ in the map calling this - + return unless open FILE, "<$file"; my $in_pod = 0; my $version; - while( <FILE> ) + while( <FILE> ) { chomp; $in_pod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $in_pod; @@ -951,22 +951,22 @@ sub _parse_version_safely # stolen from PAUSE's mldistwatch, but refactored next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/; my( $sigil, $var ) = ( $1, $2 ); - + $version = _eval_version( $_, $sigil, $var ); last; } close FILE; return 'undef' unless defined $version; - + return $version; } sub _eval_version { my( $line, $sigil, $var ) = @_; - - my $eval = qq{ + + my $eval = qq{ package ExtUtils::MakeMaker::_version; local $sigil$var; @@ -974,7 +974,7 @@ sub _eval_version $line }; \$$var }; - + my $version = do { local $^W = 0; no strict; @@ -988,16 +988,16 @@ sub _path_to_module { my( $inc, $path ) = @_; return if length $path< length $inc; - + my $module_path = substr( $path, length $inc ); $module_path =~ s/\.pm\z//; - + # XXX: this is cheating and doesn't handle everything right my @dirs = grep { ! /\W/ } File::Spec->splitdir( $module_path ); shift @dirs; - + my $module_name = join "::", @dirs; - + return $module_name; } @@ -1007,7 +1007,7 @@ sub _path_to_module =head1 EXIT VALUES -The script exits with zero if it thinks that everything worked, or a +The script exits with zero if it thinks that everything worked, or a positive number if it thinks that something failed. Note, however, that in some cases it has to divine a failure by the output of things it does not control. For now, the exit codes are vague: |