line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Geolocation::MMDB; |
2
|
1
|
|
|
1
|
|
600
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.003; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
195
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
9
|
1
|
|
|
1
|
|
353
|
use IP::Geolocation::MMDB; |
|
1
|
|
|
|
|
37094
|
|
|
1
|
|
|
|
|
201
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
1
|
|
|
1
|
1
|
62
|
my ($self, $app, $conf) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
50
|
|
|
|
33
|
my $file = $conf->{file} or croak q{The "file" parameter is mandatory}; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
8
|
my $mmdb = IP::Geolocation::MMDB->new(file => $file); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$app->helper(geolocation => sub { |
19
|
2
|
|
|
2
|
|
26383
|
my ($c, $ip_address) = @_; |
20
|
|
|
|
|
|
|
|
21
|
2
|
100
|
|
|
|
8
|
if (!defined $ip_address) { |
22
|
1
|
|
|
|
|
4
|
$ip_address = $c->tx->remote_address; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
54
|
my $data; |
26
|
2
|
50
|
|
|
|
5
|
if ($ip_address) { |
27
|
2
|
|
|
|
|
128
|
$data = $mmdb->record_for_address($ip_address); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
1111
|
return $data; |
31
|
1
|
|
|
|
|
125
|
}); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
118
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |