blib/lib/Mojolicious/Plugin/IP2Location.pm

filter: Statementstmt 50.0% 9 / 18 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 2 / 4 Podpod 100% 1 / 1 totaltotal 30.0% 12 / 40 CC 6 SCAR 33.5
CC
6
Cov
30%
__ANON__
42.0
register
2.0
BEGIN
1.0
CRAP 28.4
↑ Summary
1 package Mojolicious::Plugin::IP2Location;
2  
3 1 our $VERSION = '0.001002'; # VERSION
4  
5 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Geo::IP2Location::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 my %Province_Map = (
9 'Alberta' => 'AB',
10 'British Columbia' => 'BC',
11 'Manitoba' => 'MB',
12 'New Brunswick' => 'NB',
13 'Newfoundland and Labrador' => 'NL',
14 'Northwest Territories' => 'NT',
15 'Nova Scotia' => 'NS',
16 'Nunavut' => 'NU',
17 'Ontario' => 'ON',
18 'Prince Edward Island' => 'PE',
19 'Quebec' => 'QC',
20 'Saskatchewan' => 'SK',
21 'Yukon Territory' => 'YT',
22 );
23  
24 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod documented
25 0 my ($self, $app) = @_;
26  
27 0 state $geo_ip = Geo::IP2Location::Lite->open(
28 $app->config('ip2location')
29 );
30  
31 $app->helper(
32 0 ▶ geoip_region=> sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
33 0 my $c = shift;
34  
35 0 ▶ my $is_debug_ip
Condition0%0/3
$c->app->mode eq 'development' && $c->param('DEBUG_GEOIP')
!ll&&!rl&&r
000
MC/DC0%0/2
$c->app->mode eq 'development' && $c->param('DEBUG_GEOIP')
$c->app->mode eq 'development' $c->param('DEBUG_GEOIP')
Truth table0%0/3
A && B
A= $c->app->mode eq 'development'B= $c->param('DEBUG_GEOIP')
ABresult
0X0
100
111
36 = $c->app->mode eq 'development' && $c->param('DEBUG_GEOIP');
37  
38 0 ▶ return $c->session('gip_r')
Branch: 1 branch
BranchTrueFalseTotal
if not $is_debug_ip and length $c->session("gip_r") 0 0 0
Condition0%0/3
not $is_debug_ip and length $c->session("gip_r")
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_debug_ip and length $c->session("gip_r")
not $is_debug_ip length $c->session("gip_r")
Truth table0%0/3
not(A) and B
A= not $is_debug_ipB= length $c->session("gip_r")
ABresult
0X0
100
111
39 if not $is_debug_ip and length $c->session('gip_r');
40  
41 0 ▶ my $ip = $is_debug_ip
Branch: 1 branch
BranchTrueFalseTotal
$is_debug_ip ? : 0 0 0
42 ? $c->param('DEBUG_GEOIP') : $c->tx->remote_address;
43  
44 $c->session(
45 0 ▶ gip_r => $Province_Map{ $geo_ip->get_region( $ip ) } // '00'
Condition0%0/2
$Province_Map{$geo_ip->get_region($ip)} // "00"
l!l
00
MC/DC0%0/1
$Province_Map{$geo_ip->get_region($ip)} // "00"
$Province_Map{$geo_ip->get_region($ip)}
Truth table0%0/2
A
A= $Province_Map{$geo_ip->get_region($ip)}
Aresult
11
00
46 );
47 0 return $c->session('gip_r');
48 },
49 0 );
50 }
51  
52 1 1;
53  
54 __END__
↑ Summary