line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::MelbourneBikeShare::Terminal; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @ATTRIBUTES = qw(coordinates featurename id nbbikes nbemptydoc uploaddate |
7
|
|
|
|
|
|
|
terminalname); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %ATTRIBUTES = ( |
10
|
|
|
|
|
|
|
coordinates => 'coordinates', |
11
|
|
|
|
|
|
|
id => 'id', |
12
|
|
|
|
|
|
|
featurename => 'name', |
13
|
|
|
|
|
|
|
nbbikes => 'bikes', |
14
|
|
|
|
|
|
|
nbemptydoc => 'empty', |
15
|
|
|
|
|
|
|
terminalname => 'terminal', |
16
|
|
|
|
|
|
|
uploaddate => 'update' |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
1
|
|
|
1
|
|
3
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
290
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
foreach my $attr ( keys %ATTRIBUTES ) { |
23
|
|
|
|
|
|
|
*{ __PACKAGE__ . "::$ATTRIBUTES{ $attr }" } = sub { |
24
|
0
|
|
|
0
|
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
return $self->{ $ATTRIBUTES{ $attr } } |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
0
|
|
|
0
|
0
|
|
my ( $class, $d ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
map { $self->{ $ATTRIBUTES{ $_ } } = $d->{ $_ } } keys %ATTRIBUTES; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return $self |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
|
sub lat { $_[0]->__point( 1 ) } |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
1
|
|
sub lon { $_[0]->__point( 0 ) } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub distance { |
46
|
0
|
|
|
0
|
1
|
|
my ( $self, $lat, $lon ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
return unless $lat and $lon; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $self->__haversine( $lat, $lon ) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
|
|
sub __point { return $_[0]->{ coordinates }->{ coordinates }->[ $_[1] ] } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub __asin { |
56
|
0
|
|
|
0
|
|
|
my $x = shift; |
57
|
0
|
|
|
|
|
|
atan2( $x, sqrt( 1 - $x * $x ) ) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub __haversine { |
61
|
0
|
|
|
0
|
|
|
my( $self, $lat, $lon ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $tlon = $lon; |
64
|
0
|
|
|
|
|
|
my $radius = 6372.8; |
65
|
0
|
|
|
|
|
|
my $radians = ( 22 / 7 ) / 180; |
66
|
0
|
|
|
|
|
|
my $dlat = ( $self->lat - $lat ) * $radians; |
67
|
0
|
|
|
|
|
|
my $dlon = ( $self->lon - $lon ) * $radians; |
68
|
0
|
|
|
|
|
|
my $a = sin( $dlat / 2 )** 2 |
69
|
|
|
|
|
|
|
+ cos( $self->lat * $radians ) |
70
|
|
|
|
|
|
|
* cos( $lat * $radians ) |
71
|
|
|
|
|
|
|
* sin( $dlon / 2 )**2; |
72
|
0
|
|
|
|
|
|
my $c = 2 * __asin( sqrt( $a ) ); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $radius * $c; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |