CPAN-WAIT
view release on metacpan or search on metacpan
lib/CPAN/WAIT.pm view on Meta::CPAN
# -*- Mode: Perl -*-
# $Basename: WAIT.pm $
# $Revision: 1.6 $
# Author : Ulrich Pfeifer
# Created On : Fri Jan 31 11:30:46 1997
# Last Modified By: Ulrich Pfeifer
# Last Modified On: Thu Mar 23 21:19:20 2000
# Language : CPerl
# Update Count : 145
# Status : Unknown, Use with caution!
#
# (C) Copyright 1997, Ulrich Pfeifer, all rights reserved.
#
#
package CPAN::WAIT;
use ExtUtils::MakeMaker; # MM->catfile
# try to avoid 'use'ing CPAN.pm
# code stolen from CPAN::Config::load ;
eval {require CPAN::Config;}; # We eval because of some
# MakeMaker problems
unless ($CPAN::dot_cpan++){
unshift @INC, MM->catdir($ENV{HOME},".cpan");
eval {require CPAN::MyConfig;}; # where you can override
# system wide settings
shift @INC;
}
require WAIT::Client;
require FileHandle;
use vars qw($VERSION $DEBUG $TIMEOUT);
# $Format: "\$\V\E\R\S\I\O\N = '$ModuleVersion$';"$ MM_Unix bug
$VERSION = '0.27';
$TIMEOUT = 20; # Set this to some larger value if you
# have a slow connection.
sub _open_connection () {
my ($host, $port, $con);
# Make sure that there is a wait server to try
unless ($CPAN::Config->{'wait_list'}) {
$CPAN::Config->{'wait_list'} = ['wait://ls6.informatik.uni-dortmund.de'];
}
# Try direct connection
my $server;
SERVER:
for $server (@{$CPAN::Config->{'wait_list'}}) {
warn "CPAN::WAIT $VERSION checking $server\n" if $DEBUG;
if ($server =~ m(^wait://([^:]+)(?::(\d+))?)) {
($host, $port) = ($1, $2 || 1404);
# Constructor is inherited from Net::NNTP
$con = WAIT::Client->new($host, Port => $port, Timeout => $TIMEOUT)
unless $DEBUG and $DEBUG =~ /force proxy/;
last SERVER if $con;
}
}
# Try connection via an http proxy
unless ($con) {
warn "Could not connect to the WAIT server at $host port $port\n"
unless $DEBUG and $DEBUG =~ /force proxy/;
if ($CPAN::Config->{'http_proxy'}) {
print "Trying your http proxy $CPAN::Config->{'http_proxy'}\n";
SERVER:
for $server (@{$CPAN::Config->{'wait_list'}}) {
if ($server =~ m(^wait://([^:]+)(?::(\d+))?)) {
($host, $port) = ($1, $2 || 1404);
$con = WAIT::Client::HTTP->new($host,
Port => $port,
Proxy => $CPAN::Config->{'http_proxy'},
Timeout => $TIMEOUT);
last SERVER if $con;
}
}
warn "No luck with your proxy either. Giving up\n"
unless $con;
} else {
warn "You did not tell the CPAN module about an http proxy.\n" .
"I could use such a beast instead of a direct connection.\n";
}
}
# We had no luck.
warn "No searching available!\n" unless $con;
return $con;
}
my $con;
# Temporary file for retrieved documents
my $tmp = MM->catfile($CPAN::Config->{'cpan_home'}, 'w4c.pod');
# run a search
sub wq {
my $self = shift;
my $result;
local ($") = ' ';
$con ||= _open_connection || return;
print "Searching for '@_'\n";
unless ($result = $con->search(@_)) {
print "Your query contains a syntax error.\n";
$self->wh('wq');
} else {
print $con->message;
print @{$result};
print "Type 'wr <number>' or 'wd <number>' to examine the results\n";
}
$result;
}
# display hit record
sub wr {
my $self = shift;
my $hit = shift;
my $result;
if (@_ or !$hit) {
print "USAGE: wr <hit-number>\n";
} else {
$con ||= _open_connection || return;
print "fetching info on hit number $hit\n";
$result = $con->info($hit);
print @$result;
}
$result;
}
# display hit document
sub wd {
my $self = shift;
( run in 0.639 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )