blib/lib/Net/IRR.pm

filter: Statementstmt 77.0% 104 / 135 Branchbran 36.1% 26 / 72 Conditioncond 31.5% 6 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 84.6% 22 / 26 Podpod 100% 14 / 14 totaltotal 61.8% 172 / 278 CC 44 SCAR 22.5
CC
44
Cov
60%
get_ipv6_routes_by_origin
30.0
get_routes_by_community
20.0
sources
20.0
CRAP 9.5
↑ 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.09';
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 sub connect {
29 1 ▶ my ($class, %args) = @_;
Subroutine connect: called CC=6 SCAR=20.2
Pod documented
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 $self->{tcp} = IO::Socket::INET->new(
34 PeerAddr => $self->{host},
35 PeerPort => $self->{port},
36 1 Proto => 'tcp'
37 );
38  
39 1 ▶ unless ($self->{tcp}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tcp"}) 0 1 1
40 0 $self->{errstr} = "cannot create socket: $@";
41 0 return;
42 }
43  
44 1 ▶ return undef if $self->error();
Branch: 1 branch
BranchTrueFalseTotal
if $self->error 0 1 1
45 1 $self->_multi_mode();
46 1 $self->_identify();
47 1 return $self;
48 }
49  
50 sub get_routes_by_origin {
51 1 ▶ my ($self, $as) = @_;
Subroutine get_routes_by_origin: called CC=5 SCAR=17.8
Pod documented
52 1 ▶ croak 'usage: $whois->get_routes_by_origin( $as_number )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 1 1
53 unless @_ == 2;
54 1 ▶ $as = 'as'.$as unless $as =~ /^as/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $as =~ /^as/i 0 1 1
55 1 $self->{tcp}->send("!g${as}\n");
56 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
57 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
58 }
59 0 return ();
60 }
61  
62 # RIPE-181 Only
63 sub get_routes_by_community {
64 0 ▶ my ($self, $community) = @_;
Subroutine get_routes_by_community: not called CC=4 SCAR=30.0
Pod documented
65 0 ▶ croak 'usage: $whois->get_routes_by_community( $community )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
66 unless @_ == 2;
67 0 $self->{tcp}->send("!h${community}\n");
68 0 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 0 0 0
69 0 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
70 }
71 0 return ();
72 }
73  
74 sub get_ipv6_routes_by_origin {
75 0 ▶ my ($self, $as) = @_;
Subroutine get_ipv6_routes_by_origin: not called CC=5 SCAR=34.0
Pod documented
76 0 ▶ croak 'usage: $whois->get_ipv6_routes_by_origin( $as_number )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
77 unless @_ == 2;
78 0 ▶ $as = 'as'.$as unless $as =~ /^as/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $as =~ /^as/i 0 0 0
79 0 $self->{tcp}->send("!6${as}\n");
80 0 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 0 0 0
81 0 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
82 }
83 0 return ();
84 }
85  
86 sub get_sync_info {
87 1 ▶ my ($self, @dbs) = @_;
Subroutine get_sync_info: called CC=2 SCAR=7.0
Pod documented
88 1 ▶ my $dbs = (@dbs) ? join(",",@dbs) : '-*';
Branch: 1 branch
BranchTrueFalseTotal
@dbs ? : 0 1 1
89 1 $self->{tcp}->send("!j${dbs}\n");
90 1 return $self->_response();
91 }
92  
93 sub get_as_set {
94 1 ▶ my ($self, $as_set, $expand) = @_;
Subroutine get_as_set: called CC=6 SCAR=20.9
Pod documented
95 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
96 unless @_ >= 2 && @_ <= 3;
97 1 ▶ $expand = ($expand) ? ',1' : '';
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 1 0 1
98 1 $self->{tcp}->send("!i${as_set}${expand}\n");
99 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
100 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
101 }
102 0 return ();
103 }
104  
105 1 ▶sub get_route_set { my ($self, $route_set, $expand) = @_;
Subroutine get_route_set: called CC=6 SCAR=20.9
Pod documented
106 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
107 unless @_ >= 2 && @_ <= 3;
108 1 ▶ $expand = ($expand) ? ',1' : '';
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 1 0 1
109 1 $self->{tcp}->send("!i${route_set}${expand}\n");
110 1 ▶ if (my $data = $self->_response()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->_response) 1 0 1
111 1 ▶ return wantarray ? split(" ", $data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
112 }
113 0 return ();
114 }
115  
116 sub match {
117 1 ▶ my ($self, $type, $key) = @_;
Subroutine match: called CC=2 SCAR=7.0
Pod documented
118 1 ▶ croak 'usage: $whois->match( $object_type, $key )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 1 1
119 unless @_ == 3;
120 1 $self->{tcp}->send("!m${type},${key}\n");
121 1 return $self->_response();
122 }
123  
124 1 *disconnect = \&quit;
125 sub quit {
126 1 ▶ my $self = shift;
Subroutine quit: called CC=1 SCAR=0.0
Pod documented
127 1 $self->{tcp}->send("!q\n");
128 }
129  
130 sub _identify {
131 1 ▶ my ($self) = @_;
Subroutine _identify: called CC=1 SCAR=0.0
132 1 $self->{tcp}->send("!nNet::IRR\n");
133 1 return $self->_response();
134 }
135  
136 sub _multi_mode {
137 1 ▶ my ($self) = @_;
Subroutine _multi_mode: called CC=1 SCAR=0.0
138 1 $self->{tcp}->send("!!\n");
139 1 return 1;
140 }
141  
142 sub get_irrd_version {
143 1 ▶ my ($self) = @_;
Subroutine get_irrd_version: called CC=1 SCAR=0.0
Pod documented
144 1 $self->{tcp}->send("!v\n");
145 1 return $self->_response();
146 }
147  
148 sub route_search {
149 2 ▶ my ($self, $route, $specific) = @_;
Subroutine route_search: called CC=6 SCAR=19.6
Pod documented
150 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
151 unless @_ >= 2 && @_ <= 3;
152 2 ▶ $specific = ($specific) ? ",$specific" : '';
Branch: 1 branch
BranchTrueFalseTotal
$specific ? : 2 0 2
153 2 $self->{tcp}->send("!r${route}${specific}\n");
154 2 my $response = $self->_response();
155 2 ▶ chomp($response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 2 2
156 2 ▶ $response =~ s/\s*$// if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 2 2
157 2 return $response;
158 }
159  
160 sub sources {
161 0 ▶ my ($self, @sources) = @_;
Subroutine sources: not called CC=4 SCAR=30.0
Pod documented
162 0 ▶ my $source = (@sources) ? join(",", @sources) : '-lc';
Branch: 1 branch
BranchTrueFalseTotal
@sources ? : 0 0 0
163 0 $self->{tcp}->send("!s${source}\n");
164 0 my $response = $self->_response();
165 0 ▶ chomp($response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
166 0 ▶ return wantarray ? split(',', $response) : $response;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
167 }
168  
169 sub update {
170 0 ▶ my ($self, $db, $action, $object) = @_;
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
171 0 ▶ croak 'usage: $whois->update( $db, "ADD|DEL", $object )'
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
172 unless @_ == 4;
173 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
174 unless $action eq 'ADD' || $action eq 'DEL';
175 0 $self->{tcp}->send( sprintf("!us%s\n%s\n\n%s\n\n!ue\n", $db, $action, $object) );
176 0 return $self->_response();
177 }
178  
179 sub _response {
180 9 ▶ my $self = shift;
Subroutine _response: called CC=5 SCAR=16.4
181 9 my $t = $self->{tcp};
182 9 my $header = $t->getline();
183 9 my $error_prefix = 'Net::IRR read error';
184 9 ▶ if (not defined $header) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $header) 0 9 9
185 0 $self->{errstr} = sprintf("%s: no data read from %s:%d\n", $error_prefix, $self->{host}, $self->{port});
186 0 return ();
187 }
188 9 ▶ return () if ($header =~ /^[CDEF].*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $header =~ /^[CDEF].*$/ 3 6 9
189 6 my($data_length) = $header =~ /^A(.*)$/;
190 6 my $data = '';
191 6 ▶ while($data_length != length($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_length != length $data) 380 6 386
192 380 $data .= $t->getline();
193 }
194 carp sprintf("%s: only received %d out of %d bytes from %s:%d\n", $error_prefix, length($data), $data_length, $self->{host}, $self->{port})
195 6 ▶ if $data_length != length($data);
Branch: 1 branch
BranchTrueFalseTotal
if $data_length != length $data 0 6 6
196 6 my $footer = $t->getline();
197 6 return $data;
198 }
199  
200 sub error {
201 2 ▶ my $self = shift;
Subroutine error: called CC=1 SCAR=0.0
Pod documented
202 2 return $self->{errstr};
203 }
204  
205 1 1;
206 __END__
↑ Summary