📄 cpan.pm
字号:
} my $class = "CPAN::$type"; my $obj; CPAN->debug(sprintf "class[%s]regex[%s]command[%s]", $class, defined $regex ? $regex : "UNDEFINED", $command || "UNDEFINED", ) if $CPAN::DEBUG; if (defined $regex) { for $obj ( sort {$a->id cmp $b->id} $CPAN::META->all_objects($class) ) { unless ($obj->id){ # BUG, we got an empty object somewhere require Data::Dumper; CPAN->debug(sprintf( "Bug in CPAN: Empty id on obj[%s][%s]", $obj, Data::Dumper::Dumper($obj) )) if $CPAN::DEBUG; next; } push @m, $obj if $obj->id =~ /$regex/i or ( ( $] < 5.00303 ### provide sort of ### compatibility with 5.003 || $obj->can('name') ) && $obj->name =~ /$regex/i ); } } elsif ($command) { die "equal sign in command disabled (immature interface), ". "you can set ! \$CPAN::Shell::ADVANCED_QUERY=1to enable it. But please note, this is HIGHLY EXPERIMENTAL codethat may go away anytime.\n" unless $ADVANCED_QUERY; my($method,$criterion) = $arg =~ /(.+?)=(.+)/; my($matchcrit) = $criterion =~ m/^~(.+)/; for my $self ( sort {$a->id cmp $b->id} $CPAN::META->all_objects($class) ) { my $lhs = $self->$method() or next; # () for 5.00503 if ($matchcrit) { push @m, $self if $lhs =~ m/$matchcrit/; } else { push @m, $self if $lhs eq $criterion; } } } else { my($xarg) = $arg; if ( $type eq 'Bundle' ) { $xarg =~ s/^(Bundle::)?(.*)/Bundle::$2/; } elsif ($type eq "Distribution") { $xarg = CPAN::Distribution->normalize($arg); } if ($CPAN::META->exists($class,$xarg)) { $obj = $CPAN::META->instance($class,$xarg); } elsif ($CPAN::META->exists($class,$arg)) { $obj = $CPAN::META->instance($class,$arg); } else { next; } push @m, $obj; } } return wantarray ? @m : $m[0];}#-> sub CPAN::Shell::format_result ;sub format_result { my($self) = shift; my($type,@args) = @_; @args = '/./' unless @args; my(@result) = $self->expand($type,@args); my $result = @result == 1 ? $result[0]->as_string : @result == 0 ? "No objects of type $type found for argument @args\n" : join("", (map {$_->as_glimpse} @result), scalar @result, " items found\n", ); $result;}# The only reason for this method is currently to have a reliable# debugging utility that reveals which output is going through which# channel. No, I don't like the colors ;-)#-> sub CPAN::Shell::print_ornameted ;sub print_ornamented { my($self,$what,$ornament) = @_; my $longest = 0; return unless defined $what; if ($CPAN::Config->{term_is_latin}){ # courtesy jhi: $what =~ s{([\xC0-\xDF])([\x80-\xBF])}{chr(ord($1)<<6&0xC0|ord($2)&0x3F)}eg; #}; } if ($PRINT_ORNAMENTING) { unless (defined &color) { if ($CPAN::META->has_inst("Term::ANSIColor")) { import Term::ANSIColor "color"; } else { *color = sub { return "" }; } } my $line; for $line (split /\n/, $what) { $longest = length($line) if length($line) > $longest; } my $sprintf = "%-" . $longest . "s"; while ($what){ $what =~ s/(.*\n?)//m; my $line = $1; last unless $line; my($nl) = chomp $line ? "\n" : ""; # print "line[$line]ornament[$ornament]sprintf[$sprintf]\n"; print color($ornament), sprintf($sprintf,$line), color("reset"), $nl; } } else { print $what; }}sub myprint { my($self,$what) = @_; $self->print_ornamented($what, 'bold blue on_yellow');}sub myexit { my($self,$what) = @_; $self->myprint($what); exit;}sub mywarn { my($self,$what) = @_; $self->print_ornamented($what, 'bold red on_yellow');}sub myconfess { my($self,$what) = @_; $self->print_ornamented($what, 'bold red on_white'); Carp::confess "died";}sub mydie { my($self,$what) = @_; $self->print_ornamented($what, 'bold red on_white'); die "\n";}sub setup_output { return if -t STDOUT; my $odef = select STDERR; $| = 1; select STDOUT; $| = 1; select $odef;}#-> sub CPAN::Shell::rematein ;# RE-adme||MA-ke||TE-st||IN-stallsub rematein { shift; my($meth,@some) = @_; my $pragma = ""; if ($meth eq 'force') { $pragma = $meth; $meth = shift @some; } setup_output(); CPAN->debug("pragma[$pragma]meth[$meth] some[@some]") if $CPAN::DEBUG; # Here is the place to set "test_count" on all involved parties to # 0. We then can pass this counter on to the involved # distributions and those can refuse to test if test_count > X. In # the first stab at it we could use a 1 for "X". # But when do I reset the distributions to start with 0 again? # Jost suggested to have a random or cycling interaction ID that # we pass through. But the ID is something that is just left lying # around in addition to the counter, so I'd prefer to set the # counter to 0 now, and repeat at the end of the loop. But what # about dependencies? They appear later and are not reset, they # enter the queue but not its copy. How do they get a sensible # test_count? # construct the queue my($s,@s,@qcopy); foreach $s (@some) { my $obj; if (ref $s) { CPAN->debug("s is an object[$s]") if $CPAN::DEBUG; $obj = $s; } elsif ($s =~ m|^/|) { # looks like a regexp $CPAN::Frontend->mywarn("Sorry, $meth with a regular expression is ". "not supported\n"); sleep 2; next; } else { CPAN->debug("calling expandany [$s]") if $CPAN::DEBUG; $obj = CPAN::Shell->expandany($s); } if (ref $obj) { $obj->color_cmd_tmps(0,1); CPAN::Queue->new($obj->id); push @qcopy, $obj; } elsif ($CPAN::META->exists('CPAN::Author',$s)) { $obj = $CPAN::META->instance('CPAN::Author',$s); if ($meth eq "dump") { $obj->dump; } else { $CPAN::Frontend->myprint( join "", "Don't be silly, you can't $meth ", $obj->fullname, " ;-)\n" ); sleep 2; } } else { $CPAN::Frontend ->myprint(qq{Warning: Cannot $meth $s, }. qq{don\'t know what it is.Try the command i /$s/to find objects with matching identifiers.}); sleep 2; } } # queuerunner (please be warned: when I started to change the # queue to hold objects instead of names, I made one or two # mistakes and never found which. I reverted back instead) while ($s = CPAN::Queue->first) { my $obj; if (ref $s) { $obj = $s; # I do not believe, we would survive if this happened } else { $obj = CPAN::Shell->expandany($s); } if ($pragma && ($] < 5.00303 || $obj->can($pragma))){ ### compatibility with 5.003 $obj->$pragma($meth); # the pragma "force" in # "CPAN::Distribution" must know # what we are intending } if ($]>=5.00303 && $obj->can('called_for')) { $obj->called_for($s); } CPAN->debug( qq{pragma[$pragma]meth[$meth]obj[$obj]as_string\[}. $obj->as_string. qq{\]} ) if $CPAN::DEBUG; if ($obj->$meth()){ CPAN::Queue->delete($s); } else { CPAN->debug("failed"); } $obj->undelay; CPAN::Queue->delete_first($s); } for my $obj (@qcopy) { $obj->color_cmd_tmps(0,0); }}#-> sub CPAN::Shell::dump ;sub dump { shift->rematein('dump',@_); }#-> sub CPAN::Shell::force ;sub force { shift->rematein('force',@_); }#-> sub CPAN::Shell::get ;sub get { shift->rematein('get',@_); }#-> sub CPAN::Shell::readme ;sub readme { shift->rematein('readme',@_); }#-> sub CPAN::Shell::make ;sub make { shift->rematein('make',@_); }#-> sub CPAN::Shell::test ;sub test { shift->rematein('test',@_); }#-> sub CPAN::Shell::install ;sub install { shift->rematein('install',@_); }#-> sub CPAN::Shell::clean ;sub clean { shift->rematein('clean',@_); }#-> sub CPAN::Shell::look ;sub look { shift->rematein('look',@_); }#-> sub CPAN::Shell::cvs_import ;sub cvs_import { shift->rematein('cvs_import',@_); }package CPAN::LWP::UserAgent;sub config { return if $SETUPDONE; if ($CPAN::META->has_usable('LWP::UserAgent')) { require LWP::UserAgent; @ISA = qw(Exporter LWP::UserAgent); $SETUPDONE++; } else { $CPAN::Frontent->mywarn("LWP::UserAgent not available\n"); }}sub get_basic_credentials { my($self, $realm, $uri, $proxy) = @_; return unless $proxy; if ($USER && $PASSWD) { } elsif (defined $CPAN::Config->{proxy_user} && defined $CPAN::Config->{proxy_pass}) { $USER = $CPAN::Config->{proxy_user}; $PASSWD = $CPAN::Config->{proxy_pass}; } else { require ExtUtils::MakeMaker; ExtUtils::MakeMaker->import(qw(prompt)); $USER = prompt("Proxy authentication needed! (Note: to permanently configure username and password run o conf proxy_user your_username o conf proxy_pass your_password )\nUsername:"); if ($CPAN::META->has_inst("Term::ReadKey")) { Term::ReadKey::ReadMode("noecho"); } else { $CPAN::Frontend->mywarn("Warning: Term::ReadKey seems not to be available, your password will be echoed to the terminal!\n"); } $PASSWD = prompt("Password:"); if ($CPAN::META->has_inst("Term::ReadKey")) { Term::ReadKey::ReadMode("restore"); } $CPAN::Frontend->myprint("\n\n"); } return($USER,$PASSWD);}sub mirror { my($self,$url,$aslocal) = @_; my $result = $self->SUPER::mirror($url,$aslocal); if ($result->code == 407) { undef $USER; undef $PASSWD; $result = $self->SUPER::mirror($url,$aslocal); } $result;}package CPAN::FTP;#-> sub CPAN::FTP::ftp_get ;sub ftp_get { my($class,$host,$dir,$file,$target) = @_; $class->debug( qq[Going to fetch file [$file] from dir [$dir] on host [$host] as local [$target]\n] ) if $CPAN::DEBUG; my $ftp = Net::FTP->new($host); return 0 unless defined $ftp; $ftp->debug(1) if $CPAN::DEBUG{'FTP'} & $CPAN::DEBUG; $class->debug(qq[Going to login("anonymous","$Config::Config{cf_email}")]); unless ( $ftp->login("anonymous",$Config::Config{'cf_email'}) ){ warn "Couldn't login on $host"; return; } unless ( $ftp->cwd($dir) ){ warn "Couldn't cwd $dir"; return; } $ftp->binary; $class->debug(qq[Going to ->get("$file","$target")\n]) if $CPAN::DEBUG; unless ( $ftp->get($file,$target) ){ warn "Couldn't fetch $file from $host\n"; return; } $ftp->quit; # it's ok if this fails return 1;}# If more accuracy is wanted/needed, Chris Leach sent me this patch... # > *** /install/perl/live/lib/CPAN.pm- Wed Sep 24 13:08:48 1997 # > --- /tmp/cp Wed Sep 24 13:26:40 1997 # > *************** # > *** 1562,1567 **** # > --- 1562,1580 ---- # > return 1 if substr($url,0,4) eq "file"; # > return 1 unless $url =~ m|://([^/]+)|; # > my $host = $1; # > + my $proxy = $CPAN::Config->{'http_proxy'} || $ENV{'http_proxy'}; # > + if ($proxy) { # > + $proxy =~ m|://([^/:]+)|; # > + $proxy = $1; # > + my $noproxy = $CPAN::Config->{'no_proxy'} || $ENV{'no_proxy'}; # > + if ($noproxy) { # > + if ($host !~ /$noproxy$/) { # > + $host = $proxy; # > + } # > + } else { # > + $host = $proxy; # > + } # > + } # > require Net::Ping; # > return 1 unless $Net::Ping::VERSION >= 2; # > my $p;#-> sub CPAN::FTP::localize ;sub localize { my($self,$file,$aslocal,$force) = @_; $force ||= 0; Carp::croak "Usage: ->localize(cpan_file,as_local_file[,$force])" unless defined $aslocal; $self->debug("file[$file] aslocal[$aslocal] force[$force]") if $CPAN::DEBUG; if ($^O eq 'MacOS') {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -