GeoIP2/Role/Model/Location.pm

filter: Statementstmt 100% 74 / 74 Branchbran n/a Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 19 / 19 Podpod n/a totaltotal 96.9% 95 / 98 CC 3 SCAR 1.8
CC
3
Cov
99%
_record_class_for_key
2.0
_define_attributes_for_keys
2.0
BEGIN
1.0
CRAP 1.2
« GeoIP2/Role/Record/HasNames.pm ↑ Summary GeoIP2/Role/Model/HasSubdivisions.pm »
1 package GeoIP2::Role::Model::Location;
2 6 $GeoIP2::Role::Model::Location::VERSION = '0.050000';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use GeoIP2::Record::City;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use GeoIP2::Record::Continent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use GeoIP2::Record::Country;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use GeoIP2::Record::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use GeoIP2::Record::MaxMind;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use GeoIP2::Record::Postal;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use GeoIP2::Record::RepresentedCountry;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use GeoIP2::Record::Traits;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use GeoIP2::Types qw( ArrayRef HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Sub::Quote qw( quote_sub );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 with 'GeoIP2::Role::Model', 'GeoIP2::Role::HasLocales';
21  
22 sub _define_attributes_for_keys {
23 10 ▶ my $class = shift;
Subroutine _define_attributes_for_keys: called CC=2 SCAR=6.9
24 10 my @keys = @_;
25  
26 10 my $has = $class->can('has');
27  
28 10 for my $key (@keys) {
29 74 my $record_class = __PACKAGE__->_record_class_for_key($key);
30  
31 74 my $raw_attr = '_raw_' . $key;
32  
33 74 $has->(
34 $raw_attr => (
35 is => 'ro',
36 isa => HashRef,
37 init_arg => $key,
38 default => quote_sub(q{ {} }),
39 ),
40 );
41  
42 $has->(
43 $key => (
44 is => 'ro',
45 isa => quote_sub(
46 sprintf(
47 q{ GeoIP2::Types::object_isa_type( $_[0], %s ) },
48 B::perlstring($record_class)
49 )
50 ),
51 init_arg => undef,
52 lazy => 1,
53 default => quote_sub(
54 sprintf(
55 q{ $_[0]->_build_record( %s, %s ) },
56 74 map { B::perlstring($_) } $key, $raw_attr
57 )
58 )
59 )
60 );
61 }
62 }
63  
64 sub _all_record_names {
65 6 ▶ return qw(
Subroutine _all_record_names: called CC=1 SCAR=0.0
66 city
67 continent
68 country
69 location
70 maxmind
71 postal
72 registered_country
73 represented_country
74 traits
75 );
76 }
77  
78 around BUILDARGS => sub {
79 17 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
80 17 my $self = shift;
81  
82 17 my $p = $self->$orig(@_);
83  
84 17 delete $p->{raw};
85  
86 # We make a copy to avoid a circular reference
87 17 $p->{raw} = { %{$p} };
88  
89 17 return $p;
90 6 };
91  
92 sub _build_record {
93 64 ▶ my $self = shift;
Subroutine _build_record: called CC=1 SCAR=0.0
94 64 my $key = shift;
95 64 my $method = shift;
96  
97 64 my $raw = $self->$method();
98  
99 return $self->_record_class_for_key($key)
100 64 ->new( %{$raw}, locales => $self->locales() );
101 }
102  
103 {
104 6 my %key_to_class = (
105 maxmind => 'MaxMind',
106 registered_country => 'Country',
107 represented_country => 'RepresentedCountry',
108 );
109  
110 sub _record_class_for_key {
111 138 ▶ my $self = shift;
Subroutine _record_class_for_key: called CC=2 SCAR=7.0
112 138 my $key = shift;
113  
114 138 ▶ return 'GeoIP2::Record::' . ( $key_to_class{$key} || ucfirst $key );
Condition66%2/3
$key_to_class{$key} || ucfirst $key
l!l&&r!l&&!r
45930
MC/DC0%0/2
$key_to_class{$key} || ucfirst $key
$key_to_class{$key} ucfirst $key
Truth table66%2/3
A || B
A= $key_to_class{$key}B= ucfirst $key
ABresult
1X1
011
000
115 }
116 }
117  
118 6 1;
« GeoIP2/Role/Record/HasNames.pm ↑ Summary GeoIP2/Role/Model/HasSubdivisions.pm »