| 1 | package Net::DNS::RR::LOC; | ||||||||||||
| 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: LOC.pm 2003 2025-01-21 12:06:06Z 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::LOC - DNS LOC resource record | ||||||||||||
| 13 | |||||||||||||
| 14 | =cut | ||||||||||||
| 15 | |||||||||||||
| 16 | 1 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||
|
Subroutine
_decode_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 1 | my ( $self, $data, $offset ) = @_; | |||||||||||
| 23 | |||||||||||||
| 24 | 1 | my $version = $self->{version} = unpack "\@$offset C", $$data; | |||||||||||
| 25 | 1 | @{$self}{qw(size hp vp latitude longitude altitude)} = unpack "\@$offset xC3N3", $$data; | |||||||||||
| 26 | 1 | return; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | 5 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||
|
Subroutine
_encode_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 5 | my $self = shift; | |||||||||||
| 32 | |||||||||||||
| 33 | 5 | return pack 'C4N3', @{$self}{qw(version size hp vp latitude longitude altitude)}; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | sub _format_rdata { ## format rdata portion of RR string. | ||||||||||
|
Subroutine
_format_rdata: called CC=2 SCAR=6.9
| |||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||
| 39 | |||||||||||||
| 40 | 2 | my ( $altitude, @precision ) = map { $self->$_() . 'm' } qw(altitude size hp vp); | |||||||||||
| 41 | 2 | my $precision = join ' ', @precision; | |||||||||||
| 42 | 2 | for ($precision) { | |||||||||||
| 43 | 2 | s/^1m 10000m 10m$//; | |||||||||||
| 44 | 2 | s/ 10000m 10m$//; | |||||||||||
| 45 | 2 | s/ 10m$//; | |||||||||||
| 46 | } | ||||||||||||
| 47 | 2 | return ( $self->latitude, '', $self->longitude, '', $altitude, $precision ); | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 1 | ▶ | sub _parse_rdata { ## populate RR from rdata in argument list | ||||||||||
|
Subroutine
_parse_rdata: called CC=6 SCAR=17.9
| |||||||||||||
| 52 | 1 | my ( $self, @argument ) = @_; | |||||||||||
| 53 | |||||||||||||
| 54 | 1 | my @lat; | |||||||||||
| 55 | 1 | ▶ | while ( scalar @argument ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 4 | my $this = shift @argument; | |||||||||||
| 57 | 4 | push( @lat, $this ); | |||||||||||
| 58 | 4 | ▶ | last if $this =~ /[NSns]/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | } | ||||||||||||
| 60 | 1 | $self->latitude(@lat); | |||||||||||
| 61 | |||||||||||||
| 62 | 1 | my @long; | |||||||||||
| 63 | 1 | ▶ | while ( scalar @argument ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | 4 | my $this = shift @argument; | |||||||||||
| 65 | 4 | push( @long, $this ); | |||||||||||
| 66 | 4 | ▶ | last if $this =~ /[EWew]/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | } | ||||||||||||
| 68 | 1 | $self->longitude(@long); | |||||||||||
| 69 | |||||||||||||
| 70 | 1 | foreach my $attr (qw(altitude size hp vp)) { | |||||||||||
| 71 | 4 | $self->$attr(@argument); | |||||||||||
| 72 | 4 | shift @argument; | |||||||||||
| 73 | } | ||||||||||||
| 74 | 1 | return; | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | |||||||||||||
| 78 | 1 | ▶ | sub _defaults { ## specify RR attribute default values | ||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||
| 79 | 1 | my $self = shift; | |||||||||||
| 80 | |||||||||||||
| 81 | 1 | $self->{version} = 0; | |||||||||||
| 82 | 1 | $self->size(1); | |||||||||||
| 83 | 1 | $self->hp(10000); | |||||||||||
| 84 | 1 | $self->vp(10); | |||||||||||
| 85 | 1 | return; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 8 | ▶ | sub latitude { | ||||||||||
|
Subroutine
latitude: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 90 | 8 | my ( $self, @value ) = @_; | |||||||||||
| 91 | 8 | ▶ | $self->{latitude} = _encode_angle(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 8 | ▶ | return _decode_angle( $self->{latitude} || return, 'N', 'S' ); | ||||||||||
|
Condition100%2/2
$self->{'latitude'} || (return)
MC/DC100%1/1
$self->{'latitude'} || (return)
$self->{'latitude'}
Truth table100%2/2
A
A= $self->{'latitude'}
| |||||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | 8 | ▶ | sub longitude { | ||||||||||
|
Subroutine
longitude: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 97 | 8 | my ( $self, @value ) = @_; | |||||||||||
| 98 | 8 | ▶ | $self->{longitude} = _encode_angle(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 8 | ▶ | return _decode_angle( $self->{longitude} || return, 'E', 'W' ); | ||||||||||
|
Condition100%2/2
$self->{'longitude'} || (return)
MC/DC100%1/1
$self->{'longitude'} || (return)
$self->{'longitude'}
Truth table100%2/2
A
A= $self->{'longitude'}
| |||||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 6 | ▶ | sub altitude { | ||||||||||
|
Subroutine
altitude: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 104 | 6 | my ( $self, @value ) = @_; | |||||||||||
| 105 | 6 | ▶ | $self->{altitude} = _encode_alt(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 6 | return _decode_alt( $self->{altitude} ); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | |||||||||||||
| 110 | 7 | ▶ | sub size { | ||||||||||
|
Subroutine
size: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 111 | 7 | my ( $self, @value ) = @_; | |||||||||||
| 112 | 7 | ▶ | $self->{size} = _encode_prec(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 113 | 7 | return _decode_prec( $self->{size} ); | |||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | |||||||||||||
| 117 | 9 | ▶ | sub hp { | ||||||||||
|
Subroutine
hp: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 118 | 9 | my ( $self, @value ) = @_; | |||||||||||
| 119 | 9 | ▶ | $self->{hp} = _encode_prec(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 9 | return _decode_prec( $self->{hp} ); | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | 2 | ▶ | sub horiz_pre { return &hp; } # uncoverable pod | ||||||||||
|
Subroutine
horiz_pre: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||
| 124 | |||||||||||||
| 125 | |||||||||||||
| 126 | 9 | ▶ | sub vp { | ||||||||||
|
Subroutine
vp: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 127 | 9 | my ( $self, @value ) = @_; | |||||||||||
| 128 | 9 | ▶ | $self->{vp} = _encode_prec(@value) if scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 129 | 9 | return _decode_prec( $self->{vp} ); | |||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | 2 | ▶ | sub vert_pre { return &vp; } # uncoverable pod | ||||||||||
|
Subroutine
vert_pre: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||
| 133 | |||||||||||||
| 134 | |||||||||||||
| 135 | 2 | ▶ | sub latlon { | ||||||||||
|
Subroutine
latlon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 136 | 2 | my ( $self, @argument ) = @_; | |||||||||||
| 137 | 2 | my @lat = @argument; | |||||||||||
| 138 | 2 | my ( undef, @long ) = @argument; | |||||||||||
| 139 | 2 | return ( scalar $self->latitude(@lat), scalar $self->longitude(@long) ); | |||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | |||||||||||||
| 143 | 2 | ▶ | sub version { | ||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 144 | 2 | return shift->{version}; | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | |||||||||||||
| 148 | ######################################## | ||||||||||||
| 149 | |||||||||||||
| 150 | 1 | ▶ | no integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 151 | |||||||||||||
| 152 | 1 | ▶ | use constant ALTITUDE0 => 10000000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 153 | 1 | ▶ | use constant ORDINATE0 => 0x80000000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 154 | |||||||||||||
| 155 | 14 | ▶ | sub _decode_angle { | ||||||||||
|
Subroutine
_decode_angle: called CC=3 SCAR=11.0
| |||||||||||||
| 156 | 14 | my ( $msec, $N, $S ) = @_; | |||||||||||
| 157 | 14 | ▶ | return int( 0.5 + ( $msec - ORDINATE0 ) / 0.36 ) / 10000000 unless wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 158 | 1 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 159 | 4 | my $abs = abs( $msec - ORDINATE0 ); | |||||||||||
| 160 | 4 | my $deg = int( $abs / 3600000 ); | |||||||||||
| 161 | 4 | my $min = int( $abs / 60000 ) % 60; | |||||||||||
| 162 | 1 | ▶ | no integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 163 | 4 | my $sec = ( $abs % 60000 ) / 1000; | |||||||||||
| 164 | 4 | ▶ | return ( $deg, $min, $sec, ( $msec < ORDINATE0 ? $S : $N ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 165 | } | ||||||||||||
| 166 | |||||||||||||
| 167 | |||||||||||||
| 168 | 4 | ▶ | sub _encode_angle { | ||||||||||
|
Subroutine
_encode_angle: called CC=6 SCAR=17.9
| |||||||||||||
| 169 | 4 | my @ang = @_; | |||||||||||
| 170 | 4 | ▶ | @ang = split /[\s\260'"]+/, shift @ang unless scalar @ang > 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 171 | 4 | my $ang = ( 0 + shift @ang ) * 3600000; | |||||||||||
| 172 | 4 | ▶ | my $neg = ( @ang ? pop @ang : '' ) =~ /[SWsw]/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 173 | 4 | ▶ | $ang += ( @ang ? shift @ang : 0 ) * 60000; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 174 | 4 | ▶ | $ang += ( @ang ? shift @ang : 0 ) * 1000; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 175 | 4 | ▶ | return int( 0.5 + ( $neg ? ORDINATE0 - $ang : ORDINATE0 + $ang ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 176 | } | ||||||||||||
| 177 | |||||||||||||
| 178 | |||||||||||||
| 179 | 6 | ▶ | sub _decode_alt { | ||||||||||
|
Subroutine
_decode_alt: called CC=2 SCAR=6.9
| |||||||||||||
| 180 | 6 | ▶ | my $cm = ( shift || ALTITUDE0 ) - ALTITUDE0; | ||||||||||
|
Condition100%2/2
shift() || 10000000
MC/DC100%1/1
shift() || 10000000
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 181 | 6 | return 0.01 * $cm; | |||||||||||
| 182 | } | ||||||||||||
| 183 | |||||||||||||
| 184 | |||||||||||||
| 185 | 2 | ▶ | sub _encode_alt { | ||||||||||
|
Subroutine
_encode_alt: called CC=1 SCAR=0.0
| |||||||||||||
| 186 | 2 | ( my $argument = shift ) =~ s/[Mm]$//; | |||||||||||
| 187 | 2 | $argument += 0; | |||||||||||
| 188 | 2 | return int( 0.5 + ALTITUDE0 + 100 * $argument ); | |||||||||||
| 189 | } | ||||||||||||
| 190 | |||||||||||||
| 191 | |||||||||||||
| 192 | 1 | my @power10 = ( 0.01, 0.1, 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 0, 0, 0, 0, 0 ); | |||||||||||
| 193 | |||||||||||||
| 194 | 25 | ▶ | sub _decode_prec { | ||||||||||
|
Subroutine
_decode_prec: called CC=2 SCAR=6.9
| |||||||||||||
| 195 | 25 | ▶ | my $argument = shift || 0; | ||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 196 | 25 | my $mantissa = $argument >> 4; | |||||||||||
| 197 | 25 | return $mantissa * $power10[$argument & 0x0F]; | |||||||||||
| 198 | } | ||||||||||||
| 199 | |||||||||||||
| 200 | 8 | ▶ | sub _encode_prec { | ||||||||||
|
Subroutine
_encode_prec: called CC=2 SCAR=6.9
| |||||||||||||
| 201 | 8 | ( my $argument = shift ) =~ s/[Mm]$//; | |||||||||||
| 202 | 8 | my $exponent = 0; | |||||||||||
| 203 | 8 | ▶ | until ( $argument < $power10[1 + $exponent] ) { $exponent++ } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 204 | 8 | my $mantissa = int( 0.5 + $argument / $power10[$exponent] ); | |||||||||||
| 205 | 8 | return ( $mantissa & 0xF ) << 4 | $exponent; | |||||||||||
| 206 | } | ||||||||||||
| 207 | |||||||||||||
| 208 | ######################################## | ||||||||||||
| 209 | |||||||||||||
| 210 | |||||||||||||
| 211 | 1 | 1; | |||||||||||
| 212 | __END__ | ||||||||||||