DDG/Location.pm

filter: Statementstmt 51.8% 14 / 27 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 1 totaltotal 32.0% 17 / 53 CC 9 SCAR 41.4
CC
9
Cov
33%
new_from_geo_ip_record
90.0
__ANON__
2.0
BEGIN
1.0
CRAP 62.7
↑ Summary DDG/Rewrite.pm »
1 package DDG::Location;
2 12 our $AUTHORITY = 'cpan:DDG';
3 # ABSTRACT: A location, can be empty (given by Geo::IP::Record)
4 12 $DDG::Location::VERSION = '1017';
5 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 my @geo_ip_record_attrs = qw( country_code country_code3 country_name region
8 region_name city postal_code latitude longitude time_zone area_code
9 continent_code metro_code );
10  
11 12 my @geo_ip_record_s = (@geo_ip_record_attrs, 'loc_str');
12  
13 sub new_from_geo_ip_record {
14 0 ▶ my ( $class, $geo_ip_record ) = @_;
Subroutine new_from_geo_ip_record: not called CC=9 SCAR=45.0
Pod undocumented
15  
16 0 ▶ if ($geo_ip_record) {
Branch: 1 branch
BranchTrueFalseTotal
if ($geo_ip_record) { } 0 0 0
17 0 my %args;
18 0 for (@geo_ip_record_attrs) {
19 0 ▶ $args{$_} = $geo_ip_record->$_ if defined $geo_ip_record->$_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $geo_ip_record->$_ 0 0 0
20 }
21  
22 # add short location summary string: postal_code if it exists, otherwise 'city, country' or 'region, country'
23 0 ▶ my $city = $geo_ip_record->city || $geo_ip_record->region_name;
Condition0%0/3
$geo_ip_record->city || $geo_ip_record->region_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$geo_ip_record->city || $geo_ip_record->region_name
$geo_ip_record->city $geo_ip_record->region_name
Truth table0%0/3
A || B
A= $geo_ip_record->cityB= $geo_ip_record->region_name
ABresult
1X1
011
000
24  
25 0 ▶ if ($city) {
Branch: 1 branch
BranchTrueFalseTotal
if ($city) 0 0 0
26 0 ▶ $city .= ', ' . $geo_ip_record->country_name if $geo_ip_record->country_name;
Branch: 1 branch
BranchTrueFalseTotal
if $geo_ip_record->country_name 0 0 0
27 }
28  
29 0 ▶ $args{loc_str} = $geo_ip_record->postal_code || $city || '';
Condition0%0/5
$geo_ip_record->postal_code || $city || ''
l!l
00
$geo_ip_record->postal_code or $city
l!l&&r!l&&!r
000
MC/DC0%0/2
$geo_ip_record->postal_code || $city || ''
$geo_ip_record->postal_code $city
Truth table0%0/3
A or B
A= $geo_ip_record->postal_codeB= $city
ABresult
1X1
011
000
30  
31 0 return $class->new(
32 geo_ip_record => $geo_ip_record,
33 %args,
34 );
35 } else {
36 0 return $class->new;
37 }
38 }
39  
40 has $_ => (
41 is => 'ro',
42 395 ▶ default => sub { '' }
Subroutine __ANON__: called CC=1 SCAR=0.0
43 12 ) for (@geo_ip_record_s);
44  
45 12 has geo_ip_record => (
46 is => 'ro',
47 predicate => 'has_geo_ip_record',
48 );
49  
50 use overload '""' => sub {
51 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 return $self->country_code;
53 12 ▶}, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 12 1;
56  
57 __END__
↑ Summary DDG/Rewrite.pm »