GeoIP2/Role/Model/Location.pm

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