DNS/RR/OPT.pm

filter: Statementstmt 100% 318 / 318 Branchbran 100% 116 / 116 Conditioncond 100% 32 / 32 MC/DCmcdc 100% 17 / 17 Subroutinesub 100% 56 / 56 Podpod 100% 11 / 14 totaltotal 100% 550 / 553 CC 88 SCAR 16.5
CC
88
Cov
100%
_set_option
13.0
_JSONify
12.0
_get_option
10.0
CRAP 5.2
« DNS/Resolver/Recurse.pm ↑ Summary DNS/RR/APL.pm »
1 package Net::DNS::RR::OPT;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 our $VERSION = (qw$Id: OPT.pm 2054 2026-07-10 09:37:11Z willem $)[2];
6  
7 12 ▶use base qw(Net::DNS::RR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 =head1 NAME
11  
12 Net::DNS::RR::OPT - DNS OPT resource record
13  
14 =cut
15  
16 12 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶use Net::DNS::Parameters qw(:rcode :ednsoption);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 12 ▶use constant UTIL => scalar eval { require Scalar::Util; Scalar::Util->can('isdual') };
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 12 ▶use constant OPT => Net::DNS::Parameters::typebyname qw(OPT);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 12 require Net::DNS::DomainName;
26 12 require Net::DNS::RR::A;
27 12 require Net::DNS::RR::AAAA;
28 12 require Net::DNS::Text;
29  
30  
31 sub _decode_rdata { ## decode rdata from wire-format octet string
32 57 ▶ my ( $self, $data, $offset ) = @_;
Subroutine _decode_rdata: called CC=7 SCAR=19.5
33  
34 57 my $class = delete $self->{class}; # OPT redefines CLASS and TTL fields
35 57 ▶ $self->udpsize($class) if defined $class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class 56 1 57
36  
37 57 my $ttl = delete $self->{ttl};
38 57 ▶ $self->_ttl($ttl) if defined $ttl;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ttl 56 1 57
39  
40 57 my $limit = $offset + $self->{rdlength} - 4;
41 57 ▶ while ( $offset <= $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset <= $limit) 35 57 92
42 35 my ( $code, $length ) = unpack "\@$offset nn", $$data;
43 35 my $value = unpack "\@$offset x4 a$length", $$data;
44 35 ▶ my @value = map { ref($_) ? @$_ : defined($_) ? $_ : () } $self->{option}{$code}, $value;
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 2 68 70
defined $_ ? : 37 31 68
45 35 ▶ $self->{option}{$code} = ( scalar(@value) == 1 ) ? $value : \@value;
Branch: 1 branch
BranchTrueFalseTotal
scalar @value == 1 ? : 31 4 35
46 35 $offset += $length + 4;
47 }
48 57 return;
49 }
50  
51  
52 sub _encode_rdata { ## encode rdata as wire-format octet string
53 64 ▶ my $self = shift;
Subroutine _encode_rdata: called CC=4 SCAR=13.9
54  
55 64 ▶ my $option = $self->{option} || {};
Condition100%2/2
$self->{'option'} || {}
l!l
658
MC/DC100%1/1
$self->{'option'} || {}
$self->{'option'}
Truth table100%2/2
A
A= $self->{'option'}
Aresult
11
00
56 64 my @option = $self->options;
57 64 foreach my $item (@option) {
58 30 ▶ my @value = map { ref($_) ? @$_ : $_ } $option->{$item};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 29 30
59 30 $item = join '', map { pack( 'nna*', $item, length($_), $_ ) } @value;
60 }
61 64 return join '', @option;
62 }
63  
64  
65 sub encode { ## override RR method
66 63 ▶ my $self = shift;
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
67 63 my $data = $self->_encode_rdata;
68 63 return pack 'C n n N na*', 0, OPT, $self->udpsize, $self->_ttl, length($data), $data;
69 }
70  
71  
72 sub string { ## override RR method
73 6 ▶ my @line = split /[\r\n]+/, shift->json;
Subroutine string: called CC=1 SCAR=0.0
Pod documented
74 6 return join '', map {";;$_\n"} @line;
75 }
76  
77 sub class { ## override RR method
78 2 ▶ my ( $self, @value ) = @_;
Subroutine class: called CC=1 SCAR=0.0
Pod documented
79 2 $self->_deprecate(qq[please use "UDPsize()"]);
80 2 return $self->udpsize(@value);
81 }
82  
83 sub ttl { ## override RR method
84 2 ▶ my ( $self, @value ) = @_;
Subroutine ttl: called CC=1 SCAR=0.0
Pod documented
85 2 $self->_deprecate(qq[please use "flags()", "rcode()" or "version()"]);
86 2 return $self->_ttl(@value);
87 }
88  
89 sub _ttl {
90 122 ▶ my ( $self, @value ) = @_;
Subroutine _ttl: called CC=2 SCAR=6.9
91 122 for (@value) {
92 58 @{$self}{qw(rcode version flags)} = unpack 'C2n', pack( 'N', $_ );
93 58 $self->{rcode} = $self->{rcode} << 4;
94 58 return;
95 }
96 64 return unpack 'N', pack( 'C2n', $self->rcode >> 4, $self->version, $self->flags );
97 }
98  
99 sub generic { ## override RR method
100 1 ▶ my $self = shift;
Subroutine generic: called CC=1 SCAR=0.0
Pod documented
101 1 local $self->{class} = $self->udpsize;
102 1 local $self->{ttl} = $self->_ttl;
103 1 return $self->SUPER::generic;
104 }
105  
106 sub token { ## override RR method
107 1 ▶ return grep { !m/^[()]$/ } split /\s+/, &generic;
Subroutine token: called CC=1 SCAR=0.0
Pod documented
108 }
109  
110 sub json {
111 6 ▶ my $self = shift; # uncoverable pod
Subroutine json: called CC=3 SCAR=11.0
Pod undocumented
112  
113 6 my $version = $self->version;
114 6 ▶ unless ( $version == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version == 0) 1 5 6
115 1 my $content = unpack 'H*', $self->encode;
116 1 return <<"QQ";
117 { "EDNS-VERSION": $version,
118 "BASE16": "$content"
119 }
120 QQ
121 }
122  
123 5 my $flags = $self->flags;
124 5 my $rcode = $self->rcode;
125 5 my $size = $self->udpsize;
126 5 my @format = map { join( "\n\t\t\t", $self->_format_option($_) ) } $self->options;
127 5 ▶ my @indent = scalar(@format) ? "\n\t\t" : ();
Branch: 1 branch
BranchTrueFalseTotal
scalar @format ? : 2 3 5
128 5 my @option = join ",\n\t\t", @format;
129  
130 5 return <<"QQ";
131 { "EDNS-VERSION": $version,
132 "FLAGS": $flags,
133 "RCODE": $rcode,
134 "UDPSIZE": $size,
135 "OPTIONS": [@indent@option ]
136 }
137 QQ
138 }
139  
140  
141 sub version {
142 90 ▶ my ( $self, @value ) = @_;
Subroutine version: called CC=3 SCAR=11.0
Pod documented
143 90 for (@value) { $self->{version} = 0 + $_ }
144 90 ▶ return $self->{version} || 0;
Condition100%2/2
$self->{'version'} || 0
l!l
585
MC/DC100%1/1
$self->{'version'} || 0
$self->{'version'}
Truth table100%2/2
A
A= $self->{'version'}
Aresult
11
00
145 }
146  
147  
148 sub udpsize {
149 224 ▶ my ( $self, @value ) = @_; # uncoverable pod
Subroutine udpsize: called CC=4 SCAR=13.9
Pod undocumented
150 224 ▶ for (@value) { $self->{udpsize} = ( $_ > 512 ) ? $_ : 0 }
Branch: 1 branch
BranchTrueFalseTotal
$_ > 512 ? : 81 70 151
151 224 ▶ return $self->{udpsize} || 0;
Condition100%2/2
$self->{'udpsize'} || 0
l!l
13787
MC/DC100%1/1
$self->{'udpsize'} || 0
$self->{'udpsize'}
Truth table100%2/2
A
A= $self->{'udpsize'}
Aresult
11
00
152 }
153  
154 sub size {
155 2 ▶ my ( $self, @value ) = @_; # uncoverable pod
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
156 2 $self->_deprecate(qq[size() is an alias of "UDPsize()"]);
157 2 return $self->udpsize(@value);
158 }
159  
160  
161 sub rcode {
162 506 ▶ my ( $self, @value ) = @_;
Subroutine rcode: called CC=4 SCAR=13.9
Pod documented
163 506 ▶ for (@value) { $self->{rcode} = ( $_ < 16 ) ? 0 : $_ } # discard non-EDNS rcodes 1 .. 15
Branch: 1 branch
BranchTrueFalseTotal
$_ < 16 ? : 219 7 226
164 506 ▶ return $self->{rcode} || 0;
Condition100%2/2
$self->{'rcode'} || 0
l!l
11495
MC/DC100%1/1
$self->{'rcode'} || 0
$self->{'rcode'}
Truth table100%2/2
A
A= $self->{'rcode'}
Aresult
11
00
165 }
166  
167  
168 sub flags {
169 328 ▶ my ( $self, @value ) = @_;
Subroutine flags: called CC=3 SCAR=11.0
Pod documented
170 328 for (@value) { $self->{flags} = 0 + $_ }
171 328 ▶ return $self->{flags} || 0;
Condition100%2/2
$self->{'flags'} || 0
l!l
26302
MC/DC100%1/1
$self->{'flags'} || 0
$self->{'flags'}
Truth table100%2/2
A
A= $self->{'flags'}
Aresult
11
00
172 }
173  
174  
175 sub options {
176 74 ▶ my $self = shift;
Subroutine options: called CC=3 SCAR=11.0
Pod documented
177 74 ▶ my $option = $self->{option} || {};
Condition100%2/2
$self->{'option'} || {}
l!l
1163
MC/DC100%1/1
$self->{'option'} || {}
$self->{'option'}
Truth table100%2/2
A
A= $self->{'option'}
Aresult
11
00
178 74 ▶ @{$self->{index}} = sort { $a <=> $b } keys %$option unless defined $self->{index};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"index"} 39 35 74
179 74 return @{$self->{index}};
180 }
181  
182 sub option {
183 158 ▶ my ( $self, $name, @value ) = @_;
Subroutine option: called CC=3 SCAR=11.0
Pod documented
184 158 my $number = ednsoptionbyname($name);
185 158 ▶ return $self->_get_option($number) unless scalar @value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @value 75 83 158
186 83 my $value = $self->_set_option( $number, @value );
187 82 ▶ return $@ ? croak( ( split /\sat/i, $@ )[0] ) : $value;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 81 82
188 }
189  
190  
191 ########################################
192  
193 sub _get_option {
194 103 ▶ my ( $self, $number ) = @_;
Subroutine _get_option: called CC=10 SCAR=23.0
195  
196 103 ▶ my $options = $self->{option} || {};
Condition100%2/2
$self->{'option'} || {}
l!l
1021
MC/DC100%1/1
$self->{'option'} || {}
$self->{'option'}
Truth table100%2/2
A
A= $self->{'option'}
Aresult
11
00
197 103 ▶ my @payload = map { ref($_) ? @$_ : $_ } $options->{$number};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 101 103
198 103 ▶ return shift @payload unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 51 52 103
199 52 my $optname = ednsoptionbyval($number);
200 52 my $package = join '::', __PACKAGE__, $optname;
201 52 $package =~ s/-/_/g;
202 52 my $structured = $package->can('_decompose');
203 52 foreach my $value (@payload) {
204 56 my @value;
205 56 ▶ if ( length $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value) { } 52 4 56
206 52 ▶ @value = eval { $package->_decompose($value) } if $structured;
Branch: 1 branch
BranchTrueFalseTotal
if $structured 39 13 52
207 52 ▶ @value = {BASE16 => unpack 'H*', $value} unless scalar @value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @value 14 38 52
208 52 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 51 52
209 } else {
210 4 ▶ @value = $structured ? {'OPTION-LENGTH' => 0} : '';
Branch: 1 branch
BranchTrueFalseTotal
$structured ? : 2 2 4
211 }
212 56 $value = {$optname => @value};
213 }
214 52 return @payload;
215 }
216  
217  
218 sub _set_option {
219 83 ▶ my ( $self, $number, @value ) = @_;
Subroutine _set_option: called CC=13 SCAR=25.6
220 83 my ($arg) = @value;
221  
222 83 ▶ my $options = $self->{option} || {};
Condition100%2/2
$self->{'option'} || {}
l!l
785
MC/DC100%1/1
$self->{'option'} || {}
$self->{'option'}
Truth table100%2/2
A
A= $self->{'option'}
Aresult
11
00
223 83 delete $options->{$number};
224 83 delete $self->{index};
225 83 ▶ delete $self->{option} unless scalar( keys %$options );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$options 7 76 83
226  
227 83 ▶ return unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 1 82 83
228 82 $self->{option} = $options;
229  
230 82 ▶ if ( ref($arg) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq "HASH") 53 29 82
231 53 for ( keys %$arg ) { $$arg{uc $_} = $$arg{$_} } # tolerate mixed case
232 53 my $length = $$arg{'OPTION-LENGTH'};
233 53 my $octets = $$arg{'OPTION-DATA'};
234 53 ▶ $octets = pack 'H*', $$arg{'BASE16'} if defined $$arg{'BASE16'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg->{"BASE16"} 32 21 53
235 53 ▶ $octets = '' if defined($length) && $length == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and $length == 0 2 51 53
Condition100%3/3
defined $length and $length == 0
!ll&&!rl&&r
5012
MC/DC100%2/2
defined $length and $length == 0
defined $length $length == 0
Truth table100%3/3
A and B
A= defined $lengthB= $length == 0
ABresult
0X0
100
111
236 53 ▶ return $options->{$number} = $octets if defined $octets;
Branch: 1 branch
BranchTrueFalseTotal
if defined $octets 39 14 53
237 }
238  
239 43 my $option = ednsoptionbyval($number);
240 43 my $package = join '::', __PACKAGE__, $option;
241 43 $package =~ s/-/_/g;
242 43 ▶ return eval { $options->{$number} = $package->_compose(@value) } if length($arg) && $package->can('_compose');
Branch: 1 branch
BranchTrueFalseTotal
if length $arg and $package->can("_compose") 38 5 43
Condition100%3/3
length $arg and $package->can("_compose")
!ll&&!rl&&r
4138
MC/DC100%2/2
length $arg and $package->can("_compose")
length $arg $package->can("_compose")
Truth table100%3/3
A and B
A= length $argB= $package->can("_compose")
ABresult
0X0
100
111
243  
244 5 ▶ croak "unable to compose option $number" if ref($arg);
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg 1 4 5
245 4 return $options->{$number} = $arg;
246 }
247  
248  
249 sub _specified {
250 217 ▶ my $self = shift;
Subroutine _specified: called CC=1 SCAR=0.0
251 217 return scalar grep { $self->{$_} } qw(udpsize flags rcode option);
252 }
253  
254  
255 sub _format_option {
256 28 ▶ my ( $self, $number ) = @_;
Subroutine _format_option: called CC=1 SCAR=0.0
257 28 my @option = $self->_get_option($number);
258 28 return map { Net::DNS::RR::_wrap( _JSONify($_) ) } @option;
259 }
260  
261  
262 sub _JSONify {
263 127 ▶ my $value = shift;
Subroutine _JSONify: called CC=12 SCAR=24.8
264 127 ▶ return 'null' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 126 127
265  
266 126 ▶ if ( ref($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 56 70 126
267 56 my @tags = sort keys %$value;
268 56 my $tail = pop @tags;
269 56 ▶ for ( $$value{BASE16} ) { $_ = pack( 'U0a*', $_ ) if defined } # mark as UTF-8
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 13 43 56
270 56 my @body = map { my @x = ( qq("$_":), _JSONify( $$value{$_} ) ); $x[-1] .= ','; @x } @tags;
271 56 push @body, ( qq("$tail":), _JSONify( $$value{$tail} ) );
272 56 $body[0] = '{' . $body[0];
273 56 $body[-1] .= '}';
274 56 return @body;
275 }
276  
277 70 ▶ if ( ref($value) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 4 66 70
278 4 my @array = @$value;
279 4 my @tail = map { _JSONify($_) } grep {defined} pop @array;
280 4 my @body = map { my @x = _JSONify($_); $x[-1] .= ','; @x } @array;
281 4 return ( '[', @body, @tail, ']' );
282 }
283  
284 66 my $string = "$value"; ## stringify, then use isdual() as discriminant
285 66 ▶ return $string if UTIL && Scalar::Util::isdual($value); # native numeric representation
Branch: 1 branch
BranchTrueFalseTotal
if &Scalar::Util::isdual($value) 30 36 66
286 36 for ($string) {
287 36 ▶ unless ( utf8::is_utf8($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::is_utf8($value)) 16 20 36
288 16 ▶ return $_ if /^-?\d+$/; # integer (string representation)
Branch: 1 branch
BranchTrueFalseTotal
if /^-?\d+$/ 1 15 16
289 15 ▶ return $_ if /^-?\d+\.\d+$/; # non-integer
Branch: 1 branch
BranchTrueFalseTotal
if /^-?\d+\.\d+$/ 1 14 15
290 14 ▶ return $_ if /^-?\d+(\.\d+)?e[+-]\d\d?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /^-?\d+(\.\d+)?e[+-]\d\d?$/i 1 13 14
291 }
292 33 s/\\/\\\\/g; # escaped escape
293 33 s/^"(.*)"$/$1/; # strip enclosing quotes
294 33 s/"/\\"/g; # escape interior quotes
295 }
296 33 return qq("$string");
297 }
298  
299  
300 ## no critic ProhibitMultiplePackages
301 package Net::DNS::RR::OPT::NSID; # RFC5001
302  
303 sub _compose {
304 2 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 3 4
305 2 return pack 'H*', pop @argument;
306 }
307  
308 2 ▶sub _decompose { return pack 'U0a*', unpack 'H*', pop @_ } # mark as UTF-8
Subroutine _decompose: called CC=1 SCAR=0.0
309  
310  
311 package Net::DNS::RR::OPT::DAU; # RFC6975
312  
313 sub _compose {
314 6 ▶ my ( undef, @argument ) = map { ref($_) ? @$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 3 16 19
315 6 return pack 'C*', @argument;
316 }
317  
318 6 ▶sub _decompose { return [unpack 'C*', pop @_] }
Subroutine _decompose: called CC=1 SCAR=0.0
319  
320  
321 package Net::DNS::RR::OPT::DHU; # RFC6975
322 12 our @ISA = qw(Net::DNS::RR::OPT::DAU);
323  
324 package Net::DNS::RR::OPT::N3U; # RFC6975
325 12 our @ISA = qw(Net::DNS::RR::OPT::DAU);
326  
327  
328 package Net::DNS::RR::OPT::CLIENT_SUBNET; # RFC7871
329  
330 12 my %family = qw(1 Net::DNS::RR::A 2 Net::DNS::RR::AAAA);
331 12 my @field8 = qw(FAMILY SOURCE-PREFIX SCOPE-PREFIX ADDRESS);
332  
333 sub _compose {
334 4 ▶ shift @_;
Subroutine _compose: called CC=3 SCAR=11.0
335 4 ▶ my %argument = ( map( ( $_ => 0 ), @field8 ), map { ref($_) ? %$_ : $_ } @_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 3 6 9
336 4 ▶ my $family = $family{$argument{FAMILY}} || die 'unrecognised address family';
Condition100%2/2
$family{$argument{'FAMILY'}} || die('unrecognised address family')
l!l
31
MC/DC100%1/1
$family{$argument{'FAMILY'}} || die('unrecognised address family')
$family{$argument{'FAMILY'}}
Truth table100%2/2
A
A= $family{$argument{'FAMILY'}}
Aresult
11
00
337 3 my $bitmask = $argument{'SOURCE-PREFIX'};
338 3 my $address = bless( {}, $family )->address( $argument{ADDRESS} );
339 3 return pack 'a* B*', pack( 'nC2', @argument{@field8} ), unpack "B$bitmask", $address;
340 }
341  
342 sub _decompose {
343 4 ▶ my %object;
Subroutine _decompose: called CC=3 SCAR=11.0
344 4 @object{@field8} = unpack 'nC2a*', pop @_;
345 4 ▶ my $family = $family{$object{FAMILY}} || die 'unrecognised address family';
Condition100%2/2
$family{$object{'FAMILY'}} || die('unrecognised address family')
l!l
31
MC/DC100%1/1
$family{$object{'FAMILY'}} || die('unrecognised address family')
$family{$object{'FAMILY'}}
Truth table100%2/2
A
A= $family{$object{'FAMILY'}}
Aresult
11
00
346 3 for ( $object{ADDRESS} ) {
347 3 $_ = bless( {address => $_}, $family )->address;
348 3 s/:[:0]+$/::/;
349 }
350 3 return \%object;
351 }
352  
353  
354 package Net::DNS::RR::OPT::EXPIRE; # RFC7314
355  
356 sub _compose {
357 2 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 3 4
358 2 return pack 'N', pop @argument;
359 }
360  
361 sub _decompose {
362 2 ▶ my $argument = pop @_;
Subroutine _decompose: called CC=1 SCAR=0.0
363 2 return {'EXPIRE-TIMER' => unpack 'N', $argument};
364 }
365  
366  
367 package Net::DNS::RR::OPT::COOKIE; # RFC7873
368  
369 12 my @field10 = qw(CLIENT SERVER);
370  
371 sub _compose {
372 3 ▶ my ( undef, @argument ) = @_;
Subroutine _compose: called CC=5 SCAR=16.1
373 3 for ( ref( $argument[0] ) ) {
374 3 ▶ /HASH/ && ( @argument = @{$argument[0]}{@field10} );
Branch: 1 branch
BranchTrueFalseTotal
/HASH/ and @argument = @{$argument[0];}{@field10} 1 2 3
375 3 ▶ /ARRAY/ && ( @argument = @{$argument[0]} );
Branch: 1 branch
BranchTrueFalseTotal
/ARRAY/ and @argument = @{$argument[0];} 1 2 3
376 }
377 3 ▶ return pack 'a8a*', map { pack 'H*', $_ || '' } @argument;
Condition100%2/2
$_ || ''
l!l
32
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
378 }
379  
380 sub _decompose {
381 2 ▶ my %object;
Subroutine _decompose: called CC=1 SCAR=0.0
382 2 @object{@field10} = map { pack 'U0a*', $_ } unpack 'H16H*', pop @_; # mark as UTF-8
383 2 return \%object;
384 }
385  
386  
387 package Net::DNS::RR::OPT::TCP_KEEPALIVE; # RFC7828
388  
389 sub _compose {
390 2 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 3 4
391 2 return pack 'n', pop @argument;
392 }
393  
394 sub _decompose {
395 2 ▶ my $argument = pop @_;
Subroutine _decompose: called CC=1 SCAR=0.0
396 2 return {'TIMEOUT' => unpack 'n', $argument};
397 }
398  
399  
400 package Net::DNS::RR::OPT::PADDING; # RFC7830
401  
402 sub _compose {
403 5 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 11 12
404 5 ▶ my $length = pop(@argument) || 0;
Condition100%2/2
pop @argument || 0
l!l
41
MC/DC100%1/1
pop @argument || 0
pop @argument
Truth table100%2/2
A
A= pop @argument
Aresult
11
00
405 5 return pack "x$length";
406 }
407  
408 sub _decompose {
409 3 ▶ my $argument = pop @_;
Subroutine _decompose: called CC=2 SCAR=6.9
410 3 ▶ return {'OPTION-LENGTH' => length $argument} if $argument =~ /^\000*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $argument =~ /^\000*$/ 2 1 3
411 1 return {'BASE16' => unpack 'H*', $argument};
412 }
413  
414  
415 package Net::DNS::RR::OPT::CHAIN; # RFC7901
416  
417 sub _compose {
418 1 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 1 2
419 1 return Net::DNS::DomainName->new( pop @argument )->encode;
420 }
421  
422 sub _decompose {
423 2 ▶ my $argument = pop @_;
Subroutine _decompose: called CC=1 SCAR=0.0
424 2 return {'CLOSEST-TRUST-POINT' => Net::DNS::DomainName->decode( \$argument )->string};
425 }
426  
427  
428 package Net::DNS::RR::OPT::KEY_TAG; # RFC8145
429  
430 sub _compose {
431 2 ▶ my ( undef, @argument ) = map { ref($_) ? @$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 6 7
432 2 return pack 'n*', @argument;
433 }
434  
435 2 ▶sub _decompose { return [unpack 'n*', pop @_] }
Subroutine _decompose: called CC=1 SCAR=0.0
436  
437  
438 package Net::DNS::RR::OPT::EXTENDED_ERROR; # RFC8914
439  
440 sub _compose {
441 6 ▶ my ( undef, @arg ) = @_;
Subroutine _compose: called CC=3 SCAR=11.0
442 6 ▶ my %arg = ref( $arg[0] ) ? %{$arg[0]} : @arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg[0] ? : 3 3 6
443 6 ▶ my $text = join '', Net::DNS::RR::OPT::_JSONify( $arg{'EXTRA-TEXT'} || '' );
Condition100%2/2
$arg{'EXTRA-TEXT'} || ''
l!l
42
MC/DC100%1/1
$arg{'EXTRA-TEXT'} || ''
$arg{'EXTRA-TEXT'}
Truth table100%2/2
A
A= $arg{'EXTRA-TEXT'}
Aresult
11
00
444 6 return pack 'na*', $arg{'INFO-CODE'}, Net::DNS::Text->new($text)->raw;
445 }
446  
447 sub _decompose {
448 4 ▶ my ( $code, $text ) = unpack 'na*', pop @_;
Subroutine _decompose: called CC=6 SCAR=17.9
449 4 my $error = $Net::DNS::Parameters::dnserrorbyval{$code};
450 4 ▶ my @error = defined($error) ? ( 'ERROR' => $error ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 2 2 4
451 4 my $extra = Net::DNS::Text->decode( \$text, 0, length $text );
452 4 for ( $extra->value ) {
453 4 ▶ last unless /^[\[\{]/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^[\[\{]/ 2 2 4
454 2 s/[`]([^`]*)[`]/$1/g; ## suppress backticks
455 2 s/([\$\@])/\\$1/g; ## Here be dragons!
456 2 my $REGEX = q/("[^"]*"|[\[\]{}:,]|[-0-9.Ee+]+)|\s+|(.)/;
457 2 ▶ my @split = grep { defined && length } split /$REGEX/o;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 45 22 67
458 2 ▶ my $value = eval join( ' ', 'no integer;', map { s/^:$/=>/; $_ } @split );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
459 2 ▶ return {'INFO-CODE' => $code, @error, 'EXTRA-TEXT' => $value} if ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 1 1 2
460 }
461 3 return {'INFO-CODE' => $code, @error, 'EXTRA-TEXT' => $extra->value};
462 }
463  
464  
465 package Net::DNS::RR::OPT::REPORT_CHANNEL; # RFC9567
466  
467 sub _compose {
468 2 ▶ my ( undef, @argument ) = map { ref($_) ? %$_ : $_ } @_;
Subroutine _compose: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 4 5
469 2 return Net::DNS::DomainName->new( pop @argument )->encode;
470 }
471  
472 sub _decompose {
473 2 ▶ my $argument = pop @_;
Subroutine _decompose: called CC=1 SCAR=0.0
474 2 return {'AGENT-DOMAIN' => Net::DNS::DomainName->decode( \$argument )->string};
475 }
476  
477  
478 package Net::DNS::RR::OPT::ZONEVERSION; # RFC9660
479  
480 12 my @field19 = qw(LABELCOUNT TYPE VERSION);
481  
482 sub _compose {
483 3 ▶ my ( undef, @argument ) = @_;
Subroutine _compose: called CC=5 SCAR=16.1
484 3 for ( ref( $argument[0] ) ) {
485 3 ▶ /HASH/ && ( @argument = @{$argument[0]}{@field19} );
Branch: 1 branch
BranchTrueFalseTotal
/HASH/ and @argument = @{$argument[0];}{@field19} 1 2 3
486 3 ▶ /ARRAY/ && ( @argument = @{$argument[0]} );
Branch: 1 branch
BranchTrueFalseTotal
/ARRAY/ and @argument = @{$argument[0];} 2 1 3
487 }
488 3 ▶ return scalar(@argument) ? pack( 'C2H*', @argument ) : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @argument ? : 2 1 3
489 }
490  
491 sub _decompose {
492 8 ▶ my %object;
Subroutine _decompose: called CC=1 SCAR=0.0
493 8 my ( $l, $t, $v ) = unpack 'C2H*', pop @_;
494 8 @object{@field19} = ( $l, $t, pack 'U0a*', $v ); # mark hex data as UTF-8
495 8 return \%object;
496 }
497  
498 ########################################
499  
500  
501 12 1;
502 __END__
« DNS/Resolver/Recurse.pm ↑ Summary DNS/RR/APL.pm »