CGI-Lingua
view release on metacpan or search on metacpan
t/locales.t view on Meta::CPAN
delete $ENV{LANG};
my $l = CGI::Lingua->new(supported => ['en-gb']);
is($l->sublanguage_code_alpha2(), 'gb', 'Uppercase Accept-Language handled correctly');
Test::Mockingbird::restore_all();
};
# Concurrent instances must not share state through the cache or globals.
# country() reads $ENV{REMOTE_ADDR} lazily at call time, so we must keep the
# correct REMOTE_ADDR in scope when calling country() on each object. Both
# objects are kept alive simultaneously (declared in the outer scope) to verify
# true concurrent isolation â neither touches the other's _country field.
subtest 'Concurrent instances do not share state' => sub {
Test::Mockingbird::mock('IP::Country::Fast', 'inet_atocc', sub {
my ($self_mock, $ip) = @_;
return $ip =~ /^8\.8/ ? 'US' : 'FR';
});
local %ENV = (HTTP_ACCEPT_LANGUAGE => 'en');
# Create and immediately resolve each object while its REMOTE_ADDR is live.
# $us and $fr are declared in the outer scope so both remain alive together.
my ($us, $us_cc);
{ local $ENV{REMOTE_ADDR} = '8.8.8.8';
$us = CGI::Lingua->new(supported => ['en', 'fr']);
$us_cc = $us->country(); }
my ($fr, $fr_cc);
{ local $ENV{REMOTE_ADDR} = '90.0.0.1';
$fr = CGI::Lingua->new(supported => ['en', 'fr']);
$fr_cc = $fr->country(); }
( run in 1.962 second using v1.01-cache-2.11-cpan-14f38c9f855 )