| 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.15.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); | |||||||||||||
| 18 | |||||||||||||||
| 19 | 8 | my %KNOWN = map { $_ => 1 } 'asn', @MEMBERS, @MARKERS; | |||||||||||||
| 20 | |||||||||||||||
| 21 | # Copied on key PRESENCE, never on truthiness, as InternetData::Result is. | ||||||||||||||
| 22 | 10 | ▶ | sub from_wire { | ||||||||||||
|
Subroutine
from_wire: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||
| 23 | 10 | my ($class, $body) = @_; | |||||||||||||
| 24 | 10 | my %answer = (asn => $body->{asn}); | |||||||||||||
| 25 | 10 | for my $marker (@MARKERS) { | |||||||||||||
| 26 | 20 | ▶ | next unless exists $body->{$marker}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 2 | ▶ | $answer{$marker} = defined $body->{$marker} ? ($body->{$marker} ? 1 : 0) : undef; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 28 | } | ||||||||||||||
| 29 | 10 | for my $member (@MEMBERS) { | |||||||||||||
| 30 | 220 | ▶ | $answer{$member} = $body->{$member} if exists $body->{$member}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | } | ||||||||||||||
| 32 | 10 | return bless { %answer, _raw => $body }, $class; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 50 | ▶ | sub has { | ||||||||||||
|
Subroutine
has: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 36 | 50 | my ($self, $field) = @_; | |||||||||||||
| 37 | 50 | ▶ | Carp::croak("InternetData::AsnResult::has: unknown field '$field'") unless $KNOWN{$field}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 49 | ▶ | return exists $self->{$field} ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 82 | ▶ | *{__PACKAGE__ . "::$field"} = sub { $_[0]->{$field} }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 8 | 1; | |||||||||||||
| 56 | |||||||||||||||
| 57 | __END__ | ||||||||||||||