Geography/Implementation.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 8 / 8 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Geography.pm ↑ Summary
1 package Catalyst::Plugin::Geography::Implementation;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw[Class::Accessor::Fast Class::Data::Inheritable];
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use Geography::Countries ();
7 use IP::Country::Fast;
8  
9 __PACKAGE__->mk_classdata('lookup');
10 __PACKAGE__->mk_accessors('context');
11  
12 __PACKAGE__->lookup( IP::Country::Fast->new );
13  
14 sub new {
15 my $class = shift;
16 return bless( { context => shift }, $class );
17 }
18  
19 sub code {
20 my $self = shift;
21 my $host = shift || $self->context->request->address;
22 return $self->lookup->inet_atocc($host);
23 }
24  
25 sub country {
26 my $self = shift;
27 my $code = shift || $self->code;
28  
29 unless ( $code =~ /^[A-Za-z]+$/ ) {
30 $code = $self->code($code);
31 }
32  
33 return undef unless $code;
34 return scalar Geography::Countries::country($code);
35 }
36  
37 1;
38  
39 __END__
« Geography.pm ↑ Summary