File Coverage

blib/lib/Mail/Exim/Blacklist/Geolocation.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package Mail::Exim::Blacklist::Geolocation;
2              
3             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
4              
5 1     1   106943 use 5.016;
  1         15  
6 1     1   6 use warnings;
  1         2  
  1         25  
7 1     1   6 use utf8;
  1         2  
  1         18  
8              
9             our $VERSION = 1.000;
10              
11 1     1   64 use Exporter qw(import);
  1         3  
  1         39  
12 1     1   519 use IP::Geolocation::MMDB;
  1         789  
  1         38  
13 1     1   7 use List::Util qw(first);
  1         2  
  1         290  
14              
15             our @EXPORT_OK = qw(country_code);
16              
17             our @DIRECTORIES = qw(
18             /var/lib/GeoIP
19             /usr/share/GeoIP
20             );
21              
22             our @DATABASES = qw(
23             dbip-country.mmdb
24             GeoIP2-Country.mmdb
25             dbip-country-lite.mmdb
26             GeoLite2-Country.mmdb
27             );
28              
29             our $DATABASE = $ENV{GEOIP_COUNTRY} || first {-r} map {
30             my $dir = $_;
31             map {"$dir/$_"} @DATABASES
32             } @DIRECTORIES;
33              
34             our $MMDB = eval { IP::Geolocation::MMDB->new(file => $DATABASE) };
35              
36             sub country_code {
37 2     2 1 1006 my $ip_address = shift;
38              
39 2         5 return eval { $MMDB->getcc($ip_address) };
  2         8  
40             }
41              
42             1;
43             __END__