tokuhirom/Test-TCP — pull request #17 by MarkMartinec (2013-06-11 16:57:05+00:00)
Title: Support IPv6, make it usable on an IPv6-only host

The Test-TCP is currently unusable on an IPv6-only host or
inside a jail (like on a FreeBSD) which does not have a loopback
interface and no IP address 127.0.0.1. Consequently, any other
Perl module which uses Test-TCP in its tests will fail its
self-tests on such host.

The proposed change lets Test-TCP adapt to its network environment.

Instead of unconditionally using a module IO::Socket::INET
which does not support IPv6 protocol family, try to use the
modern IO::Socket::IP, falling back to older IO::Socket::INET6,
or ultimately to IO::Socket::INET if that is the only module
available. Instead of assuming the loopback interface has
an IP address 127.0.0.1 (which it may not have, e.g. on an
IPv6-only host its only IP address is ::1), use a host name
'localhost', which is recognized by all three IO::Socket::*
modules and resolve to whatever IP address is available.

Btw, the 'localhost' change in the POD section example regarding
Cache::Memcached was tested and works, the Cache::Memcached::new
will happily accept "localhost:11211" as servers specification.

Feel free to factor-out or otherwise modify the common new code
section in t/*.t .