blib/lib/Geo/Coder/Cache.pm

filter: Statementstmt 40.0% 16 / 40 Branchbran 0.0% 0 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 100% 2 / 2 totaltotal 35.9% 23 / 64 SCAR 25.2
CC
5
Cov
33%
geocode
20.0
new
6.0
__ANON__
2.0
CRAP 12.4
↑ Summary
1 package Geo::Coder::Cache;
2 4 ▶use base 'Cache::FileCache';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use vars qw($VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 $VERSION = '0.06';
8  
9 4 ▶our $HOME = $ENV{'HOME'} || $ENV{'LOGDIR'};
Condition33%1/3
$ENV{'HOME'} || $ENV{'LOGDIR'}
l!l&&r!l&&!r
400
MC/DC0%0/2
$ENV{'HOME'} || $ENV{'LOGDIR'}
$ENV{'HOME'} $ENV{'LOGDIR'}
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= $ENV{'LOGDIR'}
ABresult
1X1
011
000
10 4 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 ▶ my($class, %param) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
17 0 ▶ my $geocoder = delete $param{geocoder} or Carp::croak("Usage: new(geocoder => \$geocoder)");
Branch: 1 branch
BranchTrueFalseTotal
my $geocoder = delete $param{"geocoder"} or Carp::croak("Usage: new(geocoder => \$geocoder)") 0 0 0
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 ▶ my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2);
Subroutine AUTOLOAD: not called CC=1 SCAR=2.2
29  
30 # We create the function here so that it will not need to be
31 # autoloaded the next time.
32 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 *$method = sub {
34 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 $self->{'geocoder'}->$method(@_);
36 0 };
37 0 goto &$method;
38 }
39  
40 ▶sub DESTROY {} # avoid AUTOLOADing it
Subroutine DESTROY: not called CC=1 SCAR=0.0
41  
42 sub geocode {
43 0 ▶ my $self = shift;
Subroutine geocode: not called CC=4 SCAR=30.0
Pod documented
44 0 my %param;
45 0 ▶ if (@_ % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 0) { } 0 0 0
46 0 %param = @_;
47 } else {
48 0 $param{location} = shift;
49 }
50 0 ▶ if ($param{location}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"location"}) 0 0 0
51 0 my $location = $self->get($param{location});
52 0 ▶ if (defined($location)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $location) 0 0 0
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 4 1;
62 __END__
↑ Summary