File Coverage

blib/lib/Paranoid/Network/Socket.pm
Criterion Covered Total %
statement 28 44 63.6
branch 3 18 16.6
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 40 71 56.3


line stmt bran cond sub pod time code
1             # Paranoid::Network::Socket -- Socket wrapper for seemless IPv6 support
2             #
3             # $Id: lib/Paranoid/Network/Socket.pm, 2.08 2020/12/31 12:10:06 acorliss Exp $
4             #
5             # This software is free software. Similar to Perl, you can redistribute it
6             # and/or modify it under the terms of either:
7             #
8             # a) the GNU General Public License
9             # as published by the
10             # Free Software Foundation ; either version 1
11             # , or any later version
12             # , or
13             # b) the Artistic License 2.0
14             # ,
15             #
16             # subject to the following additional term: No trademark rights to
17             # "Paranoid" have been or are conveyed under any of the above licenses.
18             # However, "Paranoid" may be used fairly to describe this unmodified
19             # software, in good faith, but not as a trademark.
20             #
21             # (c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com)
22             # (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com)
23             #
24             #####################################################################
25              
26             #####################################################################
27             #
28             # Environment definitions
29             #
30             #####################################################################
31              
32             package Paranoid::Network::Socket;
33              
34 5     5   603 use 5.008;
  5         17  
35              
36 5     5   32 use strict;
  5         16  
  5         126  
37 5     5   29 use warnings;
  5         9  
  5         185  
38 5     5   28 use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS);
  5         8  
  5         347  
39 5     5   33 use base qw(Exporter);
  5         18  
  5         366  
40 5     5   3131 use Socket qw(:all);
  5         19039  
  5         6974  
41              
42             ($VERSION) = ( q$Revision: 2.08 $ =~ /(\d+(?:\.\d+)+)/sm );
43              
44             #####################################################################
45             #
46             # Module code follows
47             #
48             #####################################################################
49              
50             our $ipv6_enabled;
51             our $socket6;
52              
53             sub has_ipv6 {
54 72     72 1 1194 return $ipv6_enabled;
55             }
56              
57             BEGIN {
58              
59 5     5   96 @EXPORT = ( 'has_ipv6', @Socket::EXPORT );
60 5         50 @EXPORT_OK = ( 'has_ipv6', @Socket::EXPORT_OK );
61             %EXPORT_TAGS = (
62             %Socket::EXPORT_TAGS,
63 5         23 all => [ 'has_ipv6', @{ $Socket::EXPORT_TAGS{all} } ],
  5         184  
64             );
65              
66             # Check to see if we've got any IPv6 functions available
67 5         15 $socket6 = 0;
68 5 50       33 $ipv6_enabled = ( defined *sockaddr_in6{CODE} ) ? 1 : 0;
69              
70             # Set inet_pton/inet_ntop to import by default -- don't know why
71             # this isn't done in Socket at all...
72 5 50       16 if ( grep { $_ eq 'inet_pton' } @EXPORT_OK ) {
  545         829  
73 5         27 push @EXPORT, qw(inet_pton inet_ntop);
74             }
75              
76 5 50       179 unless ($ipv6_enabled) {
77              
78             # Socket didn't provide it, let's see if Socket6 is available
79 0 0       0 if ( eval 'require Socket6; 1;' ) {
80              
81             # Conditionally import Socket6 routines. This is important
82             # because perl 5.12 has partial IPv6 support, and 5.14 full. I
83             # want to avoid redefined and prototype mismatch warnings.
84 0         0 for my $symbol (@Socket6::EXPORT) {
85 0 0       0 unless ( grep /^$symbol$/s, @EXPORT, @EXPORT_OK ) {
86 0         0 import Socket6 $symbol;
87 0         0 push @EXPORT, $symbol;
88 0         0 push @{ $EXPORT_TAGS{all} }, $symbol;
  0         0  
89             }
90             }
91 0         0 for my $symbol (@Socket6::EXPORT_OK) {
92 0 0       0 unless ( grep /^$symbol$/s, @EXPORT, @EXPORT_OK ) {
93 0         0 import Socket6 $symbol;
94 0         0 push @EXPORT_OK, $symbol;
95 0         0 push @{ $EXPORT_TAGS{all} }, $symbol;
  0         0  
96             }
97             }
98             }
99              
100             # Check one more time...
101 0 0       0 $ipv6_enabled = ( defined *sockaddr_in6{CODE} ) ? 1 : 0;
102 0 0       0 if ($ipv6_enabled) {
103 0 0       0 $socket6 = *sockaddr_in{PACKAGE} eq 'Socket6' ? 1 : 0;
104             }
105             }
106             }
107              
108             1;
109              
110             __END__