Skip to content

Commit

Permalink
fix wrong import of ipv6 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
apocalypse authored and hinrik committed Apr 20, 2011
1 parent 43104e9 commit f9487f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
23 changes: 17 additions & 6 deletions lib/POE/Component/IRC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use POE::Component::IRC::Plugin qw(:ALL);
use POE::Component::IRC::Plugin::DCC;
use POE::Component::IRC::Plugin::ISupport;
use POE::Component::IRC::Plugin::Whois;
use Socket;
use Socket qw(AF_INET SOCK_STREAM unpack_sockaddr_in inet_ntoa inet_aton);
use base qw(Object::Pluggable);

our ($GOT_SSL, $GOT_CLIENT_DNS, $GOT_SOCKET6, $GOT_ZLIB);
Expand All @@ -27,14 +27,25 @@ BEGIN {
require POE::Component::Client::DNS;
$GOT_CLIENT_DNS = 1 if $POE::Component::Client::DNS::VERSION >= 0.99;
};
eval {
require Socket6;
import Socket6;
$GOT_SOCKET6 = 1;
};
eval {
require POE::Filter::Zlib::Stream;
$GOT_ZLIB = 1 if $POE::Filter::Zlib::Stream::VERSION >= 1.96;
};

# Socket6 provides AF_INET6 where earlier Perls' Socket don't.
{
# under perl-5.6.2 the warning "leaks" from the eval, while newer versions don't...
# it's due to Exporter.pm behaving differently, so we have to shut it up
no warnings 'redefine';
local *Carp::carp = sub { die @_ };
$GOT_SOCKET6 = 1;
eval { require Socket; Socket->import( qw(AF_INET6 unpack_sockaddr_in6 inet_ntop) ) };
if ($@) {
eval { require Socket6; Socket6->import( qw(AF_INET6 unpack_sockaddr_in6 inet_ntop) ) };
if ($@) {
$GOT_SOCKET6 = 0;
}
}
}
}

Expand Down
23 changes: 14 additions & 9 deletions t/02_behavior/04_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ use strict;
use warnings FATAL => 'all';
use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line);
use POE::Component::IRC;
use Socket;
use Test::More;

my $tests = 4;

eval {
require Socket6;
import Socket6;
};

if ($@ or not exists($INC{'Socket6.pm'}) ) {
plan skip_all => 'Socket6 is needed for IPv6 tests';
# Socket6 provides AF_INET6 where earlier Perls' Socket don't.
BEGIN {
# under perl-5.6.2 the warning "leaks" from the eval, while newer versions don't...
# it's due to Exporter.pm behaving differently, so we have to shut it up
no warnings 'redefine';
local *Carp::carp = sub { die @_ };
eval { require Socket; Socket->import( qw(AF_INET6 unpack_sockaddr_in6 inet_pton) ) };
if ($@) {
eval { require Socket6; Socket6->import( qw(AF_INET6 unpack_sockaddr_in6 inet_pton) ) };
if ($@) {
plan skip_all => 'Socket6 is needed for IPv6 tests';
}
}
}

my $addr = Socket6::inet_pton(&Socket6::AF_INET6, "::1");
my $addr = inet_pton(AF_INET6, "::1");
if (!defined $addr) {
plan skip_all => "IPv6 tests require a configured localhost address ('::1')";
}
Expand Down

0 comments on commit f9487f0

Please sign in to comment.