line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Geolocation::MMDB; |
2
|
1
|
|
|
1
|
|
811
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 1.000; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
252
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
9
|
1
|
|
|
1
|
|
472
|
use IP::Geolocation::MMDB; |
|
1
|
|
|
|
|
51308
|
|
|
1
|
|
|
|
|
248
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
1
|
|
|
1
|
1
|
76
|
my ($self, $app, $conf) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
50
|
|
|
|
50
|
my $file = $conf->{file} or croak q{The "file" parameter is mandatory}; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
15
|
my $mmdb = IP::Geolocation::MMDB->new(file => $file); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$app->helper( |
19
|
|
|
|
|
|
|
geolocation => sub { |
20
|
2
|
|
|
2
|
|
36232
|
my ($c, $ip_address) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
11
|
if (!defined $ip_address) { |
23
|
1
|
|
|
|
|
5
|
$ip_address = $c->tx->remote_address; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
93
|
my $data; |
27
|
2
|
50
|
|
|
|
7
|
if ($ip_address) { |
28
|
2
|
|
|
|
|
164
|
$data = $mmdb->record_for_address($ip_address); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
1587
|
return $data; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
121
|
); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
185
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
__END__ |