line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Query; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22171
|
use 5.008003; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
314
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Geo::Query ':all'; |
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
17
|
|
|
|
|
|
|
# will save memory. |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
19
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
20
|
|
|
|
|
|
|
our @EXPORT = qw(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
##### FORWARD |
25
|
|
|
|
|
|
|
sub Debug($); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
##### GLOBAL |
28
|
|
|
|
|
|
|
my $package = __PACKAGE__; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
0
|
|
|
0
|
0
|
|
my $type = shift; |
32
|
0
|
|
|
|
|
|
my %params = @_; |
33
|
0
|
|
|
|
|
|
my $self = {}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
0
|
|
|
|
$self->{'debug' } = $params{'debug'} || 0; # 0, 1, 2 |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
Debug "$package V$VERSION" if $self->{'debug'}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
bless $self, $type; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub distance() { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my %args = @_; |
45
|
0
|
|
0
|
|
|
|
$args{'lat1'} ||= 0; |
46
|
0
|
|
0
|
|
|
|
$args{'lat2'} ||= 0; |
47
|
0
|
|
0
|
|
|
|
$args{'lng1'} ||= 0; |
48
|
0
|
|
0
|
|
|
|
$args{'lng2'} ||= 0; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
1592
|
use Math::Trig; |
|
1
|
|
|
|
|
21908
|
|
|
1
|
|
|
|
|
333
|
|
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my %hash = (); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $R = 6371; # -- km |
55
|
0
|
|
|
|
|
|
my $dLat = deg2rad(abs($args{'lat2'} - $args{'lat1'})); |
56
|
0
|
|
|
|
|
|
my $dLon = deg2rad(abs($args{'lng2'} - $args{'lng1'})); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $lat1 = deg2rad($args{'lat1'}); |
59
|
0
|
|
|
|
|
|
my $lat2 = deg2rad($args{'lat2'}); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $a = sin($dLat / 2) * sin($dLat / 2) + cos($lat1) * cos($lat2) * sin($dLon / 2) * sin($dLon / 2); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $c = 2 * atan2(sqrt(abs($a)), sqrt(1 - $a)); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $d = $R * $c; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$hash{'d'} = $c; # -- multiply with your own radius |
68
|
0
|
|
|
|
|
|
$hash{'km'} = sprintf('%.2f', $d); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
\%hash; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub info() { |
74
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
my %args = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my %info = (); |
78
|
0
|
|
|
|
|
|
$info{'version'} = $VERSION; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
1
|
|
802
|
use LWP::Simple; |
|
1
|
|
|
|
|
86824
|
|
|
1
|
|
|
|
|
9
|
|
81
|
0
|
|
|
|
|
|
my $module_list = get 'http://meta.pg'. |
82
|
|
|
|
|
|
|
'ate.net/wiki-reto/index.php?title=Perl_modules_geo-query&printable=yes'; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my @lines = split /\n/, $module_list; |
85
|
0
|
|
|
|
|
|
my $i = 0; |
86
|
0
|
0
|
|
|
|
|
foreach (@lines) { $i++; last if /BEGIN SECTION 101/; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
for ($i = $i + 1; $i < $#lines + 1; $i++) { |
89
|
0
|
|
|
|
|
|
chomp $lines[$i]; |
90
|
0
|
0
|
|
|
|
|
last if $lines[$i] =~ /END SECTION 101/; |
91
|
0
|
0
|
|
|
|
|
$info{'modules'} .= $lines[$i] . "\n" if $lines[$i]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
\%info; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
0
|
|
sub Debug ($) { print "[ $package ] $_[0]\n"; } |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |