line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Formatter; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
361498
|
use warnings; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
177
|
|
4
|
6
|
|
|
6
|
|
32
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
166
|
|
5
|
6
|
|
|
6
|
|
29
|
use Carp; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
480
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
11179
|
use version; our $VERSION = qv('0.0.1'); |
|
6
|
|
|
|
|
13739
|
|
|
6
|
|
|
|
|
34
|
|
8
|
6
|
|
|
6
|
|
6881
|
use vars qw(@ISA @EXPORT); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
288
|
|
9
|
6
|
|
|
6
|
|
33
|
use Exporter; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
378
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
@EXPORT = qw(latlng2format format2latlng alias_format); |
12
|
6
|
|
|
6
|
|
6702
|
use Class::Inspector; |
|
6
|
|
|
|
|
26313
|
|
|
6
|
|
|
|
|
218
|
|
13
|
6
|
|
|
6
|
|
11520
|
use UNIVERSAL::require; |
|
6
|
|
|
|
|
10568
|
|
|
6
|
|
|
|
|
71
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %logic = (); |
16
|
|
|
|
|
|
|
# our @search = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
6
|
|
|
6
|
|
55
|
my $pkg = shift; |
20
|
6
|
|
|
|
|
13
|
my @formats = @_; |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
24
|
$pkg->add_format("Degree","DMS",@_); |
23
|
6
|
|
|
|
|
10549
|
$pkg->export_to_level(1, $pkg); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub add_format { |
27
|
6
|
|
|
6
|
1
|
13
|
my $pkg = shift; |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
16
|
foreach my $format (@_) { |
30
|
12
|
|
|
|
|
30
|
my $class = "Geo::Formatter::Format::$format"; |
31
|
|
|
|
|
|
|
|
32
|
12
|
50
|
|
|
|
92
|
unless( Class::Inspector->loaded($class) ) { |
33
|
12
|
50
|
|
|
|
977
|
if ($class->require) { |
34
|
12
|
|
|
|
|
200
|
$class->import; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
0
|
croak "Cannot load format : $format"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub __formatter { |
43
|
27
|
|
|
27
|
|
57
|
my $dir = shift; |
44
|
27
|
|
|
|
|
47
|
my $format = shift; |
45
|
|
|
|
|
|
|
|
46
|
27
|
|
|
|
|
54
|
my $code; |
47
|
|
|
|
|
|
|
|
48
|
27
|
50
|
33
|
|
|
255
|
if ($logic{$format} && $logic{$format}->{$dir}) { |
49
|
27
|
|
|
|
|
71
|
$code = $logic{$format}->{$dir}; |
50
|
|
|
|
|
|
|
}# else { |
51
|
|
|
|
|
|
|
# foreach my $search (@search) { |
52
|
|
|
|
|
|
|
# last if ($code = $search->match($format,$dir)); |
53
|
|
|
|
|
|
|
# } |
54
|
|
|
|
|
|
|
# } |
55
|
27
|
50
|
|
|
|
71
|
if ($code) { |
56
|
27
|
|
|
|
|
99
|
return $code->(@_); |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
0
|
croak "Cannot $dir $format format"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub latlng2format { |
63
|
13
|
|
|
13
|
1
|
48702
|
__formatter("encode",@_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub format2latlng { |
67
|
14
|
|
|
14
|
1
|
48383
|
__formatter("decode",@_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub alias_format { |
71
|
4
|
|
|
4
|
1
|
3005
|
my $format = shift; |
72
|
4
|
|
|
|
|
6
|
my $base = shift; |
73
|
4
|
|
|
|
|
6
|
my $opt = shift; |
74
|
|
|
|
|
|
|
|
75
|
4
|
50
|
|
|
|
13
|
my $base_setting = $logic{$base} or croak("Cannot find base format: $base"); |
76
|
4
|
50
|
|
|
|
26
|
$logic{$format} = {} unless ($logic{$format}); |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
8
|
foreach my $dir ("encode","decode") { |
79
|
8
|
|
|
|
|
32
|
my %dir_opt = $opt ? |
80
|
|
|
|
|
|
|
( |
81
|
4
|
|
|
|
|
12
|
%{$opt}, |
82
|
8
|
100
|
|
|
|
18
|
($opt->{$dir} ? %{$opt->{$dir}} : ()), |
|
|
50
|
|
|
|
|
|
83
|
|
|
|
|
|
|
) : |
84
|
|
|
|
|
|
|
(); |
85
|
8
|
|
|
|
|
18
|
delete @dir_opt{qw(decode encode)}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $code = $base_setting->{$dir} ? |
88
|
|
|
|
|
|
|
%dir_opt ? |
89
|
|
|
|
|
|
|
sub { |
90
|
7
|
50
|
|
7
|
|
28
|
my %opt = ref($_[$#_]) eq 'HASH' ? %{ pop() } : (); |
|
7
|
|
|
|
|
21
|
|
91
|
7
|
|
|
|
|
37
|
%opt = ( |
92
|
|
|
|
|
|
|
%dir_opt, |
93
|
|
|
|
|
|
|
%opt, |
94
|
|
|
|
|
|
|
); |
95
|
7
|
|
|
|
|
38
|
$base_setting->{$dir}->(@_,\%opt); |
96
|
|
|
|
|
|
|
} : |
97
|
8
|
100
|
|
|
|
36
|
$base_setting->{$dir} : |
|
|
50
|
|
|
|
|
|
98
|
|
|
|
|
|
|
undef; |
99
|
|
|
|
|
|
|
|
100
|
8
|
|
|
|
|
29
|
$logic{$format}->{$dir} = $code; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
105
|
|
|
|
|
|
|
__END__ |