InternetData/AsnResult.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 75.0% 3 / 4 totaltotal 93.5% 58 / 62 CC 9 SCAR 13.6
CC
9
Cov
96%
from_wire
7.0
has
3.0
raw
2.0
CRAP 3.9
« InternetData/DomainResult.pm ↑ Summary InternetData/Result.pm »
1 package InternetData::AsnResult;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 our $VERSION = '1.16.0';
9  
10 # Copied as served. Those the spec does not require are paid, and absent from an
11 # answer whose plan leaves them out.
12 8 our @MEMBERS = qw(
13 name country registry allocated domain type num_ips num_prefixes4 num_prefixes6 rpki_valid
14 rpki_invalid rpki_not_found whois prefixes rank num_upstreams upstreams num_peers peers
15 num_downstreams downstreams hosted_domains
16 );
17 8 our @MARKERS = qw(tier1 trial_expired cap_reached);
18  
19 8 my %KNOWN = map { $_ => 1 } 'asn', @MEMBERS, @MARKERS;
20  
21 # Copied on key PRESENCE, never on truthiness, as InternetData::Result is.
22 11 ▶sub from_wire {
Subroutine from_wire: called CC=7 SCAR=19.5
Pod undocumented
23 11 my ($class, $body) = @_;
24 11 my %answer = (asn => $body->{asn});
25 11 for my $marker (@MARKERS) {
26 33 ▶ next unless exists $body->{$marker};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $body->{$marker} 29 4 33
27 4 ▶ $answer{$marker} = defined $body->{$marker} ? ($body->{$marker} ? 1 : 0) : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $body->{$marker} ? : 4 0 4
$body->{$marker} ? : 2 2 4
28 }
29 11 for my $member (@MEMBERS) {
30 242 ▶ $answer{$member} = $body->{$member} if exists $body->{$member};
Branch: 1 branch
BranchTrueFalseTotal
if exists $body->{$member} 72 170 242
31 }
32 11 return bless { %answer, _raw => $body }, $class;
33 }
34  
35 78 ▶sub has {
Subroutine has: called CC=3 SCAR=11.0
Pod documented
36 78 my ($self, $field) = @_;
37 78 ▶ Carp::croak("InternetData::AsnResult::has: unknown field '$field'") unless $KNOWN{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless $KNOWN{$field} 1 77 78
38 77 ▶ return exists $self->{$field} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$field} ? : 38 39 77
39 }
40  
41 1 ▶sub fields {
Subroutine fields: called CC=1 SCAR=0.0
Pod documented
42 1 my ($self) = @_;
43 1 return grep { exists $self->{$_} } @MEMBERS, @MARKERS;
44 }
45  
46 0 ▶sub raw {
Subroutine raw: not called CC=1 SCAR=6.9
Pod documented
47 0 return $_[0]->{_raw};
48 }
49  
50 8 for my $field ('asn', @MEMBERS, @MARKERS) {
51 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 118 ▶ *{__PACKAGE__ . "::$field"} = sub { $_[0]->{$field} };
Subroutine __ANON__: called CC=1 SCAR=0.0
53 }
54  
55 8 1;
56  
57 __END__
« InternetData/DomainResult.pm ↑ Summary InternetData/Result.pm »