CGI-Lingua
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
# web => 'https://github.com/nigelhorne/CGI-Lingua/issues',
mailto => 'bug-CGI-Lingua@rt.cpan.org'
}
},
},
MIN_PERL_VERSION => '5.10.1' # //= and defined-or used throughout
);
# Return a description of the first local geo database that CGI::Lingua
# can use, or undef. Keep the file lists in step with @GEOIP2_MMDB and
# @GEOIP_DAT in lib/CGI/Lingua.pm (the module is not loaded here, because
# its prerequisites may not be installed yet).
sub local_geo_database
{
my @dirs = ((($^O eq 'MSWin32') ? ('c:/GeoIP') : ()), '/var/lib/GeoIP', '/usr/share/GeoIP', '/usr/local/share/GeoIP');
foreach my $reader ('IP::Geolocation::MMDB', 'MaxMind::DB::Reader') {
next unless(have_module($reader));
foreach my $dir (@dirs) {
foreach my $db (qw(GeoIP2-City GeoLite2-City GeoIP2-Country GeoLite2-Country)) {
my $file = "$dir/$db.mmdb";
if((-f $file) && (-r $file)) {
return "$reader version " . $reader->VERSION . " and $file";
}
}
}
}
if(have_module('IP::Country')) {
return 'IP::Country version ' . IP::Country->VERSION . ' installed';
}
if(have_module('Geo::IP')) {
my @dat = ((($^O eq 'MSWin32') ? ('c:/GeoIP/GeoIP.dat') : ()), '/usr/share/GeoIP/GeoIP.dat', '/usr/local/share/GeoIP/GeoIP.dat');
foreach my $file (@dat) {
if((-f $file) && (-r $file)) {
return 'Geo::IP version ' . Geo::IP->VERSION . " and $file";
}
}
print "Warning: Can't find your GeoIP.dat file for Geo::IP, disabling that module\n";
}
if(have_module('Geo::IPfree')) {
return 'Geo::IPfree version ' . Geo::IPfree->VERSION . ' installed';
}
return;
}
sub have_module
{
my $module = shift;
(my $file = "$module.pm") =~ s{::}{/}g;
return eval { require $file; 1 } ? 1 : 0;
}
sub are_online
{
return 0 if($ENV{'NO_NETWORK_TESTING'} || $ENV{'CIRCLECI'} || $ENV{'TRAVIS_PERL_VERSION'} || $ENV{'AUTOMATED_TESTING'} || $ENV{'NONINTERACTIVE_TESTING'} || (!-t STDIN));
if(my $s = IO::Socket::INET->new(
# PeerAddr => 'www.ripe.net:43',
PeerAddr => 'whois.apnic.net:43',
Timeout => 5
)) {
if($ENV{'PERL_MM_USE_DEFAULT'}) {
close($s);
return 1;
}
# FIXME: should test if any of the modules has been installed
if((-r '/usr/local/share/GeoIP/GeoIP.dat') ||
(-r '/usr/share/GeoIP/GeoIP.dat')) {
print <<EOF;
You appear to be directly connected to the Internet. I have some tests
that try to query Whois servers.
These tests will be slow, consider installing IP::Country, Geo::IPfree or
Geo::IP.
EOF
} else {
print <<EOF;
You appear to be directly connected to the Internet. I have some tests
that try to query Whois servers.
These tests will be slow, consider installing either IP::Country or Geo::IPfree.
EOF
}
close($s);
# Timeout inspired by Mail::IMAPClient
my $rc;
eval {
local $SIG{ALRM} = sub { die 'alarm' };
alarm(60);
$rc = prompt('Do you want to enable these tests?', 'y') =~ /^y/i ? 1 : 0;
alarm(0);
};
if($@) {
print "\n";
return 1; # The default is 'y'
}
return $rc;
}
print "On-line tests disabled because I couldn't detect an Internet connexion\n",
"Consider installing IP::Country, Geo::IPfree or Geo::IP\n";
return 0;
}
( run in 0.693 second using v1.01-cache-2.11-cpan-234fa220139 )