blib/lib/Net/DNS/Native.pm

filter: Statementstmt 100% 76 / 76 Branchbran 85.0% 17 / 20 Conditioncond 58.3% 14 / 24 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 95.8% 23 / 24 Podpod 100% 7 / 7 totaltotal 86.5% 141 / 163 CC 19 SCAR 14.2
CC
19
Cov
89%
get_result
10.1
BEGIN
6.0
timedout
4.2
CRAP 4.1
↑ Summary Native.xs »
1 package Net::DNS::Native;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.22';
12  
13 5 ▶use constant {
Subroutine BEGIN: called CC=4 SCAR=17.9
14 INET_ATON => 0,
15 INET_PTON => 1,
16 GETHOSTBYNAME => 2,
17 GETADDRINFO => 3,
18 NEED_RTLD_GLOBAL => $Config{osname} =~ /linux/i &&
19 5 ▶ !($Config{usethreads} || $Config{libs} =~ /-l?pthread\b/ || $Config{ldflags} =~ /-l?pthread\b/)
Condition33%3/9
$Net::DNS::Native::Config{'osname'} =~ /linux/i && !($Net::DNS::Native::Config{'usethreads'} || $Net::DNS::Native::Config{'libs'} =~ /-l?pthread\b/ || $Net::DNS::Native::Config{'ldflags'} =~ /-l?pthread\b/)
!ll&&!rl&&r
050
$Net::DNS::Native::Config{'usethreads'} || $Net::DNS::Native::Config{'libs'} =~ /-l?pthread\b/ || $Net::DNS::Native::Config{'ldflags'} =~ /-l?pthread\b/
l!l&&r!l&&!r
500
$Net::DNS::Native::Config{"usethreads"} or $Net::DNS::Native::Config{"libs"} =~ /-l?pthread\b/
l!l&&r!l&&!r
050
MC/DC0%0/4
$Net::DNS::Native::Config{'osname'} =~ /linux/i && !($Net::DNS::Native::Config{'usethreads'} || $Net::DNS::Native::Config{'libs'} =~ /-l?pthread\b/ || $Net::DNS::Native::Config{'ldflags'} =~ /-l?pthread\b/)
$Net::DNS::Native::Config{'osname'} =~ /linux/i $Net::DNS::Native::Config{"usethreads"} $Net::DNS::Native::Config{"libs"} =~ /-l?pthread\b/ $Net::DNS::Native::Config{'ldflags'} =~ /-l?pthread\b/
Truth table20%1/5
A && not(B or C || D)
A= $Net::DNS::Native::Config{'osname'} =~ /linux/iB= $Net::DNS::Native::Config{"usethreads"}C= $Net::DNS::Native::Config{"libs"} =~ /-l?pthread\b/D= $Net::DNS::Native::Config{'ldflags'} =~ /-l?pthread\b/
ABCDresult
0XXX0
11XX0
101X0
10010
10001
20 5 };
21  
22 5 our @ISA = 'DynaLoader';
23 5 ▶sub dl_load_flags {
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod documented
24 5 if (NEED_RTLD_GLOBAL) {
25 return 0x01;
26 }
27
28 5 return 0;
29 }
30 5 DynaLoader::bootstrap('Net::DNS::Native');
31 5 if (NEED_RTLD_GLOBAL && &_is_non_safe_symbols_loaded) {
32 die sprintf(
33 "***********************************************************************
34 Some package defined non thread safe symbols which %s uses internally
35 Please make sure you are not placed loading of modules like IO::Socket::IP
36 before this one and not called functions like getaddrinfo(), gethostbyname(),
37 inet_aton() before loading of %s
38 ************************************************************************", __PACKAGE__, __PACKAGE__);
39 }
40  
41 314 ▶sub _fd2socket($$) {
Subroutine _fd2socket: called CC=1 SCAR=0.0
42 314 my $sock = Symbol::gensym();
43 314 tie *$sock, 'Net::DNS::Native::Handle', $_[1], $_[0];
44 314 $sock;
45 }
46  
47 233 ▶sub getaddrinfo {
Subroutine getaddrinfo: called CC=1 SCAR=0.0
Pod documented
48 233 my $self = shift;
49 233 _fd2socket $self, $self->_getaddrinfo($_[0], $_[1], $_[2], GETADDRINFO);
50 }
51  
52 18 ▶sub inet_aton {
Subroutine inet_aton: called CC=1 SCAR=0.0
Pod documented
53 18 my $self = shift;
54 18 _fd2socket $self, $self->_getaddrinfo($_[0], undef, {family => Socket::AF_INET, socktype => Socket::SOCK_STREAM}, INET_ATON);
55 }
56  
57 18 ▶sub inet_pton {
Subroutine inet_pton: called CC=1 SCAR=0.0
Pod documented
58 18 my $self = shift;
59 18 _fd2socket $self, $self->_getaddrinfo($_[1], undef, {family => $_[0], socktype => Socket::SOCK_STREAM}, INET_PTON);
60 }
61  
62 45 ▶sub gethostbyname {
Subroutine gethostbyname: called CC=1 SCAR=0.0
Pod documented
63 45 my $self = shift;
64 45 _fd2socket $self, $self->_getaddrinfo($_[0], undef, {family => Socket::AF_INET, flags => Socket::AI_CANONNAME, socktype => Socket::SOCK_STREAM}, GETHOSTBYNAME);
65 }
66  
67 317 ▶sub get_result {
Subroutine get_result: called CC=10 SCAR=23.1
Pod documented
68 317 my ($self, $sock) = @_;
69
70 317 my ($type, $err, @res) = $self->_get_result(fileno($sock));
71
72 305 tied(*$sock)->need_result(0);
73
74 305 ▶ if ($type == GETADDRINFO) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 3) 233 72 305
75 233 return ($err, @res);
76 }
77
78 72 ▶ if ($type == INET_ATON || $type == INET_PTON || (!wantarray() && $type == GETHOSTBYNAME)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 0 or $type == 1 or not wantarray and $type == 2) 69 3 72
Condition88%8/9
$type == 0 or $type == 1 or not wantarray and $type == 2
l!l&&r!l&&!r
33363
$type == 0 or $type == 1
l!l&&r!l&&!r
151839
not wantarray and $type == 2
!ll&&!rl&&r
3036
MC/DC75%3/4
$type == 0 or $type == 1 or not wantarray and $type == 2
$type == 0 $type == 1 not wantarray $type == 2
Truth table80%4/5
A or B or not(C) and D
A= $type == 0B= $type == 1C= not wantarrayD= $type == 2
ABCDresult
1XXX1
01XX1
00111
000X0
00100
79 return
80 $err ? undef :
81 ( $res[0]{family} == Socket::AF_INET ?
82 Socket::unpack_sockaddr_in($res[0]{addr}) :
83 69 ▶ Net::DNS::Native::unpack_sockaddr_in6($res[0]{addr}) )[1];
Branch: 2 branches
BranchTrueFalseTotal
$err ? : 18 51 69
$res[0]{'family'} == 2 ? : 45 6 51
84 }
85
86 3 ▶ if ($type == GETHOSTBYNAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 2) 3 0 3
87 return
88 $err ? () :
89 3 ▶ ($res[0]{canonname}, undef, Socket::AF_INET, length($res[0]{addr}), map { (Socket::unpack_sockaddr_in($_->{addr}))[1] } @res);
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 3 3
90 }
91 }
92  
93 9 ▶sub timedout {
Subroutine timedout: called CC=4 SCAR=14.3
Pod documented
94 9 my ($self, $sock) = @_;
95
96 9 ▶ return if defined ${^GLOBAL_PHASE} && ${^GLOBAL_PHASE} eq 'DESTRUCT';
Branch: 1 branch
BranchTrueFalseTotal
if defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT" 0 9 9
Condition33%1/3
defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
!ll&&!rl&&r
090
MC/DC0%0/2
defined ${^GLOBAL_PHASE} and ${^GLOBAL_PHASE} eq "DESTRUCT"
defined ${^GLOBAL_PHASE} ${^GLOBAL_PHASE} eq "DESTRUCT"
Truth table33%1/3
A and B
A= defined ${^GLOBAL_PHASE}B= ${^GLOBAL_PHASE} eq "DESTRUCT"
ABresult
0X0
100
111
97
98 9 ▶ if (ref $sock) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sock) 6 3 9
99 6 tied(*$sock)->need_result(0);
100 6 $sock = fileno $sock;
101 }
102
103 9 $self->_timedout($sock);
104 }
105  
106 package Net::DNS::Native::Handle;
107  
108 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 314 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
112 314 my ($class, $fd, $resolver) = @_;
113 314 bless { fd => $fd, rs => $resolver, need_result => 1 }, $class;
114 }
115  
116 516 ▶sub FILENO {
Subroutine FILENO: called CC=1 SCAR=0.0
117 516 return $_[0]->{fd};
118 }
119  
120 249 ▶sub READ {
Subroutine READ: called CC=1 SCAR=0.0
121 249 my $self = shift;
122 249 POSIX::read( $self->{fd}, $_[0], $_[1] );
123 }
124  
125 0 ▶sub CLOSE {}
Subroutine CLOSE: not called CC=1 SCAR=0.0
126  
127 314 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.0
128 314 my $self = shift;
129
130 314 ▶ if ($self->need_result && $self->{rs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->need_result and $self->{"rs"}) 3 311 314
Condition66%2/3
$self->need_result and $self->{"rs"}
!ll&&!rl&&r
31103
MC/DC50%1/2
$self->need_result and $self->{"rs"}
$self->need_result $self->{"rs"}
Truth table66%2/3
A and B
A= $self->need_resultB= $self->{"rs"}
ABresult
0X0
100
111
131 3 $self->{rs}->timedout($self->{fd});
132 }
133 }
134  
135 625 ▶sub need_result {
Subroutine need_result: called CC=2 SCAR=6.9
136 625 my $self = shift;
137
138 625 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 314 311 625
139 314 return $self->{need_result};
140 }
141
142 311 $self->{need_result} = $_[0];
143 }
144  
145 5 1;
146  
147 __END__
↑ Summary Native.xs »