| 1 | package Net::DAS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Net::DAS - Simple Domain Availabilty Seach client. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # new object | ||||||||||||||||||||||||||||||||||||||||||
| 12 | my $das = Net::DAS->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # you can change query timeout, set to use registrar DAS servers (where available), select only specific modules, and override the requst function (normally for testing) | ||||||||||||||||||||||||||||||||||||||||||
| 14 | my $das = Net::DAS->new({timeout=>2,use_registrar=>1,modules=>['eu','be'],_request=>\&my_request}); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # lookup() always works in batch mode, so if you are only looking up a single domain you can access that domains result directly | ||||||||||||||||||||||||||||||||||||||||||
| 17 | my $res =$das->lookup('test.eu')->{'test.eu'}; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | if ($res->{'avail'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # do something | ||||||||||||||||||||||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | print $res->{'reason'}; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # or with multiple domains | ||||||||||||||||||||||||||||||||||||||||||
| 25 | my $res =$das->lookup('test.eu','test2.eu','test3.eu'); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | print $res->{'test2.eu'}->{'reason'}; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | Net::DAS is a client that aims to simplify using DAS with multiple registries by having small submodules (see L<Net::DAS::*>) to iron out the differences in the servers. It also inclused a shell script L<Net::DAS::das> to do lookups from the command line. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 13 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | use Carp qw (croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | ▶ | use Time::HiRes qw (usleep); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | our $VERSION = '0.19'; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 13 | our @modules = qw (EU BE NO LT UK SI IT GENT SE NU RO); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | Accepts a hash reference with available options being timeout (integer default 4), use_registrar (bool default 0), modules (array_ref default all), _request (sub - only used for overriding request method for testing) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | my $das = Net::DAS->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | my $das = Net::DAS->new({timeout=>2,use_registrar=>1,modules=>['eu','be'],_request=>\&my_request}); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | my $self = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | $self->{tlds} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | ▶ | $self->{use_registrar} = undef unless exists $self->{use_registrar}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | $self->{timeout} = 4 unless exists $self->{timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | $self->{_request} = \&_send_request unless exists $self->{_request}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | our (@modules); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | @modules = @{ $self->{modules} } if exists $self->{modules}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 12 | my ( $m, $t ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | foreach (@modules) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | $m = 'Net::DAS::' . uc($_); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | load($m); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | $self->{$m} = $m->register(); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 11 | foreach my $t ( @{ $self->{$m}->{tlds} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 29 | $self->{tlds}->{$t} = $m; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | warn "Warning: unable to load module $m: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =head2 lookup | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | Lookup domain availability in batch mode. You can specify 1 or more domains, but always works in batch mode, so if you are only looking up a single domain you can access that domains result directly by using the domain name as a reference. When looking up multiple domains, just send an array and the return will be a hashref with the domain names as the keys | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | my $res =$das->lookup('test.eu')->{'test.eu'}; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | if ($res->{'avail'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # do something | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | print $res->{'reason'}; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # or with multiple domains | ||||||||||||||||||||||||||||||||||||||||||
| 101 | my $res =$das->lookup('test.eu','test2.eu','test3.eu'); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | my $res =$das->lookup(@domains); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | print $res->{'test2.eu'}->{'reason'}; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 53 | ▶ | sub lookup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=14 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 53 | my ( $self, @domains ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 53 | ▶ | return { 'avail' => -1, 'reason' => 'NO DOMAIN SPECIFIED' } unless @domains; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 53 | my ( $r, $b ) = {}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 53 | foreach my $i (@domains) { | |||||||||||||||||||||||||||||||||||||||||
| 112 | 53 | chomp($i); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 53 | $r = { 'domain' => $i }; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 53 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 115 | 53 | ( $r->{'label'}, $r->{'tld'} ) = $self->_split_domain($i); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 53 | ▶ | croak("TLD ($r->{'tld'}) not supported") unless ( $r->{'module'} = $self->{tlds}->{ $r->{'tld'} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 53 | ▶ | my ($disp) = defined $self->{ $r->{module} }->{dispatch} ? $self->{ $r->{module} }->{dispatch} : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 53 | ▶ | chomp( $r->{'query'} = defined( $disp->[0] ) ? $disp->[0]->( $r->{'domain'} ) : $r->{'domain'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | local $SIG{ALRM} = sub { die "TIMEOUT\n" }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 53 | alarm $self->{timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 53 | chomp( $r->{'response'} = $self->{_request}->( $self, $r->{'query'}, $r->{module} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 53 | alarm 0; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | $r->{'avail'} | ||||||||||||||||||||||||||||||||||||||||||
| 126 | = defined( $disp->[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ? $disp->[1]->( $r->{'response'}, $i ) | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 53 | ▶ | : $self->_parse( $r->{'response'}, $i ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 53 | ▶ | $r->{'reason'} = 'AVAILABLE' if $r->{'avail'} == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 53 | ▶ | $r->{'reason'} = 'NOT AVAILABLE' if $r->{'avail'} == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 53 | ▶ | $r->{'reason'} = 'NOT VALID' if $r->{'avail'} == -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 53 | ▶ | $r->{'reason'} = 'NOT AUTHORIZED' if $r->{'avail'} == -2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 53 | ▶ | $r->{'reason'} = 'IP BLOCKED' if $r->{'avail'} == -3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 53 | ▶ | $r->{'reason'} = 'UNABLE TO PARSE RESPONSE' if $r->{'avail'} == -100; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 53 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | chomp( $r->{reason} = $@ ); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $r->{avail} = -1; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 53 | $b->{$i} = $r; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 53 | $self->_close_ports(); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 53 | return $b; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | =head2 available | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | A quick function to lookup availability of a single domain without details. Warning, you should check if the result == 1, as there are different return codes. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | print "available" if $das->availabile('test.eu')==1; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 26 | ▶ | sub available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 26 | my ( $self, $dom ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 26 | my $r = $self->lookup($dom); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 26 | return $r->{$dom}->{'avail'}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head1 PRIVATE METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =item _split_domain : splits a domain into an array ($dom,$tld) | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 55 | ▶ | sub _split_domain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_domain: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 55 | my ( $self, $i ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 55 | ▶ | return ( $1, $2 ) if $i =~ m/(.*)\.(.*\..*)/ && exists $self->{tlds}->{$2}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i =~ /(.*)\.(.*\..*)/ and exists $self->{"tlds"}{$2}
MC/DC50%1/2
$i =~ /(.*)\.(.*\..*)/ and exists $self->{"tlds"}{$2}
$i =~ /(.*)\.(.*\..*)/
exists $self->{"tlds"}{$2}
Truth table66%2/3
A and B
A= $i =~ /(.*)\.(.*\..*)/B= exists $self->{"tlds"}{$2}
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 47 | ▶ | return ( $1, $2 ) if $i =~ m/(.*)\.(.*)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | croak( 'Invalid domain ' . $i ); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =item _send_request : should not be called directly, its called by lookup() | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub _send_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_request: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my ( $self, $q, $m ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $svc = ( $self->{use_registrar} && exists $self->{$m}->{registrar} ) ? 'registrar' : 'public'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"use_registrar"} and exists $self->{$m}{"registrar"}
MC/DC0%0/2
$self->{"use_registrar"} and exists $self->{$m}{"registrar"}
$self->{"use_registrar"}
exists $self->{$m}{"registrar"}
Truth table0%0/3
A and B
A= $self->{"use_registrar"}B= exists $self->{$m}{"registrar"}
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $h = $self->{$m}->{$svc}->{host}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $p = defined $self->{$m}->{$svc}->{port} ? $self->{$m}->{$svc}->{port} : 4343; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $pr = defined $self->{$m}->{$svc}->{proto} ? $self->{$m}->{$svc}->{proto} : 'tcp'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $nl = defined $self->{$m}->{nl} ? $self->{$m}->{nl} : "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( !$self->{$m}->{sock} || !$self->{$m}->{sock}->connected() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{$m}{"sock"} and $self->{$m}{"sock"}->connected
MC/DC0%0/2
$self->{$m}{"sock"} and $self->{$m}{"sock"}->connected
$self->{$m}{"sock"}
$self->{$m}{"sock"}->connected
Truth table0%0/3
A and B
A= $self->{$m}{"sock"}B= $self->{$m}{"sock"}->connected
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $self->{$m}->{sock} = IO::Socket::INET->new( PeerAddr => $h, PeerPort => $p, Proto => $pr, Timeout => 30 ) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'IO::Socket::INET'->new('PeerAddr', $h, 'PeerPort', $p, 'Proto', $pr, 'Timeout', 30) || croak("Unable to connect to ${h}:$p $@")
MC/DC0%0/1
'IO::Socket::INET'->new('PeerAddr', $h, 'PeerPort', $p, 'Proto', $pr, 'Timeout', 30) || croak("Unable to connect to ${h}:$p $@")
'IO::Socket::INET'->new('PeerAddr', $h, 'PeerPort', $p, 'Proto', $pr, 'Timeout', 30)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('PeerAddr', $h, 'PeerPort', $p, 'Proto', $pr, 'Timeout', 30)
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | || croak("Unable to connect to $h:$p $@"); | ||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | #usleep($self->{$m}->{delay}) if exists $self->{$m}->{delay}; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->{$m}->{sock}->syswrite( $q . "$nl" ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my ( $res, $buf ); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | while ( $self->{$m}->{sock}->sysread( $buf, 1024 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $res .= $buf; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | last if $self->{$m}->{sock}->atmark; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | unless ( exists $self->{$m}->{close_cmd} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->{$m}->{sock}->close(); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | undef $self->{$m}->{sock}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | =item _parse : should not be called directly, its called by lookup(). This sub is normally overriden by the registry module's parser | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 26 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 26 | chomp( my $i = uc(shift) ); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 26 | ▶ | return -3 if $i =~ m/IP ADDRESS BLOCKED/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 26 | ▶ | return 1 if $i =~ m/.*STATUS:\sAVAILABLE/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 14 | ▶ | return 0 if $i =~ m/.*STATUS:\sNOT AVAILABLE/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | return -1 if $i =~ m/.*STATUS:\sNOT VALID/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | return (-100); | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | =item _close_ports : closes any open sockets; you should'nt need to call this. | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 65 | ▶ | sub _close_ports { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_ports: called CC=7 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 65 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 65 | ▶ | return unless defined $self->{modules}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 65 | foreach my $k ( @{ $self->{modules} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | 58 | my $m = 'NET::DAS' . $k; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 58 | ▶ | next unless exists $self->{$m} && !defined $self->{$m}->{sock} && $self->{$m}->{sock}->connected(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $self->{$m} and not defined $self->{$m}{"sock"} and $self->{$m}{"sock"}->connected
exists $self->{$m} and not defined $self->{$m}{"sock"}
MC/DC0%0/3
exists $self->{$m} and not defined $self->{$m}{"sock"} and $self->{$m}{"sock"}->connected
exists $self->{$m}
not defined $self->{$m}{"sock"}
$self->{$m}{"sock"}->connected
Truth table25%1/4
A and not(B) and C
A= exists $self->{$m}B= not defined $self->{$m}{"sock"}C= $self->{$m}{"sock"}->connected
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | $self->{$m}->{sock}->syswrite( $self->{$m}->{close_cmd} ) if exists $self->{$m}->{close_cmd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | undef $self->{$m}->{sock}; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 65 | return; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | =item DESTROY: ensures that any open sockets are closed cleanly before closing; you dont need to call this. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 12 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 12 | ▶ | $self->_close_ports() if defined $self->{modules}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 12 | undef $self->{modules}; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | Michael Holloway <michael@thedarkwinter.com> | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | Artistic License | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | =cut | ||||||||||||||||||||||||||||||||||||||||||