CGI-Lingua
view release on metacpan or search on metacpan
lib/CGI/Lingua.pm view on Meta::CPAN
# Handle ::new() misuse
if(!defined($class)) {
if($params) {
if(my $logger = $params->{'logger'}) {
$logger->error(__PACKAGE__ . ' use ->new() not ::new() to instantiate');
}
croak(__PACKAGE__ . ' use ->new() not ::new() to instantiate');
}
$class = __PACKAGE__;
} elsif(ref($class)) {
# Clone: overlay new params onto existing object state
$params->{_supported} ||= $params->{supported} if defined $params->{'supported'};
return bless { %{$class}, %{$params} }, ref($class);
}
# Validate blessed logger objects before Object::Configure runs.
# Non-blessed values (arrayrefs, hashrefs) are valid config forms that
# Object::Configure knows how to convert into a Log::Abstraction instance.
if(defined $params->{'logger'} && blessed($params->{'logger'})) {
unless(
$params->{'logger'}->can('warn')
t/function.t view on Meta::CPAN
};
subtest 'new: sentinel flags initialised to GEO_UNKNOWN' => sub {
local %ENV = ();
my $l = _basic_obj();
is($l->{_have_ipcountry}, $GEO_UNKNOWN, '_have_ipcountry starts at -1');
is($l->{_have_geoip}, $GEO_UNKNOWN, '_have_geoip starts at -1');
is($l->{_have_geoipfree}, $GEO_UNKNOWN, '_have_geoipfree starts at -1');
};
subtest 'new: cloning overlays params onto existing state' => sub {
local %ENV = (HTTP_ACCEPT_LANGUAGE => 'en');
my $orig = _basic_obj();
$orig->{_country} = 'us';
my $clone = $orig->new(supported => ['de']);
is($clone->{_country}, 'us', 'Clone inherits computed state');
is_deeply($clone->{_supported}, ['de'], 'Clone takes new supported');
isnt($orig, $clone, 'Clone is a distinct object');
};
subtest 'new: cache restoration thaws frozen state' => sub {
( run in 0.737 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )