Branch Coverage

blib/lib/CGI/Lingua.pm
Criterion Covered Total %
branch 109 442 24.6


line true false branch
112 2 29 ref $_[0] eq 'HASH' ? :
118 1 30 unless ($params{'supported'})
126 0 0 if ($cache and $ENV{'REMOTE_ADDR'})
129 0 0 if ($info and $l = $info->lang) { }
0 0 elsif ($l = $class->_what_language) { }
135 0 0 if ($logger)
138 0 0 if (my $rc = $cache->get($key))
139 0 0 if ($logger)
149 0 0 if ($rc->{'_what_language'} || $rc->{'_rlanguage'} and $info and $info->lang)
181 30 0 if (defined $^V and $^V ge 'v5.14.0')
182 0 30 if ${^GLOBAL_PHASE} eq 'DESTRUCT'
184 10 20 unless ($ENV{'REMOTE_ADDR'})
188 0 20 unless ref $self
191 20 0 unless $cache
194 0 0 if (my $l = $self->_what_language)
198 0 0 if $cache->get($key)
200 0 0 if (my $logger = $self->{'_logger'})
230 0 0 unless $warning
232 0 0 if (my $syslog = $self->{'_syslog'})
237 0 0 if (ref($syslog eq 'HASH'))
240 0 0 if (my $info = $self->{'_info'}) { }
249 0 0 if ($self->{'_logger'}) { }
0 0 elsif (not defined $self->{'_syslog'}) { }
289 10 7 unless ($self->{'_slanguage'})
320 1 15 unless ($self->{'_slanguage'})
339 0 8 if ($self->{'_logger'})
342 1 7 unless ($self->{'_slanguage'})
345 0 8 if ($self->{'_logger'})
374 0 0 unless ($self->{'_slanguage'})
391 10 29 unless ($self->{'_rlanguage'})
405 0 22 if ($self->{'_logger'})
413 21 1 if (defined $http_accept_language)
414 0 21 if ($self->{'_logger'})
420 0 0 if (not $_[0] =~ /^Use of uninitialized value/)
427 3 18 if (not $l and $http_accept_language =~ /(.+)-.+/)
433 2 1 if ($i18n->accepts($1, $self->{'_supported'}))
438 19 2 if ($l)
439 0 19 if ($self->{'_logger'})
443 6 13 unless ($l =~ /^..-..$/)
445 6 0 if ($self->{'_slanguage'})
446 0 6 if ($self->{'_logger'})
457 3 3 if ($http_accept_language =~ /..-(..)$/) { }
0 3 elsif ($http_accept_language =~ /..-([a-z]{2,3})$/i) { }
462 3 3 if ($sl)
472 13 0 if ($l =~ /(.+)-(..)$/)
478 13 0 if ($accepts)
479 0 13 if ($self->{'_logger'})
482 13 0 if ($accepts =~ /\-/) { }
486 0 0 if ($self->{'_cache'})
489 0 0 if ($from_cache) { }
490 0 0 if ($self->{'_logger'})
497 0 0 if ($self->{'_slanguage'})
498 0 0 if ($variety eq 'uk')
506 0 0 if (defined $c)
510 0 0 if ($self->{'_sublanguage'})
512 0 0 if ($self->{'_logger'})
517 0 0 unless ($from_cache)
518 0 0 if ($self->{'_logger'})
528 0 13 if ($self->{'_logger'})
531 13 0 if ($accepts)
535 13 0 if ($variety =~ /[a-z]{2,3}/ and not defined $self->{'_sublanguage'})
537 0 13 if ($self->{'_logger'})
540 0 13 if ($variety eq 'uk')
549 0 13 if ($self->{'_cache'})
552 0 13 if (defined $from_cache) { }
553 0 0 if ($self->{'_logger'})
567 13 0 if (defined $results[0])
573 0 13 if ($@ or not defined $language_name) { }
580 0 13 if ($self->{'_logger'})
583 0 13 if ($self->{'_cache'} and not defined $from_cache)
584 0 0 if ($self->{'_logger'})
591 13 0 if (defined $self->{'_sublanguage'})
599 0 2 if ($self->{'_slanguage'} and $self->{'_slanguage'} ne 'Unknown')
600 0 0 if ($self->{'_rlanguage'} eq 'Unknown')
603 0 0 if ($self->{'_rlanguage'})
604 0 0 if ($l = $self->_code2language($self->{'_rlanguage'}))
615 1 1 if (!$self->{'_rlanguage'} || $self->{'_rlanguage'} eq 'Unknown' and length $http_accept_language == 2 || $http_accept_language =~ /^..-..$/)
619 1 0 unless ($self->{'_rlanguage'})
626 0 3 if ($self->{'_dont_use_ip'})
635 2 1 if (not defined $country and my $c = $self->_what_language)
636 0 2 if ($c =~ /^(..)_(..)/) { }
1 1 elsif ($c =~ /^(..)$/) { }
643 1 2 if (defined $country)
644 0 1 if ($self->{'_logger'})
650 0 1 if ($self->{'_cache'})
655 0 1 if ($from_cache) { }
656 0 0 if ($self->{'_logger'})
662 0 1 if ($l)
664 0 0 if (defined $l)
667 0 0 if ($self->{'_logger'} and $language_name)
674 0 1 if ($language_name) { }
0 1 elsif (defined $ip) { }
675 0 0 if (not defined $self->{'_rlanguage'} or $self->{'_rlanguage'} eq 'Unknown')
678 0 0 unless (exists $self->{'_slanguage'} and $self->{'_slanguage'} ne 'Unknown')
683 0 0 if ($language_name and $language_code2 and not defined $http_accept_language) { }
685 0 0 if ($self->{'_logger'})
690 0 0 if ($self->{'_logger'})
694 0 0 unless ($code)
695 0 0 if ($http_accept_language and $http_accept_language ne $self->{'_rlanguage'})
696 0 0 if ($self->{'_logger'})
701 0 0 unless ($code)
704 0 0 if ($self->{'_rlanguage'} =~ /(.+)\s\(.+/)
705 0 0 if (not defined $http_accept_language or $1 ne $self->{'_rlanguage'})
706 0 0 if ($self->{'_logger'})
712 0 0 unless ($code)
720 0 0 if ($code)
722 0 0 $self->{'_slanguage'} ? :
731 0 0 if (not defined $self->{'_slanguage_code_alpha2'}) { }
0 0 elsif (not defined $from_cache and $self->{'_cache'} and defined $self->{'_slanguage_code_alpha2'}) { }
732 0 0 if ($self->{'_logger'})
737 0 0 if ($self->{'_logger'})
758 10 3 if (/^(.+)-.+/) { }
763 13 0 if ($language_string eq $s)
775 25 0 if (ref $self)
776 0 25 if ($self->{'_logger'})
779 2 23 if ($self->{'_what_language'})
780 0 2 if ($self->{'_logger'})
785 0 23 if (my $info = $self->{'_info'})
786 0 0 if (my $rc = $info->lang)
788 0 0 if ($self->{'_logger'})
796 0 23 if (defined $ENV{'LANG'})
799 0 0 if (ref $self)
805 21 2 if ($ENV{'HTTP_ACCEPT_LANGUAGE'})
806 21 0 if (ref $self)
827 0 12 if ($self->{'_logger'})
834 0 12 if ($self->{'_country'})
835 0 0 if ($self->{'_logger'})
842 0 12 if (defined $ENV{'GEOIP_COUNTRY_CODE'})
846 2 10 if ($ENV{'HTTP_CF_IPCOUNTRY'} and $ENV{'HTTP_CF_IPCOUNTRY'} ne 'XX')
854 10 0 unless defined $ip
859 0 0 unless (is_ipv4($ip))
860 0 0 if ($ip eq '::1') { }
870 0 0 if (is_private_ip($ip))
871 0 0 if ($self->{'_logger'})
876 0 0 if (is_loopback_ip($ip))
877 0 0 if ($self->{'_logger'})
883 0 0 if ($self->{'_cache'})
885 0 0 if ($self->{'_logger'})
886 0 0 if (defined $self->{'_country'}) { }
892 0 0 if (defined $self->{'_country'})
897 0 0 if ($self->{'_have_ipcountry'} == -1)
898 0 0 if (eval { do { require IP::Country } }) { }
906 0 0 if ($self->{'_logger'})
910 0 0 if ($self->{'_have_ipcountry'})
912 0 0 if ($self->{'_country'}) { }
920 0 0 unless (defined $self->{'_country'})
921 0 0 if ($self->{'_have_geoip'} == -1)
922 0 0 if ($^O eq 'MSWin32' or -r '/usr/local/share/GeoIP/GeoIP.dat') { }
923 0 0 if (eval { do { require Geo::IP } }) { }
936 0 0 if ($self->{'_have_geoip'} == 1)
939 0 0 unless (defined $self->{'_country'})
940 0 0 if ($self->{'_have_geoipfree'} == -1)
941 0 0 if (eval { do { require Geo::IPfree } }) { }
949 0 0 if ($self->{'_have_geoipfree'} == 1)
954 0 0 if ($self->{'_country'} and $self->{'_country'} eq 'eu')
957 0 0 if (not $self->{'_country'} and eval { do { require LWP::Simple; require JSON::Parse } })
959 0 0 if ($self->{'_logger'})
966 0 0 if (my $data = LWP::Simple::get("http://www.geoplugin.net/json.gp?ip=$ip"))
970 0 0 unless ($self->{'_country'})
971 0 0 if ($self->{'_logger'})
986 0 0 unless ($@ or not defined $whois or ref $whois ne 'HASH')
987 0 0 if (defined $whois->{'Country'}) { }
0 0 elsif (defined $whois->{'country'}) { }
992 0 0 if ($self->{'_country'})
993 0 0 if ($self->{'_country'} eq 'EU') { }
0 0 elsif ($self->{'_country'} eq 'US' and $whois->{'StateProv'} eq 'PR') { }
1002 0 0 if ($self->{'_country'}) { }
1003 0 0 if ($self->{'_logger'})
1007 0 0 if ($self->{'_logger'})
1018 0 0 unless ($@)
1020 0 0 if ($self->{'_logger'})
1026 0 0 if ($self->{'_country'})
1029 0 0 if ($self->{'_country'} =~ /^(..)\s*#/)
1037 0 0 if ($self->{'_country'})
1039 0 0 if ($self->{'_country'} eq 'hk') { }
0 0 elsif ($self->{'_country'} eq 'eu') { }
1048 0 0 if (subnet_matcher('185.10.104.0/22')->($ip)) { }
1058 0 0 if ($self->{'_cache'})
1059 0 0 if ($self->{'_logger'})
1088 0 1 if ($self->{'_locale'})
1096 1 0 if (defined $agent and $agent =~ /\((.+)\)/)
1102 0 5 if ($candidate =~ /^[a-zA-Z]{2}-([a-zA-Z]{2})$/)
1105 0 0 if ($c)
1113 1 0 if (eval { do { require HTTP::BrowserDetect } })
1117 1 0 if ($browser and $browser->country)
1119 1 0 if ($c)
1130 0 0 if ($country)
1138 0 0 unless ($@)
1139 0 0 if ($c)
1147 0 0 if (defined $ENV{'GEOIP_COUNTRY_CODE'})
1150 0 0 if ($c)
1170 0 0 if ($self->{'_logger'})
1173 0 0 if ($self->{'_timezone'})
1174 0 0 if ($self->{'_logger'})
1180 0 0 if ($self->{'_have_geoip'} == -1)
1181 0 0 if ($^O eq 'MSWin32' or -r '/usr/local/share/GeoIP/GeoIP.dat') { }
1182 0 0 if (eval { do { require Geo::IP } }) { }
1196 0 0 if ($self->{'_have_geoip'} == 1)
1199 0 0 if (not $self->{'_timezone'} and $ip)
1200 0 0 if (eval { do { require LWP::Simple; require JSON::Parse } }) { }
1201 0 0 if ($self->{'_logger'})
1208 0 0 if (my $data = LWP::Simple::get("http://ip-api.com/json/$ip"))
1224 0 20 unless $code
1225 0 20 if ($self->{'_logger'})
1226 0 0 if (defined $self->{'_country'}) { }
1232 20 0 unless ($self->{'_cache'})
1236 0 0 if ($from_cache)
1237 0 0 if ($self->{'_logger'})
1242 0 0 if ($self->{'_logger'})
1253 0 18 unless $code
1254 0 18 if ($self->{'_logger'})
1255 0 0 if ($self->{'_country'}) { }
1262 0 1 if (not $_[0] =~ /No result found in country table/)
1276 0 13 unless $code
1277 0 13 if ($self->{'_logger'})
1280 13 0 unless ($self->{'_cache'})
1282 13 0 if (defined $country)
1288 0 0 if ($from_cache)
1289 0 0 if ($self->{'_logger'})
1294 0 0 if ($self->{'_logger'})
1298 0 0 if (defined $country)