File Coverage

blib/lib/Net/INET6Glue/INET_is_INET6.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1 2     2   36288 use strict;
  2         6  
  2         73  
2 2     2   10 use warnings;
  2         4  
  2         122  
3             package Net::INET6Glue::INET_is_INET6;
4             our $VERSION = 0.6;
5              
6             ############################################################################
7             # copy IO::Socket::INET to IO::Socket::INET4
8             # copy IO::Socket::(IP|INET6) to IO::Socket::INET
9             ############################################################################
10 2     2   888 use IO::Socket::INET;
  2         23157  
  2         16  
11              
12             our $INET6CLASS;
13             $INC{'IO/Socket/INET4.pm'} = $INC{'IO/Socket/INET.pm'};
14             if ( eval "require IO::Socket::IP"
15             && $IO::Socket::IP::VERSION >= 0.25 ) {
16             $INC{'IO/Socket/INET.pm'} = $INC{'IO/Socket/IP.pm'};
17             $INET6CLASS = 'IO::Socket::IP';
18             } elsif ( eval "require IO::Socket::INET6"
19             && $IO::Socket::INET6::VERSION >= 2.54 ) {
20             $INC{'IO/Socket/INET.pm'} = $INC{'IO/Socket/INET6.pm'};
21             $INET6CLASS = 'IO::Socket::INET6';
22             } else {
23             die "failed to load IO::Socket::IP or IO::Socket::INET6: $@"
24             }
25            
26              
27             {
28             # copy subs
29 2     2   1809 no strict 'refs';
  2         3  
  2         82  
30 2     2   14 no warnings 'redefine';
  2         19  
  2         583  
31             for ( keys %{IO::Socket::INET::} ) {
32             ref(my $v = $IO::Socket::INET::{$_}) and next;
33             *{'IO::Socket::INET4::'.$_} = \&{ "IO::Socket::INET::$_" } if *{$v}{CODE};
34             }
35              
36             for ( keys %{"$INET6CLASS\::"} ) {
37             eval { *{${"$INET6CLASS\::"}{$_}} && *{${"$INET6CLASS\::"}{$_}}{CODE} } or next;
38             *{'IO::Socket::INET::'.$_} = \&{ "$INET6CLASS\::$_" };
39             }
40             }
41              
42              
43             1;
44              
45             =head1 NAME
46              
47             Net::INET6Glue::INET_is_INET6 - make L behave like
48             L
49              
50             =head1 SYNOPSIS
51              
52             use Net::INET6Glue::INET_is_INET6;
53             use LWP::Simple;
54             print get( 'http://[::1]:80' );
55             print get( 'http://ipv6.google.com' );
56              
57             =head1 DESCRIPTION
58              
59             Many modules directly create L sockets or have it as a
60             superclass. Because L has no support for IPv6 these modules
61             don't have it either.
62              
63             This module tries to make L behave like L
64             (with fallback to L) by copying the symbol table from
65             L into L.
66             The original symbol table from L is still available in
67             L.
68              
69             This strategy works for L, L and probably a lot of other modules
70             too, which don't try to depend too much on the innards of L or
71             on the text representation of IP addresses (IPv6 addresses look different than
72             IPv4 addresses).
73              
74             =head1 COPYRIGHT
75              
76             This module is copyright (c) 2008..2014, Steffen Ullrich.
77             All Rights Reserved.
78             This module is free software. It may be used, redistributed and/or modified
79             under the same terms as Perl itself.