line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Geography::Implementation; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw[Class::Accessor::Fast Class::Data::Inheritable]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
947
|
|
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__ |