| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Geo::Cache; |
|
2
|
2
|
|
|
2
|
|
56714
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
89
|
|
|
3
|
2
|
|
|
2
|
|
1055
|
use XML::Simple; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Time::CTime qw(); |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Docs {{{ |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Geo::Cache - Object interface for GPS waypoints |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Geo::Cache; |
|
15
|
|
|
|
|
|
|
my $wpt = Geo::Cache->new( |
|
16
|
|
|
|
|
|
|
lat => '37.99815', |
|
17
|
|
|
|
|
|
|
lon => '-85.302017', |
|
18
|
|
|
|
|
|
|
time => $time, |
|
19
|
|
|
|
|
|
|
name => 'GCGVW8', |
|
20
|
|
|
|
|
|
|
desc => 'Neither Hill nor Dale', |
|
21
|
|
|
|
|
|
|
sym => 'geocache', |
|
22
|
|
|
|
|
|
|
type => 'Geocache|Traditional Cache', |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
$wpt->url('http://www.geocaching.com/'); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $wpt_from_xml = Geo::Cache->new( xml => $xml, ); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $xml = $wpt->xml; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Provide an object interface to Geocaching.com waypoints and/or |
|
34
|
|
|
|
|
|
|
geocaches, using the Groundspeak GPX file as the reference for what |
|
35
|
|
|
|
|
|
|
fields are valid. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Methods are provide for various of the fields that require special |
|
38
|
|
|
|
|
|
|
treatment. |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Three output methods are provided -- C, C, and C, |
|
41
|
|
|
|
|
|
|
for outputting a single waypoint in one of these three formats. These |
|
42
|
|
|
|
|
|
|
can be used in conjunction with the C module to produce files |
|
43
|
|
|
|
|
|
|
of those formats. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 AUTHOR |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Rich Bowen |
|
48
|
|
|
|
|
|
|
rbowen@rcbowen.com |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
53
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
56
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# }}} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use vars qw(@FIELDS $VERSION $AUTOLOAD $CACHEID); |
|
63
|
|
|
|
|
|
|
$VERSION = '0.22'; |
|
64
|
|
|
|
|
|
|
@FIELDS = qw(lat lon time name desc url urlname sym type); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# sub new {{{ |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 new |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Create a new C object. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $wpt = Geo::Cache->new( |
|
73
|
|
|
|
|
|
|
lat => '37.99815', |
|
74
|
|
|
|
|
|
|
lon => '-85.302017', |
|
75
|
|
|
|
|
|
|
time => $time, |
|
76
|
|
|
|
|
|
|
name => 'GCGVW8', |
|
77
|
|
|
|
|
|
|
desc => 'Neither Hill nor Dale', |
|
78
|
|
|
|
|
|
|
sym => 'geocache', |
|
79
|
|
|
|
|
|
|
type => 'Geocache|Traditional Cache', |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub new { |
|
85
|
|
|
|
|
|
|
my $class = shift; |
|
86
|
|
|
|
|
|
|
my %parameters = @_; |
|
87
|
|
|
|
|
|
|
my $self = {}; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Can create with a blob of XML? |
|
90
|
|
|
|
|
|
|
# if ( $parameters{xml} ) { |
|
91
|
|
|
|
|
|
|
# # do something useful |
|
92
|
|
|
|
|
|
|
# } else { |
|
93
|
|
|
|
|
|
|
my %valid = map {$_=>1} @FIELDS; |
|
94
|
|
|
|
|
|
|
foreach my $field ( keys %parameters ) { |
|
95
|
|
|
|
|
|
|
delete $parameters{$field} unless $valid{$field}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
$self = bless( \%parameters, ref($class) || $class ); |
|
98
|
|
|
|
|
|
|
# } |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return ($self); |
|
101
|
|
|
|
|
|
|
} # }}} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# AUTOLOADER {{{ |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 Data methods |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A data method is provided for each of the valid fields within a Cache |
|
108
|
|
|
|
|
|
|
object. Calling the method with no argument returns the value of that |
|
109
|
|
|
|
|
|
|
attribute. Calling the method with an argument changes the value of that |
|
110
|
|
|
|
|
|
|
attribute to that value. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $name = $cache->name; |
|
113
|
|
|
|
|
|
|
$cache->lon(-84.8934); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
118
|
|
|
|
|
|
|
my $self = shift; |
|
119
|
|
|
|
|
|
|
my $val = shift; |
|
120
|
|
|
|
|
|
|
my ( $method ); |
|
121
|
|
|
|
|
|
|
( $method = $AUTOLOAD ) =~ s/.*:://; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
if (defined $val) { |
|
124
|
|
|
|
|
|
|
$self->{$method} = $val; |
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
|
|
|
|
|
|
# Use the existing value |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return $self->{$method}; |
|
130
|
|
|
|
|
|
|
} # }}} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# sub xml {{{ |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 xml/gpx |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Returns a blob of XML which constitutes one block of a |
|
137
|
|
|
|
|
|
|
Geocaching.com-style gpx data file. You'll generally not use this |
|
138
|
|
|
|
|
|
|
method by itself, but will call the C method from the C |
|
139
|
|
|
|
|
|
|
module to generate the entire file of one or more waypoints. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
C is an alias for the C method. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub gpx { |
|
146
|
|
|
|
|
|
|
my $self = shift; |
|
147
|
|
|
|
|
|
|
my @fields = @FIELDS; |
|
148
|
|
|
|
|
|
|
shift @fields for (1..2); # lat and lon |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $ret = qq~\n~; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# It appears that time, url and urlname are required fields |
|
153
|
|
|
|
|
|
|
$self->{url} ||= 'http://drbacchus.com/'; |
|
154
|
|
|
|
|
|
|
$self->{urlname} ||= 'Geo::Cache'; |
|
155
|
|
|
|
|
|
|
# Time looks like 2004-06-11T17:34:28.3952500-07:00 |
|
156
|
|
|
|
|
|
|
$self->{time} ||= |
|
157
|
|
|
|
|
|
|
Time::CTime::strftime( '%Y-%m-%dT%T.0000000-07:00', localtime ); |
|
158
|
|
|
|
|
|
|
$self->{sym} ||= 'box'; |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
foreach my $x (@fields) { |
|
161
|
|
|
|
|
|
|
if ($self->{$x}) { |
|
162
|
|
|
|
|
|
|
$ret .= qq~<$x>$self->{$x}$x>\n~; |
|
163
|
|
|
|
|
|
|
} else { |
|
164
|
|
|
|
|
|
|
$ret .= "<$x />\n"; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Need to add a little more stuff in order for this to wind up |
|
169
|
|
|
|
|
|
|
# generating valid GPX files |
|
170
|
|
|
|
|
|
|
$CACHEID++; |
|
171
|
|
|
|
|
|
|
$ret .= '' . "\n"; |
|
172
|
|
|
|
|
|
|
$ret .= qq|$self->{name} |
|
173
|
|
|
|
|
|
|
Traditional Cache |
|
174
|
|
|
|
|
|
|
Regular |
|
175
|
|
|
|
|
|
|
1 |
|
176
|
|
|
|
|
|
|
1 |
|
177
|
|
|
|
|
|
|
United States |
|
178
|
|
|
|
|
|
|
Kentucky |
|
179
|
|
|
|
|
|
|
$self->{desc} |
|
180
|
|
|
|
|
|
|
Geo::Cache |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$ret .= "\n"; |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
return $ret; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub xml { |
|
194
|
|
|
|
|
|
|
my $self = shift; |
|
195
|
|
|
|
|
|
|
return $self->gpx; |
|
196
|
|
|
|
|
|
|
} # }}} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub loc { |
|
199
|
|
|
|
|
|
|
my $self = shift; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $ret = ''; |
|
202
|
|
|
|
|
|
|
$CACHEID++; |
|
203
|
|
|
|
|
|
|
$ret .= '
|
|
204
|
|
|
|
|
|
|
$self->{name} . ']]>' . "\n"; |
|
205
|
|
|
|
|
|
|
$ret .= qq~\n~; |
|
206
|
|
|
|
|
|
|
$ret .= "Geocache\n"; |
|
207
|
|
|
|
|
|
|
$ret .= qq~$self->{name}\n\n~; |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
return $ret; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub gpsdrive { |
|
213
|
|
|
|
|
|
|
my $self = shift; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $name = $self->{name}; |
|
216
|
|
|
|
|
|
|
$name =~ s/\W/_/g; |
|
217
|
|
|
|
|
|
|
$name =~ s/^_+//; |
|
218
|
|
|
|
|
|
|
$name =~ s/_{2,}/_/g; |
|
219
|
|
|
|
|
|
|
$name =~ s/^(.{15}).*/$1/; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $ret = |
|
222
|
|
|
|
|
|
|
$name . "\t" . $self->{lat} . "\t" . $self->{lon} . "\tGeocache\n"; |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
return $ret; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
|
228
|
|
|
|
|
|
|
|