blib/lib/Net/IRR.pm

filter: Statementstmt 77.7% 108 / 139 Branchbran 36.4% 27 / 74 Conditioncond 37.5% 9 / 24 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 84.6% 22 / 26 Podpod 100% 14 / 14 totaltotal 61.9% 181 / 292 CC 47 SCAR 22.7
CC
47
Cov
61%
get_ipv6_routes_by_origin
30.0
get_routes_by_community
20.0
sources
20.0
CRAP 9.7
↑ Summary
1 package Net::IRR;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use vars qw/ @ISA %EXPORT_TAGS @EXPORT_OK $VERSION /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 $VERSION = '0.10';
12  
13 # used for route searches
14 1 ▶use constant EXACT_MATCH => 'o';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant ONE_LEVEL => 'l';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant LESS_SPECIFIC => 'L';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use constant MORE_SPECIFIC => 'M';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 require Exporter;
20 1 @ISA = qw(Exporter);
21 1 @EXPORT_OK = qw( EXACT_MATCH ONE_LEVEL LESS_SPECIFIC MORE_SPECIFIC );
22 1 %EXPORT_TAGS = (
23 'all' => \@EXPORT_OK,
24 'route' => \@EXPORT_OK,
25 );
26  
27 # constructor
28 1 ▶sub connect {
Subroutine connect: called CC=7 SCAR=22.0
Pod documented
29 1 my ($class, %args) = @_;
30 1 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
31 1 ▶ $self->{host} = $args{host} || '127.0.0.1';
Condition50%1/2
$args{'host'} || '127.0.0.1'
l!l
10
MC/DC0%0/1
$args{'host'} || '127.0.0.1'
$args{'host'}
Truth table50%1/2
A
A= $args{'host'}
Aresult
11
00
32 1 ▶ $self->{port} = $args{port} || 43;
Condition50%1/2
$args{'port'} || 43
l!l
01
MC/DC0%0/1
$args{'port'} || 43
$args{'port'}
Truth table50%1/2
A
A= $args{'port'}
Aresult
11
00
33 1 ▶ $self->{timeout} = $args{timeout} || 5;
Condition50%1/2
$args{'timeout'} || 5
l!l
01
MC/DC0%0/1
$args{'timeout'} || 5
$args{'timeout'}
Truth table50%1/2
A
A= $args{'timeout'}
Aresult
11
00
34 $self->{tcp} = IO::Socket::INET->new(
35 PeerAddr => $self->{host},
36 PeerPort => $self->{port},
37 1 Proto => 'tcp'
38 );
39  
40 1 ▶ unless ($self->{tcp}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tcp"}) 0 1 1
41 0 $self->{errstr} = "cannot create socket: $@";
42 0 return;
43 }
44  
45 1 ▶ return undef if $self->error();
Branch: 1 branch
BranchTrueFalseTotal
if $self->error 0 1 1
46 1 $self->_multi_mode();
47 1 $self->_identify();
48 1 return $self;
49 }
50  
51 1 ▶sub get_routes_by_origin {
Subroutine get_routes_by_origin: called CC=5 SCAR=17.8
Pod documented
52 1 my ($self, $as) = @_;
53 1 ▶ croak 'usage: $whois->get_routes_by_origin( $as_number )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 1 1
54 unless @_ == 2;
55 1 ▶ $as = 'as'.$as unless $as =~ /^as/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $as =~ /^as/i 0 1 1
56 1 $self->{tcp}->send("!g${as}\n");
57 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
58 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
59 }
60 0 return ();
61 }
62  
63 # RIPE-181 Only
64 0 ▶sub get_routes_by_community {
Subroutine get_routes_by_community: not called CC=4 SCAR=30.0
Pod documented
65 0 my ($self, $community) = @_;
66 0 ▶ croak 'usage: $whois->get_routes_by_community( $community )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
67 unless @_ == 2;
68 0 $self->{tcp}->send("!h${community}\n");
69 0 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 0 0 0
70 0 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
71 }
72 0 return ();
73 }
74  
75 0 ▶sub get_ipv6_routes_by_origin {
Subroutine get_ipv6_routes_by_origin: not called CC=5 SCAR=34.0
Pod documented
76 0 my ($self, $as) = @_;
77 0 ▶ croak 'usage: $whois->get_ipv6_routes_by_origin( $as_number )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
78 unless @_ == 2;
79 0 ▶ $as = 'as'.$as unless $as =~ /^as/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $as =~ /^as/i 0 0 0
80 0 $self->{tcp}->send("!6${as}\n");
81 0 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 0 0 0
82 0 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
83 }
84 0 return ();
85 }
86  
87 1 ▶sub get_sync_info {
Subroutine get_sync_info: called CC=2 SCAR=7.0
Pod documented
88 1 my ($self, @dbs) = @_;
89 1 ▶ my $dbs = (@dbs) ? join(",",@dbs) : '-*';
Branch: 1 branch
BranchTrueFalseTotal
@dbs ? : 0 1 1
90 1 $self->{tcp}->send("!j${dbs}\n");
91 1 return $self->_response();
92 }
93  
94 1 ▶sub get_as_set {
Subroutine get_as_set: called CC=6 SCAR=20.9
Pod documented
95 1 my ($self, $as_set, $expand) = @_;
96 1 ▶ croak 'usage: $whois->get_as_set( $as_set )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 and @_ <= 3 0 1 1
Condition33%1/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
001
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
97 unless @_ >= 2 && @_ <= 3;
98 1 ▶ $expand = ($expand) ? ',1' : '';
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 1 0 1
99 1 $self->{tcp}->send("!i${as_set}${expand}\n");
100 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
101 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
102 }
103 0 return ();
104 }
105  
106 1 ▶sub get_route_set { my ($self, $route_set, $expand) = @_;
Subroutine get_route_set: called CC=6 SCAR=20.9
Pod documented
107 1 ▶ croak 'usage: $whois->get_route_set( $route_set )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 and @_ <= 3 0 1 1
Condition33%1/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
001
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
108 unless @_ >= 2 && @_ <= 3;
109 1 ▶ $expand = ($expand) ? ',1' : '';
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 1 0 1
110 1 $self->{tcp}->send("!i${route_set}${expand}\n");
111 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
112 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
113 }
114 0 return ();
115 }
116  
117 1 ▶sub match {
Subroutine match: called CC=2 SCAR=7.0
Pod documented
118 1 my ($self, $type, $key) = @_;
119 1 ▶ croak 'usage: $whois->match( $object_type, $key )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 1 1
120 unless @_ == 3;
121 1 $self->{tcp}->send("!m${type},${key}\n");
122 1 return $self->_response();
123 }
124  
125 1 *disconnect = \&quit;
126 1 ▶sub quit {
Subroutine quit: called CC=1 SCAR=0.0
Pod documented
127 1 my $self = shift;
128 1 $self->{tcp}->send("!q\n");
129 }
130  
131 1 ▶sub _identify {
Subroutine _identify: called CC=1 SCAR=0.0
132 1 my ($self) = @_;
133 1 $self->{tcp}->send("!nNet::IRR\n");
134 1 return $self->_response();
135 }
136  
137 1 ▶sub _multi_mode {
Subroutine _multi_mode: called CC=1 SCAR=0.0
138 1 my ($self) = @_;
139 1 $self->{tcp}->send("!!\n");
140 1 return 1;
141 }
142  
143 1 ▶sub get_irrd_version {
Subroutine get_irrd_version: called CC=1 SCAR=0.0
Pod documented
144 1 my ($self) = @_;
145 1 $self->{tcp}->send("!v\n");
146 1 return $self->_response();
147 }
148  
149 2 ▶sub route_search {
Subroutine route_search: called CC=6 SCAR=19.6
Pod documented
150 2 my ($self, $route, $specific) = @_;
151 2 ▶ croak 'usage: $whois->route_search( $route )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 and @_ <= 3 0 2 2
Condition33%1/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
002
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
152 unless @_ >= 2 && @_ <= 3;
153 2 ▶ $specific = ($specific) ? ",$specific" : '';
Branch: 1 branch
BranchTrueFalseTotal
$specific ? : 2 0 2
154 2 $self->{tcp}->send("!r${route}${specific}\n");
155 2 my $response = $self->_response();
156 2 ▶ chomp($response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 2 2
157 2 ▶ $response =~ s/\s*$// if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 2 2
158 2 return $response;
159 }
160  
161 0 ▶sub sources {
Subroutine sources: not called CC=4 SCAR=30.0
Pod documented
162 0 my ($self, @sources) = @_;
163 0 ▶ my $source = (@sources) ? join(",", @sources) : '-lc';
Branch: 1 branch
BranchTrueFalseTotal
@sources ? : 0 0 0
164 0 $self->{tcp}->send("!s${source}\n");
165 0 my $response = $self->_response();
166 0 ▶ chomp($response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
167 0 ▶ return wantarray ? split(',', $response) : $response;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
168 }
169  
170 0 ▶sub update {
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
171 0 my ($self, $db, $action, $object) = @_;
172 0 ▶ croak 'usage: $whois->update( $db, "ADD|DEL", $object )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
173 unless @_ == 4;
174 0 ▶ croak 'second argument to $whois->update() must be either ADD or DEL'
Branch: 1 branch
BranchTrueFalseTotal
unless $action eq "ADD" or $action eq "DEL" 0 0 0
Condition0%0/3
$action eq "ADD" or $action eq "DEL"
l!l&&r!l&&!r
000
MC/DC0%0/2
$action eq "ADD" or $action eq "DEL"
$action eq "ADD" $action eq "DEL"
Truth table0%0/3
A or B
A= $action eq "ADD"B= $action eq "DEL"
ABresult
1X1
011
000
175 unless $action eq 'ADD' || $action eq 'DEL';
176 0 $self->{tcp}->send( sprintf("!us%s\n%s\n\n%s\n\n!ue\n", $db, $action, $object) );
177 0 return $self->_response();
178 }
179  
180 9 ▶sub _response {
Subroutine _response: called CC=7 SCAR=20.0
181 9 my $self = shift;
182 9 my $t = $self->{tcp};
183 9 my $header = $t->getline();
184 9 my $error_prefix = 'Net::IRR read error';
185 9 ▶ if (not defined $header) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $header) 0 9 9
186 0 $self->{errstr} = sprintf("%s: no data read from %s:%d\n", $error_prefix, $self->{host}, $self->{port});
187 0 return ();
188 }
189 9 ▶ return () if ($header =~ /^[CDEF].*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $header =~ /^[CDEF].*$/ 3 6 9
190 6 my $timeout = time() + $self->{timeout};
191 6 my($data_length) = $header =~ /^A(.*)$/;
192 6 my $data = '';
193 6 ▶ while($data_length != length($data) && time() <= $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_length != length $data and time <= $timeout) 380 6 386
Condition66%2/3
$data_length != length $data and time <= $timeout
!ll&&!rl&&r
60380
MC/DC50%1/2
$data_length != length $data and time <= $timeout
$data_length != length $data time <= $timeout
Truth table66%2/3
A and B
A= $data_length != length $dataB= time <= $timeout
ABresult
0X0
100
111
194 380 my $line = $t->getline();
195 380 ▶ if( defined($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 380 0 380
196 380 $data .= $line;
197 }
198 }
199 carp sprintf("%s: only received %d out of %d bytes from %s:%d\n", $error_prefix, length($data), $data_length, $self->{host}, $self->{port})
200 6 ▶ if $data_length != length($data);
Branch: 1 branch
BranchTrueFalseTotal
if $data_length != length $data 0 6 6
201 6 my $footer = $t->getline();
202 6 return $data;
203 }
204  
205 2 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
206 2 my $self = shift;
207 2 return $self->{errstr};
208 }
209  
210 1 1;
211 __END__
↑ Summary