DNS/RR/APL.pm

filter: Statementstmt 100% 99 / 99 Branchbran 100% 26 / 26 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 17 / 17 Podpod 100% 1 / 1 totaltotal 100% 161 / 161 CC 24 SCAR 16.4
CC
24
Cov
100%
aplist
12.0
_decode_rdata
3.0
_encode_rdata
3.0
CRAP 5.2
« DNS/RR/OPT.pm ↑ Summary DNS/Domain.pm »
1 package Net::DNS::RR::APL;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = (qw$Id: APL.pm 2003 2025-01-21 12:06:06Z willem $)[2];
6  
7 2 ▶use base qw(Net::DNS::RR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 =head1 NAME
11  
12 Net::DNS::RR::APL - DNS APL resource record
13  
14 =cut
15  
16 2 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 5 ▶sub _decode_rdata { ## decode rdata from wire-format octet string
Subroutine _decode_rdata: called CC=3 SCAR=11.0
22 5 my ( $self, $data, $offset ) = @_;
23  
24 5 my $limit = $offset + $self->{rdlength};
25  
26 5 my $aplist = $self->{aplist} = [];
27 5 ▶ while ( $offset < $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $limit) 25 5 30
28 25 my $xlen = unpack "\@$offset x3 C", $$data;
29 25 my $size = ( $xlen & 0x7F );
30 25 my $item = bless {}, 'Net::DNS::RR::APL::Item';
31 25 $item->{negate} = $xlen - $size;
32 25 @{$item}{qw(family prefix address)} = unpack "\@$offset n C x a$size", $$data;
33 25 $offset += $size + 4;
34 25 push @$aplist, $item;
35 }
36 5 ▶ croak('corrupt APL data') unless $offset == $limit; # more or less FUBAR
Branch: 1 branch
BranchTrueFalseTotal
unless $offset == $limit 1 4 5
37 4 return;
38 }
39  
40  
41 7 ▶sub _encode_rdata { ## encode rdata as wire-format octet string
Subroutine _encode_rdata: called CC=3 SCAR=11.0
42 7 my $self = shift;
43  
44 7 my @rdata;
45 7 my $aplist = $self->{aplist};
46 7 foreach (@$aplist) {
47 27 my $address = $_->{address};
48 27 $address =~ s/[\000]+$//; # strip trailing null octets
49 27 ▶ my $xlength = ( $_->{negate} ? 0x80 : 0 ) | length($address);
Branch: 1 branch
BranchTrueFalseTotal
$_->{'negate'} ? : 5 22 27
50 27 push @rdata, pack 'n C2 a*', @{$_}{qw(family prefix)}, $xlength, $address;
51 }
52 7 return join '', @rdata;
53 }
54  
55  
56 2 ▶sub _format_rdata { ## format rdata portion of RR string.
Subroutine _format_rdata: called CC=1 SCAR=0.0
57 2 my $self = shift;
58  
59 2 my $aplist = $self->{aplist};
60 2 my @rdata = map { $_->string } @$aplist;
61 2 return @rdata;
62 }
63  
64  
65 4 ▶sub _parse_rdata { ## populate RR from rdata in argument list
Subroutine _parse_rdata: called CC=1 SCAR=0.0
66 4 my ( $self, @argument ) = @_;
67  
68 4 $self->aplist(@argument);
69 3 return;
70 }
71  
72  
73 20 ▶sub aplist {
Subroutine aplist: called CC=12 SCAR=24.8
Pod documented
74 20 my ( $self, @argument ) = @_;
75  
76 20 ▶ while ( scalar @argument ) { # parse apitem strings
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @argument) 26 6 32
77 26 ▶ last unless $argument[0] =~ m#[!:./]#;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument[0] =~ m[[!:./]] 13 13 26
78 13 local $_ = shift @argument;
79 13 m#^(!?)(\d+):(.+)/(\d+)$#;
80 13 ▶ my $n = $1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 2 11 13
81 13 ▶ my $f = $2 || 0;
Condition100%2/2
$2 || 0
l!l
121
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
82 13 my $a = $3;
83 13 ▶ my $p = $4 || 0;
Condition100%2/2
$4 || 0
l!l
85
MC/DC100%1/1
$4 || 0
$4
Truth table100%2/2
A
A= $4
Aresult
11
00
84 13 $self->aplist( negate => $n, family => $f, address => $a, prefix => $p );
85 }
86  
87 19 ▶ my $aplist = $self->{aplist} ||= [];
Condition100%2/2
$self->{"aplist"} ||= []
l!l
145
MC/DC100%1/1
$self->{"aplist"} ||= []
$self->{"aplist"}
Truth table100%2/2
A
A= $self->{"aplist"}
Aresult
11
00
88 19 ▶ if ( my %argval = @argument ) { # parse attribute=value list
Branch: 1 branch
BranchTrueFalseTotal
if (my(%argval) = @argument) 13 6 19
89 13 my $item = bless {}, 'Net::DNS::RR::APL::Item';
90 13 ▶ while ( my ( $attribute, $value ) = each %argval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %argval) 52 13 65
91 52 ▶ $item->$attribute($value) unless $attribute eq 'address';
Branch: 1 branch
BranchTrueFalseTotal
unless $attribute eq "address" 39 13 52
92 }
93 13 $item->address( $argval{address} ); # address must be last
94 12 push @$aplist, $item;
95 }
96  
97 18 my @ap = @$aplist;
98 18 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 16 2 18
99 2 ▶ return wantarray ? @ap : join ' ', map { $_->string } @ap;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
100 }
101  
102  
103 ########################################
104  
105  
106 package Net::DNS::RR::APL::Item; ## no critic ProhibitMultiplePackages
107  
108 2 ▶use Net::DNS::RR::A;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 2 ▶use Net::DNS::RR::AAAA;
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 2 my %family = qw(1 Net::DNS::RR::A 2 Net::DNS::RR::AAAA);
112  
113  
114 18 ▶sub negate {
Subroutine negate: called CC=2 SCAR=6.9
115 18 my ( $self, @value ) = @_;
116 18 for (@value) { return $self->{negate} = $_ }
117 5 return $self->{negate};
118 }
119  
120  
121 52 ▶sub family {
Subroutine family: called CC=3 SCAR=11.0
122 52 my ( $self, @value ) = @_;
123 52 for (@value) { $self->{family} = 0 + $_ }
124 52 ▶ return $self->{family} || 0;
Condition100%2/2
$self->{'family'} || 0
l!l
502
MC/DC100%1/1
$self->{'family'} || 0
$self->{'family'}
Truth table100%2/2
A
A= $self->{'family'}
Aresult
11
00
125 }
126  
127  
128 33 ▶sub prefix {
Subroutine prefix: called CC=3 SCAR=11.0
129 33 my ( $self, @value ) = @_;
130 33 for (@value) { $self->{prefix} = 0 + $_ }
131 33 ▶ return $self->{prefix} || 0;
Condition100%2/2
$self->{'prefix'} || 0
l!l
2211
MC/DC100%1/1
$self->{'prefix'} || 0
$self->{'prefix'}
Truth table100%2/2
A
A= $self->{'prefix'}
Aresult
11
00
132 }
133  
134  
135 26 ▶sub address {
Subroutine address: called CC=3 SCAR=11.0
136 26 my ( $self, @value ) = @_;
137  
138 26 ▶ my $family = $family{$self->family} || die 'unknown address family';
Condition100%2/2
$family{$self->family} || die('unknown address family')
l!l
251
MC/DC100%1/1
$family{$self->family} || die('unknown address family')
$family{$self->family}
Truth table100%2/2
A
A= $family{$self->family}
Aresult
11
00
139 25 ▶ return bless( {%$self}, $family )->address unless scalar @value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @value 13 12 25
140  
141 12 my $bitmask = $self->prefix;
142 12 my $address = bless( {}, $family )->address( shift @value );
143 12 return $self->{address} = pack "B$bitmask", unpack 'B*', $address;
144 }
145  
146  
147 8 ▶sub string {
Subroutine string: called CC=2 SCAR=6.9
148 8 my $self = shift;
149  
150 8 ▶ my $not = $self->{negate} ? '!' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'negate'} ? : 1 7 8
151 8 my ( $family, $address, $prefix ) = ( $self->family, $self->address, $self->prefix );
152 8 return "$not$family:$address/$prefix";
153 }
154  
155  
156 2 1;
157 __END__
« DNS/RR/OPT.pm ↑ Summary DNS/Domain.pm »