line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Geo; |
2
|
1
|
|
|
1
|
|
15848
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
14
|
|
3
|
1
|
|
|
1
|
|
1701
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
1
|
|
|
1
|
1
|
68
|
my ($self, $app) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$app->helper(geo => sub { |
11
|
0
|
|
|
0
|
|
|
my ($self,$ip) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $ip_info = $ua->get('http://geo.serving-sys.com/GeoTargeting/ebGetLocation.aspx?ip=' . $ip)->res->body; |
16
|
0
|
|
|
|
|
|
my %data = map { (split /=/, $_) } split(/&/, $ip_info); |
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return \%data; |
19
|
1
|
|
|
|
|
20
|
}); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
1; |
23
|
|
|
|
|
|
|
__END__ |