Whois.pm

filter: Statementstmt 63.4% 85 / 134 Branchbran 41.3% 19 / 46 Conditioncond 26.9% 7 / 26 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 86.6% 13 / 15 Podpod 100% 1 / 1 totaltotal 52.3% 125 / 239 SCAR 49.9
CC
34
Cov
54%
whois
57.0
_sock_input
30.0
_sock_down
15.7
CRAP 147.4
↑ Summary Whois/TLDList.pm »
1 package POE::Component::Client::Whois;
2 5 $POE::Component::Client::Whois::VERSION = '1.36';
3 #ABSTRACT: A one shot non-blocking RFC 812 WHOIS query.
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use POE qw(Filter::Line Wheel::ReadWrite Wheel::SocketFactory);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use POE::Component::Client::Whois::TLDList;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use POE::Component::Client::Whois::IPBlks;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub whois {
14 3 ▶ my $package = shift;
Subroutine whois: called CC=16 SCAR=40.4
Pod documented
15 3 my %args = @_;
16  
17 3 $args{ lc $_ } = delete $args{$_} for keys %args;
18  
19 3 ▶ $args{referral} = 1 unless defined $args{referral} and !$args{referral};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"referral"} and not $args{"referral"} 3 0 3
Condition33%1/3
defined $args{"referral"} and not $args{"referral"}
!ll&&!rl&&r
300
MC/DC0%0/2
defined $args{"referral"} and not $args{"referral"}
defined $args{"referral"} not $args{"referral"}
Truth table33%1/3
A and not(B)
A= defined $args{"referral"}B= not $args{"referral"}
ABresult
0X0
100
111
20  
21 3 ▶ unless ( $args{query} and $args{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"query"} and $args{"event"}) 0 3 3
Condition33%1/3
$args{"query"} and $args{"event"}
!ll&&!rl&&r
003
MC/DC0%0/2
$args{"query"} and $args{"event"}
$args{"query"} $args{"event"}
Truth table33%1/3
A and B
A= $args{"query"}B= $args{"event"}
ABresult
0X0
100
111
22 0 warn "You must provide a query string and a response event\n";
23 0 return undef;
24 }
25  
26 3 ▶ unless ( $args{host} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"host"}) 2 1 3
27 2 my $whois_server;
28 2 my $tld = POE::Component::Client::Whois::TLDList->new();
29 2 my $blk = POE::Component::Client::Whois::IPBlks->new();
30 SWITCH: {
31 2 ▶ if ( $args{query} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"query"} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ and scalar grep(($_ >= 0 && $_ <= 255), split(/\./, $args{"query"}, 0)) == 4) 0 2 2
Condition16%1/6
$args{"query"} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ and scalar grep(($_ >= 0 && $_ <= 255), split(/\./, $args{"query"}, 0)) == 4
!ll&&!rl&&r
200
$_ >= 0 && $_ <= 255
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"query"} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ and scalar grep(($_ >= 0 && $_ <= 255), split(/\./, $args{"query"}, 0)) == 4
$args{"query"} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ scalar grep(($_ >= 0 && $_ <= 255), split(/\./, $args{"query"}, 0)) == 4
MC/DC0%0/2
$_ >= 0 && $_ <= 255
$_ >= 0 $_ <= 255
Truth table33%1/3
A and B
A= $args{"query"} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/B= scalar grep(($_ >= 0 && $_ <= 255), split(/\./, $args{"query"}, 0)) == 4
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_ >= 0B= $_ <= 255
ABresult
0X0
100
111
32 and
33 scalar( grep $_ >= 0 && $_ <= 255, split /\./, $args{query} ) ==
34 4 )
35 {
36 0 $whois_server = ( $blk->get_server( $args{query} ) )[0];
37 0 ▶ unless ($whois_server) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($whois_server) 0 0 0
38 0 warn
39 "Couldn\'t determine correct whois server, falling back on arin\n";
40 0 $whois_server = 'whois.arin.net';
41 }
42 0 last SWITCH;
43 }
44 2 ▶ if ( $args{query} =~ /:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"query"} =~ /:/) 0 2 2
45 0 warn "IPv6 detected, defaulting to arin\n";
46 0 $whois_server = 'whois.arin.net';
47 0 last SWITCH;
48 }
49 2 $whois_server = ( $tld->tld( $args{query} ) )[0];
50 2 ▶ if ( $whois_server eq 'ARPA' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($whois_server eq "ARPA") 0 2 2
51 0 $args{query} =~ s/\.in-addr\.arpa//;
52 0 $args{query} = join '.', reverse split( /\./, $args{query} );
53 0 $whois_server = ( $blk->get_server( $args{query} ) )[0];
54 0 ▶ unless ($whois_server) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($whois_server) 0 0 0
55 0 warn
56 "Couldn\'t determine correct whois server, falling back on arin\n";
57 0 $whois_server = 'whois.arin.net';
58 }
59 }
60 2 ▶ unless ($whois_server) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($whois_server) 0 2 2
61 0 warn
62 "Could not automagically determine whois server from query string, defaulting to internic \n";
63 0 $whois_server = 'whois.internic.net';
64 }
65 }
66 2 $args{host} = $whois_server;
67 }
68  
69 $args{session} = $poe_kernel->get_active_session()
70 3 ▶ unless ( $args{session} );
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"session"} 3 0 3
71  
72 3 my $self = bless { request => \%args }, $package;
73  
74 3 $self->{session_id} = POE::Session->create(
75 object_states => [
76 $self => [
77 qw(_start _connect _sock_input _sock_down _sock_up _sock_failed _time_out)
78 ],
79 ],
80 options => { trace => 0 },
81 )->ID();
82  
83 3 return $self;
84 }
85  
86 sub _start {
87 3 ▶ my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
Subroutine _start: called CC=1 SCAR=0.0
88 3 $self->{_dot_com} = ( POE::Component::Client::Whois::TLDList->new()->tld('.com') )[0];
89 3 $self->{session_id} = $_[SESSION]->ID();
90 3 $kernel->yield('_connect');
91 3 undef;
92 }
93  
94 sub _connect {
95 3 ▶ my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
Subroutine _connect: called CC=4 SCAR=13.9
96  
97 # Check here for NONE or WEB and send an error straight away.
98 3 ▶ if ( my ($type) = $self->{request}->{host} =~ /^(NONE|WEB)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($type) = $self->{"request"}{"host"} =~ /^(NONE|WEB)$/) 2 1 3
99 2 my $error;
100 2 ▶ if ( $type eq 'NONE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'NONE') { } 1 1 2
101 1 $error = 'This TLD has no whois server.';
102 }
103 else {
104 $error =
105 'This TLD has no whois server, but you can access the '
106 . 'whois database at '
107 . (
108 POE::Component::Client::Whois::TLDList->new->tld(
109 $self->{request}->{query}
110 )
111 1 )[1];
112 }
113 2 $self->{request}->{error} = $error;
114 2 my $request = delete $self->{request};
115 2 my $session = delete $request->{session};
116 2 $kernel->post( $session => $request->{event} => $request );
117 2 return;
118 }
119 $self->{factory} = POE::Wheel::SocketFactory->new(
120 SocketDomain => AF_INET,
121 SocketType => SOCK_STREAM,
122 SocketProtocol => 'tcp',
123 RemoteAddress => $self->{request}->{host},
124 1 ▶ RemotePort => $self->{request}->{port} || 43,
Condition50%1/2
$self->{'request'}{'port'} || 43
l!l
10
MC/DC0%0/1
$self->{'request'}{'port'} || 43
$self->{'request'}{'port'}
Truth table50%1/2
A
A= $self->{'request'}{'port'}
Aresult
11
00
125 SuccessEvent => '_sock_up',
126 FailureEvent => '_sock_failed',
127 );
128 1 undef;
129 }
130  
131 sub _sock_failed {
132 0 ▶ my ( $kernel, $self, $op, $errno, $errstr ) =
Subroutine _sock_failed: not called CC=1 SCAR=6.9
133 @_[ KERNEL, OBJECT, ARG0 .. ARG2 ];
134  
135 0 delete $self->{factory};
136 0 $self->{request}->{error} = "$op error $errno: $errstr";
137 0 my $request = delete $self->{request};
138 0 my $session = delete $request->{session};
139  
140 0 $kernel->post( $session => $request->{event} => $request );
141 0 undef;
142 }
143  
144 sub _sock_up {
145 1 ▶ my ( $kernel, $self, $session, $socket ) =
Subroutine _sock_up: called CC=3 SCAR=12.9
146 @_[ KERNEL, OBJECT, SESSION, ARG0 ];
147 1 delete $self->{factory};
148  
149 1 $self->{'socket'} = new POE::Wheel::ReadWrite(
150 Handle => $socket,
151 Driver => POE::Driver::SysRW->new(),
152 Filter => POE::Filter::Line->new(
153 InputRegexp => '\015?\012',
154 OutputLiteral => "\015\012"
155 ),
156 InputEvent => '_sock_input',
157 ErrorEvent => '_sock_down',
158 );
159  
160 1 ▶ unless ( $self->{'socket'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"socket"}) 0 1 1
161 0 my $request = delete $self->{request};
162 0 my $session = delete $request->{session};
163 $request->{error} =
164 0 "Couldn\'t create a Wheel::ReadWrite on socket for whois";
165 0 $kernel->post( $session => $request->{event} => $request );
166 0 return undef;
167 }
168  
169 my $query = $self->{request}->{host} eq 'de.whois-servers.net'
170 ? join(' ', '-T dn,ace -C US-ASCII', $self->{request}->{query})
171 1 ▶ : $self->{request}->{query};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'request'}{'host'} eq 'de.whois-servers.net' ? : 0 1 1
172  
173 1 $self->{'socket'}->put( $query );
174 1 $kernel->delay( '_time_out' => 30 );
175 1 undef;
176 }
177  
178 sub _sock_down {
179 1 ▶ my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
Subroutine _sock_down: called CC=7 SCAR=27.5
180 1 delete $self->{socket};
181 1 $kernel->delay( '_time_out' => undef );
182  
183 1 ▶ if ( $self->{request}->{referral} and $self->{_referral} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"request"}{"referral"} and $self->{"_referral"}) 0 1 1
Condition33%1/3
$self->{"request"}{"referral"} and $self->{"_referral"}
!ll&&!rl&&r
010
MC/DC0%0/2
$self->{"request"}{"referral"} and $self->{"_referral"}
$self->{"request"}{"referral"} $self->{"_referral"}
Truth table33%1/3
A and B
A= $self->{"request"}{"referral"}B= $self->{"_referral"}
ABresult
0X0
100
111
184 0 ▶ delete $self->{request}->{reply} if $self->{referral_only};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"referral_only"} 0 0 0
185 0 my $referral = delete $self->{_referral};
186 0 my ($host,$port) = split /:/, $referral;
187 0 $self->{request}->{host} = $host;
188 0 ▶ $self->{request}->{port} = ( $port ? $port : '43' );
Branch: 1 branch
BranchTrueFalseTotal
$port ? : 0 0 0
189 0 $kernel->yield('_connect');
190 0 return;
191 }
192  
193 1 my $request = delete $self->{request};
194 1 my $session = delete $request->{session};
195  
196 1 ▶ if ( defined( $request->{reply} ) and ref( $request->{reply} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $request->{'reply'} and ref $request->{'reply'} eq 'ARRAY') { } 1 0 1
Condition33%1/3
defined $request->{"reply"} and ref $request->{"reply"} eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $request->{"reply"} and ref $request->{"reply"} eq "ARRAY"
defined $request->{"reply"} ref $request->{"reply"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $request->{"reply"}B= ref $request->{"reply"} eq "ARRAY"
ABresult
0X0
100
111
197 {
198 1 delete $request->{error};
199 }
200 else {
201 0 $request->{error} = "No information received from remote host";
202 }
203 1 $kernel->post( $session => $request->{event} => $request );
204 1 undef;
205 }
206  
207 sub _sock_input {
208 34 ▶ my ( $kernel, $self, $line ) = @_[ KERNEL, OBJECT, ARG0 ];
Subroutine _sock_input: called CC=8 SCAR=34.0
209 34 push @{ $self->{request}->{reply} }, $line;
210 34 ▶ if ( my ($referral) = $line =~ /ReferralServer:\s+(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($referral) = $line =~ /ReferralServer:\s+(.*)$/) 0 34 34
211 0 my ( $scheme, $authority, $path, $query, $fragment ) = $referral =~
212 m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
213 0 ▶ return unless $scheme and $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme and $authority 0 0 0
Condition0%0/3
$scheme and $authority
!ll&&!rl&&r
000
MC/DC0%0/2
$scheme and $authority
$scheme $authority
Truth table0%0/3
A and B
A= $schemeB= $authority
ABresult
0X0
100
111
214 0 $scheme = lc $scheme;
215 0 ▶ return unless $scheme =~ m'r?whois';
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme =~ /r?whois/ 0 0 0
216 0 my ( $host, $port ) = split /:/, $authority;
217 0 ▶ return if $host eq $self->{request}->{host};
Branch: 1 branch
BranchTrueFalseTotal
if $host eq $self->{"request"}{"host"} 0 0 0
218 0 $self->{_referral} = $authority;
219 }
220 34 ▶ if ( $self->{request}->{host} eq $self->{_dot_com}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"request"}{"host"} eq $self->{"_dot_com"} and my($other) = $line =~ /Whois Server:\s+(.*)\s*$/i) 0 34 34
Condition33%1/3
$self->{"request"}{"host"} eq $self->{"_dot_com"} and my($other) = $line =~ /Whois Server:\s+(.*)\s*$/i
!ll&&!rl&&r
3400
MC/DC0%0/2
$self->{"request"}{"host"} eq $self->{"_dot_com"} and my($other) = $line =~ /Whois Server:\s+(.*)\s*$/i
$self->{"request"}{"host"} eq $self->{"_dot_com"} my($other) = $line =~ /Whois Server:\s+(.*)\s*$/i
Truth table33%1/3
A and B
A= $self->{"request"}{"host"} eq $self->{"_dot_com"}B= my($other) = $line =~ /Whois Server:\s+(.*)\s*$/i
ABresult
0X0
100
111
221 and my ($other) = $line =~ /Whois Server:\s+(.*)\s*$/i )
222 {
223 0 $self->{_referral} = $other;
224 }
225 34 undef;
226 }
227  
228 sub _time_out {
229 0 ▶ my ( $kernel, $self ) = @_[ KERNEL, OBJECT ];
Subroutine _time_out: not called CC=1 SCAR=6.9
230 0 delete $self->{'socket'};
231 0 undef;
232 }
233  
234 5 1;
235  
236 __END__
↑ Summary Whois/TLDList.pm »