DNS/RR/LOC.pm

filter: Statementstmt 100% 126 / 126 Branchbran 94.4% 34 / 36 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 31 / 31 Podpod 100% 8 / 10 (2 uncoverable) totaltotal 99.0% 211 / 215 (2 uncoverable) CC 25 SCAR 10.0
CC
25
Cov
99%
_parse_rdata
6.0
_encode_angle
6.0
latitude
3.0
CRAP 2.7
« DNS/RR/MR.pm ↑ Summary DNS/Header.pm »
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
BranchTrueFalseTotal
if (scalar @argument) 4 0 4
56 4 my $this = shift @argument;
57 4 push( @lat, $this );
58 4 ▶ last if $this =~ /[NSns]/;
Branch: 1 branch
BranchTrueFalseTotal
if $this =~ /[NSns]/ 1 3 4
59 }
60 1 $self->latitude(@lat);
61  
62 1 my @long;
63 1 ▶ while ( scalar @argument ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @argument) 4 0 4
64 4 my $this = shift @argument;
65 4 push( @long, $this );
66 4 ▶ last if $this =~ /[EWew]/;
Branch: 1 branch
BranchTrueFalseTotal
if $this =~ /[EWew]/ 1 3 4
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
BranchTrueFalseTotal
if scalar @value 2 6 8
92 8 ▶ return _decode_angle( $self->{latitude} || return, 'N', 'S' );
Condition100%2/2
$self->{'latitude'} || (return)
l!l
71
MC/DC100%1/1
$self->{'latitude'} || (return)
$self->{'latitude'}
Truth table100%2/2
A
A= $self->{'latitude'}
Aresult
11
00
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
BranchTrueFalseTotal
if scalar @value 2 6 8
99 8 ▶ return _decode_angle( $self->{longitude} || return, 'E', 'W' );
Condition100%2/2
$self->{'longitude'} || (return)
l!l
71
MC/DC100%1/1
$self->{'longitude'} || (return)
$self->{'longitude'}
Truth table100%2/2
A
A= $self->{'longitude'}
Aresult
11
00
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
BranchTrueFalseTotal
if scalar @value 2 4 6
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
BranchTrueFalseTotal
if scalar @value 3 4 7
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
BranchTrueFalseTotal
if scalar @value 3 6 9
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
BranchTrueFalseTotal
if scalar @value 2 7 9
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
BranchTrueFalseTotal
unless wantarray 10 4 14
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
BranchTrueFalseTotal
$msec < 2147483648 ? : 2 2 4
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
BranchTrueFalseTotal
unless scalar @ang > 1 2 2 4
171 4 my $ang = ( 0 + shift @ang ) * 3600000;
172 4 ▶ my $neg = ( @ang ? pop @ang : '' ) =~ /[SWsw]/;
Branch: 1 branch
BranchTrueFalseTotal
@ang ? : 2 2 4
173 4 ▶ $ang += ( @ang ? shift @ang : 0 ) * 60000;
Branch: 1 branch
BranchTrueFalseTotal
@ang ? : 2 2 4
174 4 ▶ $ang += ( @ang ? shift @ang : 0 ) * 1000;
Branch: 1 branch
BranchTrueFalseTotal
@ang ? : 2 2 4
175 4 ▶ return int( 0.5 + ( $neg ? ORDINATE0 - $ang : ORDINATE0 + $ang ) );
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 1 3 4
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
l!l
51
MC/DC100%1/1
shift() || 10000000
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
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
l!l
223
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
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
BranchTrueFalseTotal
unless ($argument < $power10[1 + $exponent]) 30 8 38
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__
« DNS/RR/MR.pm ↑ Summary DNS/Header.pm »