1package Net::DNS::RR::GPOS;
2
3use strict;
4use warnings;
5our $VERSION = (qw$Id: GPOS.pm 1814 2020-10-14 21:49:16Z willem $)[2];
6
7use base qw(Net::DNS::RR);
8
9
10=head1 NAME
11
12Net::DNS::RR::GPOS - DNS GPOS resource record
13
14=cut
15
16use integer;
17
18use Carp;
19use Net::DNS::Text;
20
21
22sub _decode_rdata {			## decode rdata from wire-format octet string
23	my $self = shift;
24	my ( $data, $offset ) = @_;
25
26	my $limit = $offset + $self->{rdlength};
27	( $self->{latitude},  $offset ) = Net::DNS::Text->decode( $data, $offset ) if $offset < $limit;
28	( $self->{longitude}, $offset ) = Net::DNS::Text->decode( $data, $offset ) if $offset < $limit;
29	( $self->{altitude},  $offset ) = Net::DNS::Text->decode( $data, $offset ) if $offset < $limit;
30	croak('corrupt GPOS data') unless $offset == $limit;	# more or less FUBAR
31	return;
32}
33
34
35sub _encode_rdata {			## encode rdata as wire-format octet string
36	my $self = shift;
37
38	return '' unless defined $self->{altitude};
39	return join '', map { $self->{$_}->encode } qw(latitude longitude altitude);
40}
41
42
43sub _format_rdata {			## format rdata portion of RR string.
44	my $self = shift;
45
46	return '' unless defined $self->{altitude};
47	return join ' ', map { $self->{$_}->string } qw(latitude longitude altitude);
48}
49
50
51sub _parse_rdata {			## populate RR from rdata in argument list
52	my $self = shift;
53
54	$self->latitude(shift);
55	$self->longitude(shift);
56	$self->altitude(shift);
57	die 'too many arguments for GPOS' if scalar @_;
58	return;
59}
60
61
62sub _defaults {				## specify RR attribute default values
63	my $self = shift;
64
65	$self->_parse_rdata(qw(0.0 0.0 0.0));
66	return;
67}
68
69
70sub latitude {
71	my $self = shift;
72	$self->{latitude} = _fp2text(shift) if scalar @_;
73	return defined(wantarray) ? _text2fp( $self->{latitude} ) : undef;
74}
75
76
77sub longitude {
78	my $self = shift;
79	$self->{longitude} = _fp2text(shift) if scalar @_;
80	return defined(wantarray) ? _text2fp( $self->{longitude} ) : undef;
81}
82
83
84sub altitude {
85	my $self = shift;
86	$self->{altitude} = _fp2text(shift) if scalar @_;
87	return defined(wantarray) ? _text2fp( $self->{altitude} ) : undef;
88}
89
90
91########################################
92
93sub _fp2text {
94	return Net::DNS::Text->new( sprintf( '%1.10g', shift ) );
95}
96
97sub _text2fp {
98	no integer;
99	return ( 0.0 + shift->value );
100}
101
102
1031;
104__END__
105
106
107=head1 SYNOPSIS
108
109    use Net::DNS;
110    $rr = Net::DNS::RR->new('name GPOS latitude longitude altitude');
111
112=head1 DESCRIPTION
113
114Class for DNS Geographical Position (GPOS) resource records.
115
116=head1 METHODS
117
118The available methods are those inherited from the base class augmented
119by the type-specific methods defined in this package.
120
121Use of undocumented package features or direct access to internal data
122structures is discouraged and could result in program termination or
123other unpredictable behaviour.
124
125
126=head2 latitude
127
128    $latitude = $rr->latitude;
129    $rr->latitude( $latitude );
130
131Floating-point representation of latitude, in degrees.
132
133=head2 longitude
134
135    $longitude = $rr->longitude;
136    $rr->longitude( $longitude );
137
138Floating-point representation of longitude, in degrees.
139
140=head2 altitude
141
142    $altitude = $rr->altitude;
143    $rr->altitude( $altitude );
144
145Floating-point representation of altitude, in metres.
146
147
148=head1 COPYRIGHT
149
150Copyright (c)1997,1998 Michael Fuhr.
151
152All rights reserved.
153
154Package template (c)2009,2012 O.M.Kolkman and R.W.Franks.
155
156
157=head1 LICENSE
158
159Permission to use, copy, modify, and distribute this software and its
160documentation for any purpose and without fee is hereby granted, provided
161that the above copyright notice appear in all copies and that both that
162copyright notice and this permission notice appear in supporting
163documentation, and that the name of the author not be used in advertising
164or publicity pertaining to distribution of the software without specific
165prior written permission.
166
167THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
170THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
171LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
172FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
173DEALINGS IN THE SOFTWARE.
174
175
176=head1 SEE ALSO
177
178L<perl>, L<Net::DNS>, L<Net::DNS::RR>, RFC1712
179
180=cut
181