Subject: | Net::HTTP fails tests if changed to use IO::Socket::IP |
IO::Socket::IP isn't currently a substitute for IO::Socket::INET in
Net::HTTP. If I change Net::HTTP to use it:
--- lib/Net/HTTP.pm~ 2013-03-10 23:35:20.000000000 +0100
+++ lib/Net/HTTP.pm 2014-01-09 17:34:17.000000000 +0100
@@ -5,8 +5,8 @@
$VERSION = "6.06";
unless ($SOCKET_CLASS) {
- eval { require IO::Socket::INET } || require IO::Socket;
- $SOCKET_CLASS = "IO::Socket::INET";
+ eval { require IO::Socket::IP; } || require IO::Socket;
+ $SOCKET_CLASS = "IO::Socket::IP";
}
require Net::HTTP::Methods;
require Carp;
Then tests fail. The failure can be reduced to this
$ cat nb.pl
#!perl -w
use v5.10;
require Net::HTTP;
# bind a random TCP port for testing
my %lopts = (
LocalAddr => "127.0.0.1",
LocalPort => 0,
Proto => "tcp",
ReuseAddr => 1,
Listen => 1024
);
my $srv = IO::Socket::INET->new(%lopts);
my $host = $srv->sockhost . ':' . $srv->sockport;
my $nb = Net::HTTP->new(Host => $host, Blocking => 0);
say ref($nb);
__END__
which generates no output, because $nb is not defined.
(It should be Net::HTTP)
The problem seems to be that Net::HTTP is a subclass of the socket
module, and has these methods:
sub new {
my $class = shift;
Carp::croak("No Host option provided") unless @_;
$class->SUPER::new(@_);
}
sub configure {
my($self, $cnf) = @_;
$self->http_configure($cnf);
}
sub http_connect {
my($self, $cnf) = @_;
$self->SUPER::configure($cnf);
}
and relies its configure being called by the SUPER::new. Which is the
case for IO::Socket::INET, but isn't for IO::Socket::IP.
Given that IO::Socket::IP has this:
# IO::Socket may call this one; neaten up the arguments from IO::Socket::INET
# before calling our real _configure method
sub configure
{
I assume that this is a bug in emulation of IO::Socket::INET, as it's
not documented as an incompatibility.
IO::Socket::IP 0.24 with blead, on both OS X and Linux.
Nicholas Clark