CGI-ACL
view release on metacpan or search on metacpan
t/integration.t view on Meta::CPAN
}
# Per-run lingua cache: each IP address makes exactly one WHOIS query for the
# entire test run. CGI::Lingua caches the resolved country inside the object;
# subsequent calls to country() on the cached object return the stored value
# without a new network round-trip.
#
# local $_ protects the caller's loop variable: CGI::Lingua and the WHOIS
# modules it calls use $_ internally (e.g. in grep/map inside
# Net::Whois::IANA), and without localisation that clobbers map/grep
# iterations in the calling code, producing scrambled results.
my %_lingua_cache;
sub lingua_for {
my $addr = shift;
unless(exists $_lingua_cache{$addr}) {
local $_;
local $ENV{REMOTE_ADDR} = $addr;
my $l = CGI::Lingua->new(supported => ['en']);
do { local $SIG{__WARN__} = sub {}; $l->country() };
$_lingua_cache{$addr} = $l;
}
( run in 1.468 second using v1.01-cache-2.11-cpan-4ab04211f4c )