| 1 | package Net::DNS::RR; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 96 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 96 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 96 | our $VERSION = (qw$Id: RR.pm 2037 2025-08-18 14:39:32Z willem $)[2]; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Net::DNS::RR - DNS resource record base class | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Net::DNS; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | $rr = Net::DNS::RR->new('example.com IN AAAA 2001:DB8::1'); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | $rr = Net::DNS::RR->new( | ||||||||||||||||||||||||||||
| 20 | owner => 'example.com', | ||||||||||||||||||||||||||||
| 21 | type => 'AAAA', | ||||||||||||||||||||||||||||
| 22 | address => '2001:DB8::1' | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Net::DNS::RR is the base class for DNS Resource Record (RR) objects. | ||||||||||||||||||||||||||||
| 29 | See also the manual pages for each specific RR type. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 96 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 96 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 96 | ▶ | use constant LIB => grep { $_ ne '.' } grep { !ref($_) } @INC; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 96 | ▶ | use Net::DNS::Parameters qw(%classbyname :class :type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 96 | ▶ | use Net::DNS::DomainName; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | B<WARNING!!!> Do not assume the RR objects you receive from a query | ||||||||||||||||||||||||||||
| 46 | are of a particular type. You must always check the object type | ||||||||||||||||||||||||||||
| 47 | before calling any of its methods. If you call an unknown method, | ||||||||||||||||||||||||||||
| 48 | you will get an error message and execution will be terminated. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1319 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 1319 | my ( $class, @list ) = @_; | |||||||||||||||||||||||||||
| 54 | 1319 | my $rr = eval { | |||||||||||||||||||||||||||
| 55 | 1319 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 56 | 1319 | ▶ | scalar @list > 1 ? &_new_hash : &_new_string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | 1319 | ▶ | return $rr if $rr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 24 | ▶ | my @param = map { defined($_) ? split /\s+/ : 'undef' } @list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 24 | my $stmnt = substr "$class->new( @param )", 0, 80; | |||||||||||||||||||||||||||
| 61 | 24 | croak "${@}in $stmnt\n"; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head2 new (from string) | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | $aaaa = Net::DNS::RR->new('host.example.com. 86400 AAAA 2001:DB8::1'); | ||||||||||||||||||||||||||||
| 68 | $mx = Net::DNS::RR->new('example.com. 7200 MX 10 mailhost.example.com.'); | ||||||||||||||||||||||||||||
| 69 | $cname = Net::DNS::RR->new('www.example.com 300 IN CNAME host.example.com'); | ||||||||||||||||||||||||||||
| 70 | $txt = Net::DNS::RR->new('txt.example.com 3600 HS TXT "text data"'); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Returns an object of the appropriate RR type, or a L<Net::DNS::RR> object | ||||||||||||||||||||||||||||
| 73 | if the type is not implemented. The attribute values are extracted from the | ||||||||||||||||||||||||||||
| 74 | string passed by the user. The syntax of the argument string follows the | ||||||||||||||||||||||||||||
| 75 | RFC1035 specification for zone files, and is compatible with the result | ||||||||||||||||||||||||||||
| 76 | returned by the string method. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | The owner and RR type are required; all other information is optional. | ||||||||||||||||||||||||||||
| 79 | Omitting the optional fields is useful for creating the empty RDATA | ||||||||||||||||||||||||||||
| 80 | sections required for certain dynamic update operations. | ||||||||||||||||||||||||||||
| 81 | See the L<Net::DNS::Update> manual page for additional examples. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | All names are interpreted as fully qualified domain names. | ||||||||||||||||||||||||||||
| 84 | The trailing dot (.) is optional. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 96 | my $PARSE_REGEX = q/("[^"]*")|;[^\n]*|[ \t\n\r\f()]+/; # NB: *not* \s (matches Unicode white space) | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1020 | ▶ | sub _new_string { | ||||||||||||||||||||||||||
|
Subroutine
_new_string: called CC=18 SCAR=28.9
| |||||||||||||||||||||||||||||
| 91 | 1020 | my ( $base, $string ) = @_; | |||||||||||||||||||||||||||
| 92 | 1020 | ▶ | die 'argument absent or undefined' unless defined $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 1019 | ▶ | die 'non-scalar argument' if ref $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # parse into quoted strings, contiguous non-whitespace and (discarded) comments | ||||||||||||||||||||||||||||
| 96 | 1017 | local $_ = $string; | |||||||||||||||||||||||||||
| 97 | 1017 | s/\\\\/\\092/g; # disguise escaped escape | |||||||||||||||||||||||||||
| 98 | 1017 | s/\\"/\\034/g; # disguise escaped quote | |||||||||||||||||||||||||||
| 99 | 1017 | s/\\\(/\\040/g; # disguise escaped bracket | |||||||||||||||||||||||||||
| 100 | 1017 | s/\\\)/\\041/g; # disguise escaped bracket | |||||||||||||||||||||||||||
| 101 | 1017 | s/\\;/\\059/g; # disguise escaped semicolon | |||||||||||||||||||||||||||
| 102 | 1017 | ▶ | my ( $owner, @token ) = grep { defined && length } split /$PARSE_REGEX/o; | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $_ && length $_
MC/DC100%2/2
defined $_ && length $_
defined $_
length $_
Truth table100%3/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1017 | ▶ | die 'unable to parse RR string' unless scalar @token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1016 | my $t1 = $token[0]; | |||||||||||||||||||||||||||
| 106 | 1016 | my $t2 = $token[1]; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1016 | my ( $ttl, $class ); | |||||||||||||||||||||||||||
| 109 | 1016 | ▶ | if ( not defined $t2 ) { # <owner> <type> | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 110 | 70 | ▶ | @token = ('ANY') if $classbyname{uc $t1}; # <owner> <class> | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } elsif ( $t1 =~ /^\d/ ) { | ||||||||||||||||||||||||||||
| 112 | 495 | $ttl = shift @token; # <owner> <ttl> [<class>] <type> | |||||||||||||||||||||||||||
| 113 | 495 | ▶ | $class = shift @token if $classbyname{uc $t2} || $t2 =~ /^CLASS\d/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Net::DNS::RR::classbyname{uc $t2} or $t2 =~ /^CLASS\d/i
MC/DC100%2/2
$Net::DNS::RR::classbyname{uc $t2} or $t2 =~ /^CLASS\d/i
$Net::DNS::RR::classbyname{uc $t2}
$t2 =~ /^CLASS\d/i
Truth table100%3/3
A or B
A= $Net::DNS::RR::classbyname{uc $t2}B= $t2 =~ /^CLASS\d/i
| |||||||||||||||||||||||||||||
| 114 | ▶ | } elsif ( $classbyname{uc $t1} || $t1 =~ /^CLASS\d/i ) { | |||||||||||||||||||||||||||
|
Condition100%3/3
$Net::DNS::RR::classbyname{uc $t1} or $t1 =~ /^CLASS\d/i
MC/DC100%2/2
$Net::DNS::RR::classbyname{uc $t1} or $t1 =~ /^CLASS\d/i
$Net::DNS::RR::classbyname{uc $t1}
$t1 =~ /^CLASS\d/i
Truth table100%3/3
A or B
A= $Net::DNS::RR::classbyname{uc $t1}B= $t1 =~ /^CLASS\d/i
| |||||||||||||||||||||||||||||
| 115 | 53 | $class = shift @token; # <owner> <class> [<ttl>] <type> | |||||||||||||||||||||||||||
| 116 | 53 | ▶ | $ttl = shift @token if $t2 =~ /^\d/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1016 | my $type = shift(@token); | |||||||||||||||||||||||||||
| 120 | 1016 | my $populated = scalar @token; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1016 | my $self = $base->_subclass( $type, $populated ); # create RR object | |||||||||||||||||||||||||||
| 123 | 1015 | $self->owner($owner); | |||||||||||||||||||||||||||
| 124 | 1015 | &class( $self, $class ); # specify CLASS | |||||||||||||||||||||||||||
| 125 | 1015 | &ttl( $self, $ttl ); # specify TTL | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1015 | ▶ | return $self unless $populated; # empty RR | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 926 | ▶ | if ( $#token && $token[0] =~ /^[\\]?#$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$#token and $token[0] =~ /^[\\]?#$/
MC/DC100%2/2
$#token and $token[0] =~ /^[\\]?#$/
$#token
$token[0] =~ /^[\\]?#$/
Truth table100%3/3
A and B
A= $#tokenB= $token[0] =~ /^[\\]?#$/
| |||||||||||||||||||||||||||||
| 130 | 29 | shift @token; # RFC3597 hexadecimal format | |||||||||||||||||||||||||||
| 131 | 29 | ▶ | my $rdlen = shift(@token) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift @token || 0
MC/DC100%1/1
shift @token || 0
shift @token
Truth table100%2/2
A
A= shift @token
| |||||||||||||||||||||||||||||
| 132 | 29 | my $rdata = pack 'H*', join( '', @token ); | |||||||||||||||||||||||||||
| 133 | 29 | ▶ | die 'length and hexadecimal data inconsistent' unless $rdlen == length $rdata; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 26 | $self->rdata($rdata); # unpack RDATA | |||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||
| 136 | 897 | $self->_parse_rdata(@token); # parse arguments | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 901 | $self->_post_parse(); | |||||||||||||||||||||||||||
| 140 | 890 | return $self; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 new (from hash) | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | $rr = Net::DNS::RR->new(%hash); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | $rr = Net::DNS::RR->new( | ||||||||||||||||||||||||||||
| 149 | owner => 'host.example.com', | ||||||||||||||||||||||||||||
| 150 | ttl => 86400, | ||||||||||||||||||||||||||||
| 151 | class => 'IN', | ||||||||||||||||||||||||||||
| 152 | type => 'AAAA', | ||||||||||||||||||||||||||||
| 153 | address => '2001:DB8::1' | ||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | $rr = Net::DNS::RR->new( | ||||||||||||||||||||||||||||
| 157 | owner => 'txt.example.com', | ||||||||||||||||||||||||||||
| 158 | type => 'TXT', | ||||||||||||||||||||||||||||
| 159 | txtdata => [ 'one', 'two' ] | ||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Returns an object of the appropriate RR type, or a L<Net::DNS::RR> object | ||||||||||||||||||||||||||||
| 163 | if the type is not implemented. Consult the relevant manual pages for the | ||||||||||||||||||||||||||||
| 164 | usage of type specific attributes. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | The owner and RR type are required; all other information is optional. | ||||||||||||||||||||||||||||
| 167 | Omitting optional attributes is useful for creating the empty RDATA | ||||||||||||||||||||||||||||
| 168 | sections required for certain dynamic update operations. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 96 | my @core = qw(owner name type class ttl rdlength); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 586 | ▶ | sub _new_hash { | ||||||||||||||||||||||||||
|
Subroutine
_new_hash: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 175 | 586 | my $base = shift; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 586 | my %argument = ( owner => '.', type => 'NULL' ); | |||||||||||||||||||||||||||
| 178 | 586 | my @attribute; | |||||||||||||||||||||||||||
| 179 | 586 | ▶ | while ( my $key = shift ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 1372 | push @attribute, $key; | |||||||||||||||||||||||||||
| 181 | 1372 | $argument{lc $key} = shift; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 586 | my ( $owner, $name, $type, $class, $ttl ) = delete @argument{@core}; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 586 | my $self = $base->_subclass( $type, scalar(%argument) ); | |||||||||||||||||||||||||||
| 187 | 586 | ▶ | $self->owner( $name ? $name : $owner ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 586 | ▶ | $self->class($class) if defined $class; # optional CLASS | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 586 | ▶ | $self->ttl($ttl) if defined $ttl; # optional TTL | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 586 | eval { | |||||||||||||||||||||||||||
| 192 | 586 | foreach my $attribute (@attribute) { | |||||||||||||||||||||||||||
| 193 | 1372 | my $value = $argument{lc $attribute}; | |||||||||||||||||||||||||||
| 194 | 1372 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 473 | ▶ | $self->$attribute( ref($value) eq 'ARRAY' ? @$value : $value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||
| 198 | 586 | ▶ | die ref($self) eq __PACKAGE__ ? "type $type not implemented" : () if $@; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 584 | $self->_post_parse(); | |||||||||||||||||||||||||||
| 201 | 584 | return $self; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head2 decode | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | ( $rr, $next ) = Net::DNS::RR->decode( \$data, $offset, @opaque ); | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | Decodes a DNS resource record at the specified location within a | ||||||||||||||||||||||||||||
| 210 | DNS packet. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | The argument list consists of a reference to the buffer containing | ||||||||||||||||||||||||||||
| 213 | the packet data and offset indicating where resource record begins. | ||||||||||||||||||||||||||||
| 214 | Any remaining arguments are passed as opaque data to subordinate | ||||||||||||||||||||||||||||
| 215 | decoders and do not form part of the published interface. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | Returns a C<Net::DNS::RR> object and the offset of the next record | ||||||||||||||||||||||||||||
| 218 | in the packet. | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | An exception is raised if the data buffer contains insufficient or | ||||||||||||||||||||||||||||
| 221 | corrupt data. | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 96 | ▶ | use constant RRFIXEDSZ => length pack 'n2 N n', (0) x 4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 10014 | ▶ | sub decode { | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | 10014 | my ( $base, @argument ) = @_; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 10014 | my ( $owner, $fixed ) = Net::DNS::DomainName1035->decode(@argument); | |||||||||||||||||||||||||||
| 231 | 10013 | my $index = $fixed + RRFIXEDSZ; | |||||||||||||||||||||||||||
| 232 | 10013 | my ( $data, $offset, @opaque ) = @argument; | |||||||||||||||||||||||||||
| 233 | 10013 | ▶ | die 'corrupt wire-format data' if length $$data < $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 10012 | my $self = $base->_subclass( unpack "\@$fixed n", $$data ); | |||||||||||||||||||||||||||
| 235 | 10012 | $self->{owner} = $owner; | |||||||||||||||||||||||||||
| 236 | 10012 | @{$self}{qw(class ttl rdlength)} = unpack "\@$fixed x2 n N n", $$data; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 10012 | my $next = $index + $self->{rdlength}; | |||||||||||||||||||||||||||
| 239 | 10012 | ▶ | die 'corrupt wire-format data' if length $$data < $next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 10011 | ▶ | if ( $next > $index or $self->type eq 'OPT' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next > $index or $self->type eq "OPT"
MC/DC100%2/2
$next > $index or $self->type eq "OPT"
$next > $index
$self->type eq "OPT"
Truth table100%3/3
A or B
A= $next > $indexB= $self->type eq "OPT"
| |||||||||||||||||||||||||||||
| 242 | 10010 | local $self->{offset} = $offset; | |||||||||||||||||||||||||||
| 243 | 10010 | eval { $self->_decode_rdata( $data, $index, @opaque ) }; | |||||||||||||||||||||||||||
| 244 | 10010 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 10011 | ▶ | return wantarray ? ( $self, $next ) : $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =head2 encode | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | $data = $rr->encode( $offset, @opaque ); | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | Returns the C<Net::DNS::RR> in binary format suitable for inclusion | ||||||||||||||||||||||||||||
| 256 | in a DNS packet buffer. | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | The offset indicates the intended location within the packet data | ||||||||||||||||||||||||||||
| 259 | where the C<Net::DNS::RR> is to be stored. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | Any remaining arguments are opaque data which are passed intact to | ||||||||||||||||||||||||||||
| 262 | subordinate encoders. | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =cut | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 1145 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 1145 | my ( $self, $offset, @opaque ) = @_; | |||||||||||||||||||||||||||
| 268 | 1145 | ▶ | ( $offset, @opaque ) = ( 0x4000, {} ) unless defined $offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 1145 | my $owner = $self->{owner}->encode( $offset, @opaque ); | |||||||||||||||||||||||||||
| 271 | 1145 | my ( $type, $class, $ttl ) = @{$self}{qw(type class ttl)}; | |||||||||||||||||||||||||||
| 272 | 1145 | ▶ | my $rdata = $self->_empty ? '' : $self->_encode_rdata( $offset + length($owner) + RRFIXEDSZ, @opaque ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 1145 | ▶ | return pack 'a* n2 N n a*', $owner, $type, $class || 1, $ttl || 0, length $rdata, $rdata; | ||||||||||||||||||||||||||
|
Condition100%4/4
$class || 1
$ttl || 0
MC/DC100%1/1
$class || 1
$class
MC/DC100%1/1
$ttl || 0
$ttl
Truth table100%2/2
A
A= $class
Truth table100%2/2
A
A= $ttl
| |||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =head2 canonical | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | $data = $rr->canonical; | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | Returns the C<Net::DNS::RR> in canonical binary format suitable for | ||||||||||||||||||||||||||||
| 282 | DNSSEC signature validation. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | The absence of the associative array argument signals to subordinate | ||||||||||||||||||||||||||||
| 285 | encoders that the canonical uncompressed form of embedded domain | ||||||||||||||||||||||||||||
| 286 | names is to be used. | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =cut | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 305 | ▶ | sub canonical { | ||||||||||||||||||||||||||
|
Subroutine
canonical: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 291 | 305 | my $self = shift; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 305 | my $owner = $self->{owner}->canonical; | |||||||||||||||||||||||||||
| 294 | 305 | my ( $type, $class, $ttl ) = @{$self}{qw(type class ttl)}; | |||||||||||||||||||||||||||
| 295 | 305 | ▶ | my $rdata = $self->_empty ? '' : $self->_encode_rdata( length($owner) + RRFIXEDSZ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 305 | ▶ | return pack 'a* n2 N n a*', $owner, $type, $class || 1, $ttl || 0, length $rdata, $rdata; | ||||||||||||||||||||||||||
|
Condition100%4/4
$class || 1
$ttl || 0
MC/DC100%1/1
$class || 1
$class
MC/DC100%1/1
$ttl || 0
$ttl
Truth table100%2/2
A
A= $class
Truth table100%2/2
A
A= $ttl
| |||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =head2 print | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | $rr->print; | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | Prints the resource record to the currently selected output filehandle. | ||||||||||||||||||||||||||||
| 305 | Calls the string method to get the formatted RR representation. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 27 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 310 | 27 | print shift->string, "\n"; | |||||||||||||||||||||||||||
| 311 | 27 | return; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =head2 string | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | print $rr->string, "\n"; | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | Returns a string representation of the RR using the master file format | ||||||||||||||||||||||||||||
| 320 | mandated by RFC1035. | ||||||||||||||||||||||||||||
| 321 | All domain names are fully qualified with trailing dot. | ||||||||||||||||||||||||||||
| 322 | This differs from RR attribute methods, which omit the trailing dot. | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | =cut | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 1118 | ▶ | sub string { | ||||||||||||||||||||||||||
|
Subroutine
string: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 327 | 1118 | my $self = shift; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 1118 | my $owner = $self->{owner}->string; | |||||||||||||||||||||||||||
| 330 | 1118 | ▶ | my @ttl = defined $self->{ttl} ? $self->{ttl} : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 1118 | ▶ | my @class = defined $self->{class} ? $self->class : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 1118 | my @core = ( $owner, @ttl, @class, $self->type ); | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 1118 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 335 | 1118 | my $empty = $self->_empty; | |||||||||||||||||||||||||||
| 336 | 1118 | ▶ | my @rdata = $empty ? () : eval { $self->_format_rdata }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 1118 | ▶ | carp $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 1118 | ▶ | my $tab = length($owner) < 72 ? "\t" : ' '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 1118 | my @line = _wrap( join( $tab, @core, '(' ), @rdata, ')' ); | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 1118 | my $last = pop(@line); # last or only line | |||||||||||||||||||||||||||
| 343 | 1118 | ▶ | $last = join $tab, @core, "@rdata" unless scalar(@line); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1118 | ▶ | $self->_annotation('no data') if $empty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 1118 | return join "\n\t", @line, _wrap( $last, $self->_annotation ); | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =head2 plain | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | $plain = $rr->plain; | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | Returns a simplified single-line representation of the RR. | ||||||||||||||||||||||||||||
| 355 | This facilitates interaction with programs like nsupdate | ||||||||||||||||||||||||||||
| 356 | which have rudimentary parsers. | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | =cut | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 8 | ▶ | sub plain { | ||||||||||||||||||||||||||
|
Subroutine
plain: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 361 | 8 | return join ' ', shift->token; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =head2 token | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | @token = $rr->token; | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | Returns a token list representation of the RR zone file string. | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 7 | ▶ | sub token { | ||||||||||||||||||||||||||
|
Subroutine
token: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 374 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 7 | ▶ | my @ttl = defined $self->{ttl} ? $self->{ttl} : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 7 | ▶ | my @class = defined $self->{class} ? $self->class : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 7 | my @core = ( $self->{owner}->string, @ttl, @class, $self->type ); | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | # parse into quoted strings, contiguous non-whitespace and (discarded) comments | ||||||||||||||||||||||||||||
| 381 | 7 | ▶ | local $_ = $self->_empty ? '' : join( ' ', $self->_format_rdata ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 7 | s/\\\\/\\092/g; # disguise escaped escape | |||||||||||||||||||||||||||
| 383 | 7 | s/\\"/\\034/g; # disguise escaped quote | |||||||||||||||||||||||||||
| 384 | 7 | s/\\\(/\\040/g; # disguise escaped bracket | |||||||||||||||||||||||||||
| 385 | 7 | s/\\\)/\\041/g; # disguise escaped bracket | |||||||||||||||||||||||||||
| 386 | 7 | s/\\;/\\059/g; # disguise escaped semicolon | |||||||||||||||||||||||||||
| 387 | 7 | ▶ | return ( @core, grep { defined && length } split /$PARSE_REGEX/o ); | ||||||||||||||||||||||||||
|
Condition100%3/3
defined $_ && length $_
MC/DC100%2/2
defined $_ && length $_
defined $_
length $_
Truth table100%3/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =head2 generic | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | $generic = $rr->generic; | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | Returns the generic RR representation defined in RFC3597. This facilitates | ||||||||||||||||||||||||||||
| 396 | creation of zone files containing RRs unrecognised by outdated nameservers | ||||||||||||||||||||||||||||
| 397 | and provisioning software. | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | =cut | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 8 | ▶ | sub generic { | ||||||||||||||||||||||||||
|
Subroutine
generic: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 402 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 8 | ▶ | my @ttl = defined $self->{ttl} ? $self->{ttl} : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 8 | ▶ | my @class = defined $self->{class} ? "CLASS$self->{class}" : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 8 | my @core = ( $self->{owner}->string, @ttl, @class, "TYPE$self->{type}" ); | |||||||||||||||||||||||||||
| 407 | 8 | my $data = $self->rdata; | |||||||||||||||||||||||||||
| 408 | 8 | my @data = ( '\\#', length($data), split /(\S{32})/, unpack 'H*', $data ); | |||||||||||||||||||||||||||
| 409 | 8 | my @line = _wrap( "@core (", @data, ')' ); | |||||||||||||||||||||||||||
| 410 | 8 | ▶ | return join "\n\t", @line if scalar(@line) > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 7 | return join ' ', @core, @data; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | =head2 owner name | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | $name = $rr->owner; | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | Returns the owner name of the record. | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 2323 | ▶ | sub owner { | ||||||||||||||||||||||||||
|
Subroutine
owner: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | 2323 | my ( $self, @name ) = @_; | |||||||||||||||||||||||||||
| 425 | 2323 | for (@name) { $self->{owner} = Net::DNS::DomainName1035->new($_) } | |||||||||||||||||||||||||||
| 426 | 2323 | ▶ | return defined wantarray ? $self->{owner}->name : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 424 | ▶ | sub name { return &owner; } ## historical | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =head2 type | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | $type = $rr->type; | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | Returns the record type. | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =cut | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 2209 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 441 | 2209 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 442 | 2209 | for (@value) { croak 'not possible to change RR->type' } | |||||||||||||||||||||||||||
| 443 | 2208 | return typebyval( $self->{type} ); | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | =head2 class | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | $class = $rr->class; | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | Resource record class. | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =cut | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 2527 | ▶ | sub class { | ||||||||||||||||||||||||||
|
Subroutine
class: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 456 | 2527 | my ( $self, $class ) = @_; | |||||||||||||||||||||||||||
| 457 | 2527 | ▶ | return $self->{class} = classbyname($class) if defined $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 1560 | ▶ | return defined $self->{class} ? classbyval( $self->{class} ) : 'IN'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =head2 ttl | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | $ttl = $rr->ttl; | ||||||||||||||||||||||||||||
| 465 | $ttl = $rr->ttl(3600); | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | Resource record time to live in seconds. | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | =cut | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | # The following time units are recognised, but are not part of the | ||||||||||||||||||||||||||||
| 472 | # published API. These are required for parsing BIND zone files but | ||||||||||||||||||||||||||||
| 473 | # should not be used in other contexts. | ||||||||||||||||||||||||||||
| 474 | 96 | my %unit = ( W => 604800, D => 86400, H => 3600, M => 60, S => 1 ); | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 1129 | ▶ | sub ttl { | ||||||||||||||||||||||||||
|
Subroutine
ttl: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 477 | 1129 | my ( $self, $time ) = @_; | |||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 1129 | ▶ | return $self->{ttl} || 0 unless defined $time; # avoid defining rr->{ttl} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'ttl'} || 0
MC/DC100%1/1
$self->{'ttl'} || 0
$self->{'ttl'}
Truth table100%2/2
A
A= $self->{'ttl'}
| |||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 596 | my $ttl = 0; | |||||||||||||||||||||||||||
| 482 | 596 | my %time = reverse split /(\D)\D*/, $time . 'S'; | |||||||||||||||||||||||||||
| 483 | 596 | ▶ | while ( my ( $u, $t ) = each %time ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | 596 | ▶ | my $scale = $unit{uc $u} || die qq(bad time: $t$u); | ||||||||||||||||||||||||||
|
Condition100%2/2
$unit{uc $u} || die("bad time: $t$u")
MC/DC100%1/1
$unit{uc $u} || die("bad time: $t$u")
$unit{uc $u}
Truth table100%2/2
A
A= $unit{uc $u}
| |||||||||||||||||||||||||||||
| 485 | 595 | $ttl += $t * $scale; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | 595 | return $self->{ttl} = $ttl; | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | ################################################################################ | ||||||||||||||||||||||||||||
| 492 | ## | ||||||||||||||||||||||||||||
| 493 | ## Default implementation for unknown RR type | ||||||||||||||||||||||||||||
| 494 | ## | ||||||||||||||||||||||||||||
| 495 | ################################################################################ | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 7 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_decode_rdata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 498 | 7 | my ( $self, $data, $offset ) = @_; | |||||||||||||||||||||||||||
| 499 | 7 | return $self->{rdata} = substr $$data, $offset, $self->{rdlength}; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 12 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_encode_rdata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 504 | 12 | return shift->{rdata}; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 7 | ▶ | sub _format_rdata { ## format rdata portion of RR string | ||||||||||||||||||||||||||
|
Subroutine
_format_rdata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 509 | 7 | my $rdata = shift->rdata; # RFC3597 unknown RR format | |||||||||||||||||||||||||||
| 510 | 7 | return ( '\\#', length($rdata), split /(\S{32})/, unpack 'H*', $rdata ); | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 2 | ▶ | sub _parse_rdata { ## parse RR attributes in argument list | ||||||||||||||||||||||||||
|
Subroutine
_parse_rdata: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 515 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 516 | 2 | ▶ | die join ' ', 'type', $self->type, 'not implemented' if ref($self) eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | 1 | die join ' ', 'no zone file representation defined for', $self->type; | |||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 1431 | ▶ | sub _post_parse { } ## parser post processing | ||||||||||||||||||||||||||
|
Subroutine
_post_parse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 117 | ▶ | sub _defaults { } ## set attribute default values | ||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 2 | ▶ | sub dump { ## print internal data structure | ||||||||||||||||||||||||||
|
Subroutine
dump: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 528 | 2 | my @data = @_; # uncoverable pod | |||||||||||||||||||||||||||
| 529 | 2 | require Data::Dumper; | |||||||||||||||||||||||||||
| 530 | 2 | ▶ | local $Data::Dumper::Maxdepth = $Data::Dumper::Maxdepth || 6; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Data::Dumper::Maxdepth || 6
MC/DC100%1/1
$Data::Dumper::Maxdepth || 6
$Data::Dumper::Maxdepth
Truth table100%2/2
A
A= $Data::Dumper::Maxdepth
| |||||||||||||||||||||||||||||
| 531 | 2 | ▶ | local $Data::Dumper::Sortkeys = $Data::Dumper::Sortkeys || 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Data::Dumper::Sortkeys || 1
MC/DC100%1/1
$Data::Dumper::Sortkeys || 1
$Data::Dumper::Sortkeys
Truth table100%2/2
A
A= $Data::Dumper::Sortkeys
| |||||||||||||||||||||||||||||
| 532 | 2 | ▶ | local $Data::Dumper::Useqq = $Data::Dumper::Useqq || 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Data::Dumper::Useqq || 1
MC/DC100%1/1
$Data::Dumper::Useqq || 1
$Data::Dumper::Useqq
Truth table100%2/2
A
A= $Data::Dumper::Useqq
| |||||||||||||||||||||||||||||
| 533 | 2 | return print Data::Dumper::Dumper(@data); | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 2 | ▶ | sub rdatastr { ## historical RR subtype method | ||||||||||||||||||||||||||
|
Subroutine
rdatastr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 537 | 2 | my $self = shift; # uncoverable pod | |||||||||||||||||||||||||||
| 538 | 2 | $self->_deprecate('prefer $rr->rdstring()'); | |||||||||||||||||||||||||||
| 539 | 2 | return $self->rdstring; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | =head2 rdata | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | $rr = Net::DNS::RR->new( type => NULL, rdata => 'arbitrary' ); | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | Resource record data section when viewed as opaque octets. | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | =cut | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 173 | ▶ | sub rdata { | ||||||||||||||||||||||||||
|
Subroutine
rdata: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 552 | 173 | my $self = shift; | |||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | 173 | ▶ | return $self->_empty ? '' : eval { $self->_encode_rdata( 0x4000, {} ) } unless @_; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | 34 | ▶ | my $data = shift || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 557 | 34 | ▶ | $self->_decode_rdata( \$data, 0 ) if ( $self->{rdlength} = length $data ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 558 | 32 | return; | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | =head2 rdstring | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | $rdstring = $rr->rdstring; | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | Returns a string representation of the RR-specific data. | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =cut | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 88 | ▶ | sub rdstring { | ||||||||||||||||||||||||||
|
Subroutine
rdstring: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 571 | 88 | my $self = shift; | |||||||||||||||||||||||||||
| 572 | 88 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 88 | ▶ | my @rdata = $self->_empty ? () : eval { $self->_format_rdata }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | 88 | ▶ | carp $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 88 | return join "\n\t", _wrap(@rdata); | |||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | =head2 rdlength | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | $rdlength = $rr->rdlength; | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | Returns the uncompressed length of the encoded RR-specific data. | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | =cut | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 7 | ▶ | sub rdlength { | ||||||||||||||||||||||||||
|
Subroutine
rdlength: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 590 | 7 | return length shift->rdata; | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | ################################################################################### | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | =head1 Sorting of RR arrays | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | Sorting of RR arrays is done by Net::DNS::rrsort(), see documentation | ||||||||||||||||||||||||||||
| 599 | for L<Net::DNS>. This package provides class methods to set the | ||||||||||||||||||||||||||||
| 600 | comparator function used for a particular RR based on its attributes. | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | =head2 set_rrsort_func | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | my $function = sub { ## numerically ascending order | ||||||||||||||||||||||||||||
| 606 | $Net::DNS::a->{'preference'} <=> $Net::DNS::b->{'preference'}; | ||||||||||||||||||||||||||||
| 607 | }; | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | Net::DNS::RR::MX->set_rrsort_func( 'preference', $function ); | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | Net::DNS::RR::MX->set_rrsort_func( 'default_sort', $function ); | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | set_rrsort_func() must be called as a class method. The first argument is | ||||||||||||||||||||||||||||
| 614 | the attribute name on which the sorting is to take place. If you specify | ||||||||||||||||||||||||||||
| 615 | "default_sort" then that is the sort algorithm that will be used when | ||||||||||||||||||||||||||||
| 616 | get_rrsort_func() is called without an RR attribute as argument. | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | The second argument is a reference to a comparator function that uses the | ||||||||||||||||||||||||||||
| 619 | global variables $a and $b in the Net::DNS package. During sorting, the | ||||||||||||||||||||||||||||
| 620 | variables $a and $b will contain references to objects of the class whose | ||||||||||||||||||||||||||||
| 621 | set_rrsort_func() was called. The above sorting function will only be | ||||||||||||||||||||||||||||
| 622 | applied to Net::DNS::RR::MX objects. | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | The above example is the sorting function implemented in MX. | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | =cut | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 96 | our %rrsortfunct; | |||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 42 | ▶ | sub set_rrsort_func { | ||||||||||||||||||||||||||
|
Subroutine
set_rrsort_func: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 631 | 42 | my $class = shift; | |||||||||||||||||||||||||||
| 632 | 42 | my $attribute = shift; | |||||||||||||||||||||||||||
| 633 | 42 | my $function = shift; | |||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | 42 | my ($type) = $class =~ m/::([^:]+)$/; | |||||||||||||||||||||||||||
| 636 | 42 | $rrsortfunct{$type}{$attribute} = $function; | |||||||||||||||||||||||||||
| 637 | 42 | return; | |||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | =head2 get_rrsort_func | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | $function = Net::DNS::RR::MX->get_rrsort_func('preference'); | ||||||||||||||||||||||||||||
| 644 | $function = Net::DNS::RR::MX->get_rrsort_func(); | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | get_rrsort_func() returns a reference to the comparator function. | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | =cut | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | 30 | ▶ | my $default = sub { return $Net::DNS::a->canonical() cmp $Net::DNS::b->canonical(); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | 13 | ▶ | sub get_rrsort_func { | ||||||||||||||||||||||||||
|
Subroutine
get_rrsort_func: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 653 | 13 | my $class = shift; | |||||||||||||||||||||||||||
| 654 | 13 | ▶ | my $attribute = shift || 'default_sort'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 'default_sort'
MC/DC100%1/1
shift() || 'default_sort'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 13 | my ($type) = $class =~ m/::([^:]+)$/; | |||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | 13 | ▶ | return $rrsortfunct{$type}{$attribute} || return $default; | ||||||||||||||||||||||||||
|
Condition100%2/2
$Net::DNS::RR::rrsortfunct{$type}{$attribute} || (return $default)
MC/DC100%1/1
$Net::DNS::RR::rrsortfunct{$type}{$attribute} || (return $default)
$Net::DNS::RR::rrsortfunct{$type}{$attribute}
Truth table100%2/2
A
A= $Net::DNS::RR::rrsortfunct{$type}{$attribute}
| |||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | ################################################################################ | ||||||||||||||||||||||||||||
| 663 | # | ||||||||||||||||||||||||||||
| 664 | # Net::DNS::RR->_subclass($rrname) | ||||||||||||||||||||||||||||
| 665 | # Net::DNS::RR->_subclass($rrname, $default) | ||||||||||||||||||||||||||||
| 666 | # | ||||||||||||||||||||||||||||
| 667 | # Create a new object blessed into appropriate RR subclass, after | ||||||||||||||||||||||||||||
| 668 | # loading the subclass module (if necessary). A subclass with no | ||||||||||||||||||||||||||||
| 669 | # corresponding module will be regarded as unknown and blessed | ||||||||||||||||||||||||||||
| 670 | # into the RR base class. | ||||||||||||||||||||||||||||
| 671 | # | ||||||||||||||||||||||||||||
| 672 | # The optional second argument indicates that default values are | ||||||||||||||||||||||||||||
| 673 | # to be copied into the newly created object. | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 96 | our %_MINIMAL = ( 255 => bless ['type' => 255], __PACKAGE__ ); | |||||||||||||||||||||||||||
| 676 | 96 | our %_LOADED = %_MINIMAL; | |||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | 11614 | ▶ | sub _subclass { | ||||||||||||||||||||||||||
|
Subroutine
_subclass: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 679 | 11614 | my ( $class, $rrname, $default ) = @_; | |||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | 11614 | ▶ | unless ( $_LOADED{$rrname} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 682 | 184 | my $rrtype = typebyname($rrname); | |||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | 183 | ▶ | unless ( $_LOADED{$rrtype} ) { # load once only | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | 173 | local @INC = LIB; | |||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | 173 | my $identifier = typebyval($rrtype); | |||||||||||||||||||||||||||
| 688 | 173 | $identifier =~ s/\W/_/g; # kosher Perl identifier | |||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | 173 | my $subclass = join '::', __PACKAGE__, $identifier; | |||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | 173 | ▶ | unless ( eval "require $subclass" ) { ## no critic ProhibitStringyEval | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 693 | 1 | my $perl = Net::DNS::Parameters::_typespec("$rrtype.RRTYPE"); | |||||||||||||||||||||||||||
| 694 | 1 | $subclass = join '::', __PACKAGE__, "TYPE$rrtype"; | |||||||||||||||||||||||||||
| 695 | 1 | ▶ | push @INC, sub { # see perldoc -f require | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 696 | 1 | my @line = split /\n/, $perl; | |||||||||||||||||||||||||||
| 697 | 1 | ▶ | return ( sub { defined( $_ = shift @line ) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 698 | 1 | }; | |||||||||||||||||||||||||||
| 699 | 1 | eval "require $subclass"; ## no critic ProhibitStringyEval | |||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 173 | ▶ | $subclass = __PACKAGE__ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | # cache pre-built minimal and populated default object images | ||||||||||||||||||||||||||||
| 705 | 173 | my @base = ( 'type' => $rrtype ); | |||||||||||||||||||||||||||
| 706 | 173 | $_MINIMAL{$rrtype} = bless [@base], $subclass; | |||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | 173 | my $object = bless {@base}, $subclass; | |||||||||||||||||||||||||||
| 709 | 173 | $object->_defaults; | |||||||||||||||||||||||||||
| 710 | 173 | $_LOADED{$rrtype} = bless [%$object], $subclass; | |||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | 183 | $_MINIMAL{$rrname} = $_MINIMAL{$rrtype}; | |||||||||||||||||||||||||||
| 714 | 183 | $_LOADED{$rrname} = $_LOADED{$rrtype}; | |||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 11613 | ▶ | my $prebuilt = $default ? $_LOADED{$rrname} : $_MINIMAL{$rrname}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 718 | 11613 | return bless {@$prebuilt}, ref($prebuilt); # create object | |||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | 1177 | ▶ | sub _annotation { | ||||||||||||||||||||||||||
|
Subroutine
_annotation: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 723 | 1177 | my ( $self, @note ) = @_; | |||||||||||||||||||||||||||
| 724 | 1177 | ▶ | push @{$self->{annotation}}, "\t; @note" if scalar @note; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 725 | 1177 | ▶ | return wantarray ? @{delete( $self->{annotation} ) || []} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
delete $self->{'annotation'} || []
MC/DC100%1/1
delete $self->{'annotation'} || []
delete $self->{'annotation'}
Truth table100%2/2
A
A= delete $self->{'annotation'}
| |||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | 96 | my %warned; | |||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | 9 | ▶ | sub _deprecate { | ||||||||||||||||||||||||||
|
Subroutine
_deprecate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 732 | 9 | my ( undef, @note ) = @_; | |||||||||||||||||||||||||||
| 733 | 9 | ▶ | carp "deprecated method; @note" unless $warned{"@note"}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 734 | 9 | return; | |||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | 96 | my %ignore = map { ( $_ => 1 ) } @core, 'annotation', '#'; | |||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | 2802 | ▶ | sub _empty { | ||||||||||||||||||||||||||
|
Subroutine
_empty: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 741 | 2802 | my $self = shift; | |||||||||||||||||||||||||||
| 742 | 2802 | ▶ | return not( $self->{'#'} ||= scalar grep { !$ignore{$_} } keys %$self ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"#"} ||= scalar grep({not $ignore{$_};} keys %$self)
MC/DC100%1/1
$self->{"#"} ||= scalar grep({not $ignore{$_};} keys %$self)
$self->{"#"}
Truth table100%2/2
A
A= $self->{"#"}
| |||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | 2358 | ▶ | sub _wrap { | ||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 747 | 2358 | my @text = @_; | |||||||||||||||||||||||||||
| 748 | 2358 | my $cols = 80; | |||||||||||||||||||||||||||
| 749 | 2358 | my $coln = 0; | |||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | 2358 | my ( @line, @fill ); | |||||||||||||||||||||||||||
| 752 | 2358 | foreach (@text) { | |||||||||||||||||||||||||||
| 753 | 5597 | ▶ | $coln += ( length || next ) + 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
length $_ || (next)
MC/DC100%1/1
length $_ || (next)
length $_
Truth table100%2/2
A
A= length $_
| |||||||||||||||||||||||||||||
| 754 | 5561 | ▶ | if ( $coln > $cols ) { # start new line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 755 | 1780 | ▶ | push( @line, join ' ', @fill ) if @fill; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 756 | 1780 | $coln = length; | |||||||||||||||||||||||||||
| 757 | 1780 | @fill = (); | |||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||
| 759 | 5561 | ▶ | $coln = $cols if chomp; # force line break | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 760 | 5561 | ▶ | push( @fill, $_ ) if length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | 2358 | return ( @line, join ' ', @fill ); | |||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | ################################################################################ | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | 1 | ▶ | sub DESTROY { } ## Avoid tickling AUTOLOAD (in cleanup) | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | ## no critic | ||||||||||||||||||||||||||||
| 771 | 11 | ▶ | sub AUTOLOAD { ## Default method | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 772 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||
| 774 | 96 | ▶ | no strict 'refs'; ## no critic ProhibitNoStrict | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 775 | 11 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 776 | 11 | my ($method) = reverse split /::/, $AUTOLOAD; | |||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||
| 778 | 11 | my $canonical = lc($method); ## tolerate mixed-case attribute name | |||||||||||||||||||||||||||
| 779 | 11 | ▶ | if ( $self->can($canonical) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 780 | 6 | ▶ | *{$AUTOLOAD} = sub { shift->$canonical(@_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 781 | 6 | return &$AUTOLOAD; | |||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | 5 | my $oref = ref($self); | |||||||||||||||||||||||||||
| 785 | 5 | ▶ | *{$AUTOLOAD} = sub { }; ## suppress deep recursion | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 786 | 5 | ▶ | croak qq[$self has no class method "$method"] unless $oref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | 4 | my $string = $self->string; | |||||||||||||||||||||||||||
| 789 | 4 | my @object = grep { defined($_) } $oref, $oref->VERSION; | |||||||||||||||||||||||||||
| 790 | 4 | my $module = join '::', __PACKAGE__, $self->type; | |||||||||||||||||||||||||||
| 791 | 4 | ▶ | eval("require $module") if $oref eq __PACKAGE__; ## no critic ProhibitStringyEval | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | 4 | @_ = (<<"END"); | |||||||||||||||||||||||||||
| 794 | *** FATAL PROGRAM ERROR!! Unknown instance method "$method" | ||||||||||||||||||||||||||||
| 795 | *** which the program has attempted to call for the object: | ||||||||||||||||||||||||||||
| 796 | *** | ||||||||||||||||||||||||||||
| 797 | $string | ||||||||||||||||||||||||||||
| 798 | *** | ||||||||||||||||||||||||||||
| 799 | *** THIS IS A BUG IN THE CALLING SOFTWARE, which incorrectly assumes | ||||||||||||||||||||||||||||
| 800 | *** that the object would be of a particular type. The type of an | ||||||||||||||||||||||||||||
| 801 | *** object should be checked before calling any of its methods. | ||||||||||||||||||||||||||||
| 802 | *** | ||||||||||||||||||||||||||||
| 803 | @object | ||||||||||||||||||||||||||||
| 804 | $@ | ||||||||||||||||||||||||||||
| 805 | END | ||||||||||||||||||||||||||||
| 806 | 4 | goto &Carp::confess; | |||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | 96 | 1; | |||||||||||||||||||||||||||
| 811 | __END__ | ||||||||||||||||||||||||||||