line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Cache; |
2
|
4
|
|
|
4
|
|
196657
|
use base 'Cache::FileCache'; |
|
4
|
|
|
|
|
31
|
|
|
4
|
|
|
|
|
1900
|
|
3
|
4
|
|
|
4
|
|
165734
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
113
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
22
|
use vars qw($VERSION $AUTOLOAD); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
976
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.07'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $HOME = $ENV{'HOME'} || $ENV{'LOGDIR'}; |
10
|
|
|
|
|
|
|
our %default_cache_args = ( |
11
|
|
|
|
|
|
|
'namespace' => 'geo-coder-cache', |
12
|
|
|
|
|
|
|
'cache_root' => "$HOME/.cache", |
13
|
|
|
|
|
|
|
'default_expires_in' => 86400); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
|
my($class, %param) = @_; |
17
|
0
|
0
|
|
|
|
|
my $geocoder = delete $param{geocoder} or Carp::croak("Usage: new(geocoder => \$geocoder)"); |
18
|
0
|
|
|
|
|
|
($default_cache_args{namespace} = 'geo-coder-cache-' . lc ref($geocoder)) =~ s{::}{-}g; |
19
|
0
|
|
|
|
|
|
my %cache_args = (%default_cache_args, %param); |
20
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(\%cache_args); |
21
|
0
|
|
|
|
|
|
$self->{geocoder} = $geocoder; |
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# delegate all other method calls the the cache object. |
26
|
|
|
|
|
|
|
sub AUTOLOAD |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
|
|
0
|
|
|
my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# We create the function here so that it will not need to be |
31
|
|
|
|
|
|
|
# autoloaded the next time. |
32
|
4
|
|
|
4
|
|
32
|
no strict 'refs'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
925
|
|
33
|
|
|
|
|
|
|
*$method = sub { |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
$self->{'geocoder'}->$method(@_); |
36
|
0
|
|
|
|
|
|
}; |
37
|
0
|
|
|
|
|
|
goto &$method; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
0
|
|
|
sub DESTROY {} # avoid AUTOLOADing it |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub geocode { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my %param; |
45
|
0
|
0
|
|
|
|
|
if (@_ % 2 == 0) { |
46
|
0
|
|
|
|
|
|
%param = @_; |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
$param{location} = shift; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
0
|
|
|
|
|
if ($param{location}) { |
51
|
0
|
|
|
|
|
|
my $location = $self->get($param{location}); |
52
|
0
|
0
|
|
|
|
|
if (defined($location)) { |
53
|
0
|
|
|
|
|
|
return $location; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
my $location = $self->{geocoder}->geocode(%param); |
57
|
0
|
|
|
|
|
|
$self->set($param{location}, $location); |
58
|
0
|
|
|
|
|
|
return $location; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |