DNS/RR/DELEG.pm

filter: Statementstmt 100% 202 / 202 Branchbran 100% 80 / 80 Conditioncond 90.9% 10 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 29 / 29 Podpod 83.3% 5 / 6 totaltotal 98.8% 330 / 334 CC 49 SCAR 15.1
CC
49
Cov
100%
_post_parse
11.0
_parameter
6.0
mandatory
5.0
CRAP 4.5
« DNS/RR/SVCB.pm ↑ Summary DNS/Resolver/android.pm »
1 package Net::DNS::RR::DELEG;
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 1 our $VERSION = (qw$Id: DELEG.pm 2053 2026-07-07 10:18:23Z willem $)[2];
6  
7 1 ▶use base qw(Net::DNS::RR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 =head1 NAME
11  
12 Net::DNS::RR::DELEG - DNS DELEG resource record
13  
14 =cut
15  
16 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Net::DNS::RR::A;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Net::DNS::RR::AAAA;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Net::DNS::DomainName;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Net::DNS::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 my %keybycode = (
24 0 => 'mandatory',
25 1 => 'server-ipv4',
26 2 => 'server-ipv6',
27 3 => 'server-name',
28 4 => 'include-delegparam',
29 );
30 1 my %keybyname = reverse %keybycode;
31  
32  
33 2 ▶sub _decode_rdata { ## decode rdata from wire-format octet string
Subroutine _decode_rdata: called CC=4 SCAR=13.9
34 2 my ( $self, $data, $offset ) = @_;
35  
36 2 my $limit = $self->{rdlength};
37 2 my $rdata = $self->{rdata} = substr $$data, $offset, $limit;
38 2 my $index = 0;
39  
40 2 my $params = $self->{parameters} = [];
41 2 ▶ while ( ( my $start = $index + 4 ) <= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $start = $index + 4) <= $limit) 7 1 8
42 7 my ( $key, $size ) = unpack( "\@$index n2", $rdata );
43 7 ▶ last if ( $index = $start + $size ) > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if ($index = $start + $size) > $limit 1 6 7
44 6 push @$params, ( $key, substr $rdata, $start, $size );
45 }
46 2 ▶ die $self->type . ': corrupt RDATA' unless $index == $limit;
Branch: 1 branch
BranchTrueFalseTotal
unless $index == $limit 1 1 2
47 1 return;
48 }
49  
50  
51 4 ▶sub _encode_rdata { ## encode rdata as wire-format octet string
Subroutine _encode_rdata: called CC=2 SCAR=6.9
52 4 my $self = shift;
53  
54 4 my @packed;
55 4 my ($paramref) = grep {defined} $self->{parameters}, [];
56 4 my @parameters = @$paramref;
57 4 ▶ while (@parameters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parameters) 16 4 20
58 16 my $key = shift @parameters;
59 16 my $val = shift @parameters;
60 16 push @packed, pack( 'n2a*', $key, length($val), $val );
61 }
62 4 return join '', @packed;
63 }
64  
65  
66 2 ▶sub _format_rdata { ## format rdata portion of RR string.
Subroutine _format_rdata: called CC=4 SCAR=13.9
67 2 my $self = shift;
68  
69 2 my @rdata;
70 2 my ($paramref) = grep {defined} $self->{parameters}, [];
71 2 my @parameters = @$paramref;
72 2 ▶ while (@parameters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parameters) 6 2 8
73 6 my $key = shift @parameters;
74 6 my $val = shift @parameters;
75 6 ▶ if ( my $name = $keybycode{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $keybycode{$key}) { } 5 1 6
76 5 my @val = grep {length} $self->$name;
77 5 s/,/\\044/g foreach @val; # escape embedded commas
78 5 my @rhs = grep {length} join ',', @val;
79 5 push @rdata, join '=', $name, @rhs;
80 } else {
81 1 my $txt = Net::DNS::Text->decode( \$val, 0, length $val );
82 1 push @rdata, join '=', "key$key", $txt->string;
83 }
84 }
85  
86 2 return @rdata;
87 }
88  
89  
90 13 ▶sub _parse_rdata { ## populate RR from rdata in argument list
Subroutine _parse_rdata: called CC=5 SCAR=16.1
91 13 my ( $self, @argument ) = @_;
92  
93 13 ▶ while ( local $_ = shift @argument ) {
Branch: 1 branch
BranchTrueFalseTotal
if (local $_ = shift @argument) 16 10 26
94 16 m/^([^=]+)(=?)(.*)$/;
95 16 my $key = $1;
96 16 ▶ my $val = length($3) ? $3 : $2 ? shift @argument : '';
Branch: 2 branches
BranchTrueFalseTotal
length $3 ? : 14 2 16
$2 ? : 1 1 2
97 16 ▶ if (/^key\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^key\d+/) { } 1 15 16
98 1 $self->$key($val);
99 } else {
100 15 local $_ = $val;
101 15 s/^"([^"]*)"$/$1/s; # strip enclosing quotes
102 15 s/\\,/\\044/g; # disguise escaped comma
103 15 $self->$key( split /,/ );
104 }
105 }
106 10 return;
107 }
108  
109  
110 11 ▶sub _post_parse { ## parser post processing
Subroutine _post_parse: called CC=11 SCAR=24.0
111 11 my $self = shift;
112  
113 11 my ($paramref) = grep {defined} $self->{parameters}, [];
114 11 my %parameter = @$paramref;
115  
116 11 ▶ if ( defined $parameter{0} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameter{0}) 3 8 11
117 3 my %unique;
118 3 foreach ( grep { !$unique{$_}++ } unpack 'n*', $parameter{0} ) {
119 4 ▶ die( $self->type . qq[: unexpected "key0" in mandatory list] ) if $unique{0};
Branch: 1 branch
BranchTrueFalseTotal
if $unique{0} 1 3 4
120 3 ▶ die( $self->type . qq[: duplicate "key$_" in mandatory list] ) if --$unique{$_};
Branch: 1 branch
BranchTrueFalseTotal
if --$unique{$_} 1 2 3
121 2 ▶ die( $self->type . qq[: mandatory "key$_" not present] ) unless defined $parameter{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parameter{$_} 1 1 2
122 }
123 }
124  
125 8 foreach ( 3, 4 ) {
126 15 ▶ next unless defined $parameter{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parameter{$_} 9 6 15
127 6 ▶ next if length( $parameter{$_} ) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $parameter{$_} > 1 4 2 6
128 2 die( $self->type . qq[: invalid $keybycode{$_}] );
129 }
130  
131 6 ▶ if ( defined $parameter{4} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parameter{4}) 2 4 6
132 2 ▶ die( $self->type . qq[: parameter conflicts with $keybycode{4}] )
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %parameter > 1 1 1 2
133 if scalar( keys %parameter ) > 1;
134 }
135 5 return;
136 }
137  
138  
139 7 ▶sub mandatory { ## mandatory=key1,server-name,...
Subroutine mandatory: called CC=5 SCAR=16.1
Pod undocumented
140 7 my ( $self, @value ) = @_; # uncoverable pod
141 7 ▶ my @list = map { $keybyname{lc $_} || $_ } @value;
Condition66%2/3
$keybyname{lc $_} || $_
l!l&&r!l&&!r
190
MC/DC0%0/2
$keybyname{lc $_} || $_
$keybyname{lc $_} $_
Truth table66%2/3
A || B
A= $keybyname{lc $_}B= $_
ABresult
1X1
011
000
142 7 ▶ my @keys = map { /(\d+)$/ ? $1 : die( $self->type . qq[: unexpected "$_"] ) } @list;
Branch: 1 branch
BranchTrueFalseTotal
/(\d+)$/ ? : 9 1 10
143 6 ▶ return $self->_parameter( 0, _integer16( sort { $a <=> $b } @keys ) ) if @keys;
Branch: 1 branch
BranchTrueFalseTotal
if @keys 4 2 6
144 2 my $packed = $self->_parameter(0);
145 2 ▶ return _list( defined($packed) ? map {"key$_"} unpack 'n*', $packed : return );
Branch: 1 branch
BranchTrueFalseTotal
defined $packed ? : 1 1 2
146 }
147  
148 5 ▶sub server_ipv4 { ## server-ipv4=192.0.2.53
Subroutine server_ipv4: called CC=3 SCAR=11.0
Pod documented
149 5 my ( $self, @value ) = @_;
150 5 ▶ return $self->_parameter( 1, _address4(@value) ) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 2 3 5
151 3 ▶ my $packed = $self->_parameter(1) || return;
Condition100%2/2
$self->_parameter(1) || (return)
l!l
21
MC/DC100%1/1
$self->_parameter(1) || (return)
$self->_parameter(1)
Truth table100%2/2
A
A= $self->_parameter(1)
Aresult
11
00
152 2 my @iplist = unpack 'a4' x ( length($packed) / 4 ), $packed;
153 2 return _list( map { Net::DNS::RR::A::address( {address => $_} ) } @iplist );
154 }
155  
156 5 ▶sub server_ipv6 { ## server-ipv6=2001:DB8::53
Subroutine server_ipv6: called CC=3 SCAR=11.0
Pod documented
157 5 my ( $self, @value ) = @_;
158 5 ▶ return $self->_parameter( 2, _address6(@value) ) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 2 3 5
159 3 ▶ my $packed = $self->_parameter(2) || return;
Condition100%2/2
$self->_parameter(2) || (return)
l!l
21
MC/DC100%1/1
$self->_parameter(2) || (return)
$self->_parameter(2)
Truth table100%2/2
A
A= $self->_parameter(2)
Aresult
11
00
160 2 my @iplist = unpack 'a16' x ( length($packed) / 16 ), $packed;
161 2 return _list( map { Net::DNS::RR::AAAA::address_short( {address => $_} ) } @iplist );
162 }
163  
164 9 ▶sub server_name { ## server-name=nameserver.example
Subroutine server_name: called CC=4 SCAR=13.9
Pod documented
165 9 my ( $self, @value ) = @_;
166 9 ▶ return $self->_parameter( 3, _domain(@value) ) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 6 3 9
167 3 ▶ my $packed = $self->_parameter(3) || return;
Condition100%2/2
$self->_parameter(3) || (return)
l!l
21
MC/DC100%1/1
$self->_parameter(3) || (return)
$self->_parameter(3)
Truth table100%2/2
A
A= $self->_parameter(3)
Aresult
11
00
168 2 my $index = 0;
169 2 ▶ ( $value[++$#value], $index ) = Net::DNS::DomainName->decode( \$packed, $index ) while $index < length $packed;
Branch: 1 branch
BranchTrueFalseTotal
$index < length $packed and do { ($value[++$#value], $index) = "Net::DNS::DomainName"->decode(\$packed, $index) } 2 2 4
170 2 return _list( map { $_->fqdn } @value );
171 }
172  
173 7 ▶sub include_delegparam { ## include-delegparam=provider.example
Subroutine include_delegparam: called CC=4 SCAR=13.9
Pod documented
174 7 my ( $self, @value ) = @_;
175 7 ▶ return $self->_parameter( 4, _domain(@value) ) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 4 3 7
176 3 ▶ my $packed = $self->_parameter(4) || return;
Condition100%2/2
$self->_parameter(4) || (return)
l!l
21
MC/DC100%1/1
$self->_parameter(4) || (return)
$self->_parameter(4)
Truth table100%2/2
A
A= $self->_parameter(4)
Aresult
11
00
177 2 my $index = 0;
178 2 ▶ ( $value[++$#value], $index ) = Net::DNS::DomainName->decode( \$packed, $index ) while $index < length $packed;
Branch: 1 branch
BranchTrueFalseTotal
$index < length $packed and do { ($value[++$#value], $index) = "Net::DNS::DomainName"->decode(\$packed, $index) } 2 2 4
179 2 return _list( map { $_->fqdn } @value );
180 }
181  
182  
183 ########################################
184  
185 12 ▶sub AUTOLOAD { ## Dynamic constructor/accessor methods
Subroutine AUTOLOAD: called CC=5 SCAR=16.1
186 12 my ( $self, @argument ) = @_;
187  
188 12 our $AUTOLOAD;
189 12 my ($method) = reverse split /::/, $AUTOLOAD;
190 12 my $canonical = lc($method);
191 12 $canonical =~ s/-/_/g;
192 12 ▶ if ( $self->can($canonical) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($canonical)) 4 8 12
193 1 ▶ no strict 'refs'; ## no critic ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
194 4 ▶ *{$AUTOLOAD} = sub { shift->$canonical(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
195 4 return $self->$canonical(@argument);
196 }
197  
198 8 my $super = "SUPER::$method";
199 8 ▶ return $self->$super(@argument) unless $method =~ /^key[0]*(\d+)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /^key[0]*(\d+)$/i 1 7 8
200 7 my $key = $1;
201 7 ▶ return $self->_parameter($key) unless @argument;
Branch: 1 branch
BranchTrueFalseTotal
unless @argument 4 3 7
202 3 my $first = shift @argument;
203 3 ▶ my $value = defined $first ? Net::DNS::Text->new($first)->raw : $first;
Branch: 1 branch
BranchTrueFalseTotal
defined $first ? : 2 1 3
204 3 return $self->_parameter( $key, $value, @argument );
205 }
206  
207  
208 40 ▶sub _parameter {
Subroutine _parameter: called CC=6 SCAR=17.9
209 40 my ( $self, $key, @argument ) = @_;
210  
211 40 my ($paramref) = grep {defined} $self->{parameters}, [];
212 40 my %parameter = @$paramref;
213  
214 40 ▶ if ( scalar @argument ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @argument) 22 18 40
215 22 my $arg = shift @argument; # key($value);
216 22 ▶ delete $parameter{$key} unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 21 22
217 22 ▶ die( $self->type . qq[: duplicate parameter key$key] ) if defined $parameter{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $parameter{$key} 1 21 22
218 21 ▶ die( $self->type . qq[: unexpected key$key value] ) if scalar @argument;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @argument 1 20 21
219 20 delete $self->{rdata};
220 20 ▶ $parameter{$key} = $arg if defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 19 1 20
221 20 $self->{parameters} = [map { ( $_, $parameter{$_} ) } sort { $a <=> $b } keys %parameter];
222 }
223  
224 38 return $parameter{$key};
225 }
226  
227  
228 18 ▶sub _concatenate { ## concatenate octet string(s)
Subroutine _concatenate: called CC=2 SCAR=6.9
229 18 my @arg = @_;
230 18 ▶ return scalar(@arg) > 1 ? join( '', @arg ) : @arg;
Branch: 1 branch
BranchTrueFalseTotal
scalar @arg > 1 ? : 6 12 18
231 }
232  
233 9 ▶sub _list { ## context-dependent list or single value
Subroutine _list: called CC=2 SCAR=6.9
234 9 my @arg = @_;
235 9 ▶ return wantarray ? @arg : shift @arg;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 2 9
236 }
237  
238 2 ▶sub _address4 {
Subroutine _address4: called CC=1 SCAR=0.0
239 2 my @arg = @_;
240 2 return _concatenate( map { Net::DNS::RR::A::address( {}, $_ ) } @arg );
241 }
242  
243 2 ▶sub _address6 {
Subroutine _address6: called CC=1 SCAR=0.0
244 2 my @arg = @_;
245 2 return _concatenate( map { Net::DNS::RR::AAAA::address( {}, $_ ) } @arg );
246 }
247  
248 10 ▶sub _domain {
Subroutine _domain: called CC=1 SCAR=0.0
249 10 my @arg = @_;
250 10 return _concatenate( map { Net::DNS::DomainName->new($_)->encode() } @arg );
251 }
252  
253 4 ▶sub _integer16 {
Subroutine _integer16: called CC=1 SCAR=0.0
254 4 my @arg = @_;
255 4 return _concatenate( map { pack( 'n', $_ ) } @arg );
256 }
257  
258  
259 4 ▶sub generic {
Subroutine generic: called CC=3 SCAR=11.0
Pod documented
260 4 my $self = shift;
261 4 my $size = 0;
262 4 my @rdata;
263 4 my ($paramref) = grep {defined} $self->{parameters}, [];
264 4 my @parameters = @$paramref;
265 4 ▶ while (@parameters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parameters) 18 4 22
266 18 my $key = shift @parameters;
267 18 my $val = shift @parameters;
268 18 push @rdata, "\n", unpack 'H4H4', pack( 'n2', $key, length $val );
269 18 $size += 4 + length $val;
270 18 push @rdata, split /(\S{32})/, unpack 'H*', $val;
271 }
272  
273 4 my @ttl = grep {defined} $self->{ttl};
274 4 ▶ my @class = map { $_ ? "CLASS$_" : () } $self->{class};
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 3 1 4
275 4 my @core = ( $self->{owner}->string, @ttl, @class, "TYPE$self->{type}" );
276 4 return join "\n\t", Net::DNS::RR::_wrap( "@core ( \\# $size", @rdata, ')' );
277 }
278  
279 ########################################
280  
281  
282 1 1;
283 __END__
« DNS/RR/SVCB.pm ↑ Summary DNS/Resolver/android.pm »