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