line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::OSM::MapFeatures::Feature::Value; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use base qw( Class::Factory Class::Accessor ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
273012
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(value)); |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4287
|
use overload '""' => \&stringify, '<=>' => \&compare, 'cmp' => \&compare; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Geo::OSM::MapFeatures::Feature::Value - Represents a feature value |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This module represents a value on a feature from map features. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
To handle all the special value types this class is a factory and returns |
31
|
|
|
|
|
|
|
a subclass of itself if the value is special. Normal static strings are |
32
|
|
|
|
|
|
|
handled in this module. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( userdef => "Geo::OSM::MapFeatures::Feature::Value::Userdef" ); |
37
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( num => "Geo::OSM::MapFeatures::Feature::Value::Num" ); |
38
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( range => "Geo::OSM::MapFeatures::Feature::Value::Range" ); |
39
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( date => "Geo::OSM::MapFeatures::Feature::Value::Date" ); |
40
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( time => "Geo::OSM::MapFeatures::Feature::Value::Time" ); |
41
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( list => "Geo::OSM::MapFeatures::Feature::Value::List" ); |
42
|
|
|
|
|
|
|
__PACKAGE__->add_factory_type( numwithunit => "Geo::OSM::MapFeatures::Feature::Value::NumWithUnit" ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 FUNCTIONS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 value |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This always contains the value as it was on map features (except any |
49
|
|
|
|
|
|
|
wiki syntax) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
0
|
|
|
0
|
1
|
|
my $pkg = shift; |
55
|
0
|
|
|
|
|
|
my $value = shift(); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
0
|
|
|
|
my $class = ref($pkg) || $pkg; |
58
|
0
|
|
|
|
|
|
my %classargs; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Arbitrarily defined value |
61
|
0
|
0
|
0
|
|
|
|
if( $value =~ /user defined|defined by editor/i || $value =~ /^\s*\.\.\.\s*$/ ){ |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#FIXME: Maybe defined by editor should be separate? |
63
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('userdef'); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
# Empty value - what the heck? |
66
|
|
|
|
|
|
|
elsif( $value eq '' ){ |
67
|
0
|
|
|
|
|
|
Carp::carp "Empty value, what the heck? Calling it user defined"; |
68
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('userdef'); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
# Numeric value |
71
|
|
|
|
|
|
|
elsif( lc($value) eq 'num' || lc($value) eq 'number' ){ |
72
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('num'); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
# Range value |
75
|
|
|
|
|
|
|
elsif( $value =~ /^(-?\d+)\s+to\s+(-?\d+)$/i ){ |
76
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('range'); |
77
|
0
|
|
|
|
|
|
%classargs = (from => $1, to => $2); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
# Date value |
80
|
|
|
|
|
|
|
elsif( lc($value) eq 'date' ){ |
81
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('date') |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
# Day of week |
84
|
|
|
|
|
|
|
elsif( lc($value) eq 'day of week' ){ |
85
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('list'); |
86
|
0
|
|
|
|
|
|
%classargs = ( |
87
|
|
|
|
|
|
|
list => [ |
88
|
|
|
|
|
|
|
'monday', 'mon', |
89
|
|
|
|
|
|
|
'tuesday', 'tue', |
90
|
|
|
|
|
|
|
'wednesday', 'wed', |
91
|
|
|
|
|
|
|
'thursday', 'thu', |
92
|
|
|
|
|
|
|
'friday', 'fri', |
93
|
|
|
|
|
|
|
'saturday', 'sat', |
94
|
|
|
|
|
|
|
'sunday', 'sun' |
95
|
|
|
|
|
|
|
]); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
# Time value |
98
|
|
|
|
|
|
|
elsif( lc($value) eq 'time' ){ |
99
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('time'); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
# Speed |
102
|
|
|
|
|
|
|
elsif( lc($value) eq 'speed' ){ |
103
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('numwithunit'); |
104
|
0
|
|
|
|
|
|
%classargs = ( |
105
|
|
|
|
|
|
|
units => [ |
106
|
|
|
|
|
|
|
'kph', 'km/h', |
107
|
|
|
|
|
|
|
'mph', 'knots' |
108
|
|
|
|
|
|
|
] |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
# Lengths |
112
|
|
|
|
|
|
|
elsif( lc($value) eq 'length' || lc($value) eq 'height' || lc($value) eq 'width' ){ |
113
|
0
|
|
|
|
|
|
$class = $pkg->get_factory_class('numwithunit'); |
114
|
0
|
|
|
|
|
|
%classargs = ( |
115
|
|
|
|
|
|
|
units => [ |
116
|
|
|
|
|
|
|
'mm', 'cm', 'dm', 'm', 'km', |
117
|
|
|
|
|
|
|
'mil', # Scandinavian mil (10km) |
118
|
|
|
|
|
|
|
'inch', 'foot', 'yard', 'mile', |
119
|
|
|
|
|
|
|
'nm', # Nautical mile |
120
|
|
|
|
|
|
|
'furlong' |
121
|
|
|
|
|
|
|
] |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $self = bless( {value => $value}, $class); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return $self->init($value, \%classargs, @_); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Inheriting classes need to override this method if they get arguments |
131
|
|
|
|
|
|
|
sub init { |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
confess "BUG: Subclass with arguments haven't overriden init. classargs=$_[1]" |
135
|
0
|
0
|
|
|
|
|
if %{$_[1]}; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $self; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub stringify { |
141
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $self->value(); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Comparison operator |
147
|
|
|
|
|
|
|
sub compare { |
148
|
0
|
|
|
0
|
0
|
|
my ($s1, $s2, $inverted) = @_; |
149
|
0
|
0
|
|
|
|
|
return $inverted ? "$s2" cmp "$s1" : "$s1" cmp "$s2"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Knut Arne Bjørndal, C<< >> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 BUGS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
159
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
160
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SUPPORT |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
perldoc Geo::OSM::MapFeatures |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
You can also look for information at: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * CPAN Ratings |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * Search CPAN |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Copyright 2008-2009 Knut Arne Bjørndal, all rights reserved. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
203
|
|
|
|
|
|
|
under the same terms as Perl itself. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; # End of Geo::OSM::MapFeatures::Feature::Value |