This was something I came up with ages ago. Don't know if it'll play nice with current LWP or not, but it should get you started.
package MyHTTP;
use base qw(LWP::Protocol::http);
sub _new_socket {
my($self, $host, $port, $timeout) = @_;
local($^W) = 0; # IO::Socket::INET can be noisy
my @args = (PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => $timeout,
);
push @args, LocalAddr => $ENV{LWP_LOCAL_ADDR}
if exists $ENV{LWP_LOCAL_ADDR};
my $sock = IO::Socket::INET->new( @args );
unless ($sock) {
# IO::Socket::INET leaves additional error messages in $@
$@ =~ s/^.*?: //;
die "Can't connect to $host:$port ($@)";
}
$sock;
}
LWP::Protocol::implementor( 'http', 'MyHTTP' );
package main;
use LWP::Simple qw( getprint );
getprint( shift || 'http://localhost/' );
exit 0;
__END__
|