Branch Coverage

blib/lib/CGI/Lingua.pm
Criterion Covered Total %
branch 112 452 24.7


line true false branch
113 2 31 ref $_[0] eq 'HASH' ? :
115 0 33 if (not defined $class) { }
0 33 elsif (ref $class) { }
131 3 30 unless ($params{'supported'})
139 0 0 if ($cache and $ENV{'REMOTE_ADDR'})
142 0 0 if ($info and $l = $info->lang) { }
0 0 elsif ($l = $class->_what_language) { }
148 0 0 if ($logger)
151 0 0 if (my $rc = $cache->get($key))
152 0 0 if ($logger)
165 0 0 if ($rc->{'_what_language'} || $rc->{'_rlanguage'} and $info and $info->lang)
197 31 0 if (defined $^V and $^V ge "v5.14.0")
198 0 31 if ${^GLOBAL_PHASE} eq "DESTRUCT"
200 11 20 unless ($ENV{'REMOTE_ADDR'})
204 0 20 unless ref $self
207 20 0 unless $cache
210 0 0 if (my $l = $self->_what_language)
214 0 0 if $cache->get($key)
216 0 0 if (my $logger = $self->{'_logger'})
246 0 0 unless $warning
248 0 0 if (my $syslog = $self->{'_syslog'})
254 0 0 if (ref $syslog eq "HASH")
257 0 0 if (my $info = $self->{'_info'}) { }
266 0 0 if ($self->{'_logger'}) { }
0 0 elsif (not defined $self->{'_syslog'}) { }
307 10 7 unless ($self->{'_slanguage'})
338 1 15 unless ($self->{'_slanguage'})
357 0 8 if ($self->{'_logger'})
360 1 7 unless ($self->{'_slanguage'})
363 0 8 if ($self->{'_logger'})
391 0 0 unless ($self->{'_slanguage'})
411 10 29 unless ($self->{'_rlanguage'})
425 0 22 if ($self->{'_logger'})
433 21 1 if (defined $http_accept_language)
434 0 21 if ($self->{'_logger'})
440 0 0 if (not $_[0] =~ /^Use of uninitialized value/)
447 3 18 if (not $l and $http_accept_language =~ /(.+)-.+/)
453 2 1 if ($i18n->accepts($1, $self->{'_supported'}))
458 19 2 if ($l) { }
0 3 elsif ($http_accept_language =~ /;/ and defined $self->{'_logger'}) { }
459 0 19 if ($self->{'_logger'})
463 6 13 if (not $l =~ /^..-..$/) { }
13 0 elsif ($l =~ /(.+)-(..)$/) { }
465 6 0 if ($self->{'_slanguage'})
466 0 6 if ($self->{'_logger'})
477 3 3 if ($http_accept_language =~ /..-(..)$/) { }
0 3 elsif ($http_accept_language =~ /..-([a-z]{2,3})$/i) { }
482 3 3 if ($sl)
496 13 0 if ($accepts)
497 0 13 if ($self->{'_logger'})
500 13 0 if ($accepts =~ /\-/) { }
504 0 0 if ($self->{'_cache'})
507 0 0 if ($from_cache) { }
508 0 0 if ($self->{'_logger'})
515 0 0 if ($self->{'_slanguage'})
516 0 0 if ($variety eq "uk")
524 0 0 if (defined $c)
528 0 0 if ($self->{'_sublanguage'})
530 0 0 if ($self->{'_logger'})
535 0 0 unless ($from_cache)
536 0 0 if ($self->{'_logger'})
546 0 13 if ($self->{'_logger'})
549 13 0 if ($accepts)
553 13 0 if ($variety =~ /[a-z]{2,3}/ and not defined $self->{'_sublanguage'})
555 0 13 if ($self->{'_logger'})
558 0 13 if ($variety eq "uk")
567 0 13 if ($self->{'_cache'})
570 0 13 if (defined $from_cache) { }
571 0 0 if ($self->{'_logger'})
585 13 0 if (defined $results[0])
591 0 13 if ($@ or not defined $language_name) { }
598 0 13 if ($self->{'_logger'})
601 0 13 if ($self->{'_cache'} and not defined $from_cache)
602 0 0 if ($self->{'_logger'})
609 13 0 if (defined $self->{'_sublanguage'})
619 0 2 if ($self->{'_slanguage'} and $self->{'_slanguage'} ne "Unknown")
620 0 0 if ($self->{'_rlanguage'} eq "Unknown")
623 0 0 if ($self->{'_rlanguage'})
624 0 0 if ($l = $self->_code2language($self->{'_rlanguage'}))
635 1 1 if (!$self->{'_rlanguage'} || $self->{'_rlanguage'} eq 'Unknown' and length $http_accept_language == 2 || $http_accept_language =~ /^..-..$/)
639 1 0 unless ($self->{'_rlanguage'})
646 0 3 if ($self->{'_dont_use_ip'})
655 2 1 if (not defined $country and my $c = $self->_what_language)
656 0 2 if ($c =~ /^(..)_(..)/) { }
1 1 elsif ($c =~ /^(..)$/) { }
663 1 2 if (defined $country)
664 0 1 if ($self->{'_logger'})
670 0 1 if ($self->{'_cache'})
675 0 1 if ($from_cache) { }
676 0 0 if ($self->{'_logger'})
682 0 1 if ($l)
684 0 0 if (defined $l)
687 0 0 if ($self->{'_logger'} and $language_name)
694 0 1 if ($language_name) { }
0 1 elsif (defined $ip) { }
695 0 0 if (not defined $self->{'_rlanguage'} or $self->{'_rlanguage'} eq "Unknown")
698 0 0 unless (exists $self->{'_slanguage'} and $self->{'_slanguage'} ne "Unknown")
703 0 0 if ($language_name and $language_code2 and not defined $http_accept_language) { }
705 0 0 if ($self->{'_logger'})
710 0 0 if ($self->{'_logger'})
714 0 0 unless ($code)
715 0 0 if ($http_accept_language and $http_accept_language ne $self->{'_rlanguage'})
716 0 0 if ($self->{'_logger'})
721 0 0 unless ($code)
724 0 0 if ($self->{'_rlanguage'} =~ /(.+)\s\(.+/)
725 0 0 if (not defined $http_accept_language or $1 ne $self->{'_rlanguage'})
726 0 0 if ($self->{'_logger'})
732 0 0 unless ($code)
740 0 0 if ($code)
742 0 0 $self->{'_slanguage'} ? :
751 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'}) { }
752 0 0 if ($self->{'_logger'})
757 0 0 if ($self->{'_logger'})
778 10 3 if (/^(.+)-.+/) { }
783 13 0 if ($language_string eq $s)
795 25 0 if (ref $self)
796 0 25 if ($self->{'_logger'})
799 2 23 if ($self->{'_what_language'})
800 0 2 if ($self->{'_logger'})
805 0 23 if (my $info = $self->{'_info'})
806 0 0 if (my $rc = $info->lang)
808 0 0 if ($self->{'_logger'})
816 0 23 if (defined $ENV{'LANG'})
819 0 0 if (ref $self)
825 21 2 if ($ENV{'HTTP_ACCEPT_LANGUAGE'})
826 21 0 if (ref $self)
847 0 12 if ($self->{'_logger'})
854 0 12 if ($self->{'_country'})
855 0 0 if ($self->{'_logger'})
862 0 12 if (defined $ENV{'GEOIP_COUNTRY_CODE'})
866 2 10 if ($ENV{'HTTP_CF_IPCOUNTRY'} and $ENV{'HTTP_CF_IPCOUNTRY'} ne "XX")
874 10 0 unless defined $ip
879 0 0 unless (is_ipv4($ip))
880 0 0 if ($ip eq '::1') { }
890 0 0 if (is_private_ip($ip))
891 0 0 if ($self->{'_logger'})
896 0 0 if (is_loopback_ip($ip))
897 0 0 if ($self->{'_logger'})
903 0 0 if ($self->{'_cache'})
905 0 0 if ($self->{'_logger'})
906 0 0 if (defined $self->{'_country'}) { }
912 0 0 if (defined $self->{'_country'})
917 0 0 if ($self->{'_have_ipcountry'} == -1)
918 0 0 if (eval {
926 0 0 if ($self->{'_logger'})
930 0 0 if ($self->{'_have_ipcountry'})
932 0 0 if ($self->{'_country'}) { }
940 0 0 unless (defined $self->{'_country'})
941 0 0 if ($self->{'_have_geoip'} == -1)
944 0 0 if ($self->{'_have_geoip'} == 1)
947 0 0 unless (defined $self->{'_country'})
948 0 0 if ($self->{'_have_geoipfree'} == -1)
952 0 0 if ($@) { }
960 0 0 if ($self->{'_have_geoipfree'} == 1)
965 0 0 if ($self->{'_country'} and $self->{'_country'} eq "eu")
968 0 0 if (not $self->{'_country'} and eval {
970 0 0 if ($self->{'_logger'})
977 0 0 if (my $data = LWP::Simple::WithCache::get("http://www.geoplugin.net/json.gp?ip=$ip"))
981 0 0 unless ($self->{'_country'})
982 0 0 if ($self->{'_logger'})
997 0 0 unless ($@ or not defined $whois or ref $whois ne "HASH")
998 0 0 if (defined $whois->{'Country'}) { }
0 0 elsif (defined $whois->{'country'}) { }
1003 0 0 if ($self->{'_country'})
1004 0 0 if ($self->{'_country'} eq 'EU') { }
0 0 elsif ($self->{'_country'} eq 'US' and $whois->{'StateProv'} eq 'PR') { }
1013 0 0 if ($self->{'_country'}) { }
1014 0 0 if ($self->{'_logger'})
1018 0 0 if ($self->{'_logger'})
1029 0 0 unless ($@)
1031 0 0 if ($self->{'_logger'})
1037 0 0 if ($self->{'_country'})
1040 0 0 if ($self->{'_country'} =~ /^(..)\s*#/)
1048 0 0 if ($self->{'_country'})
1050 0 0 if ($self->{'_country'} eq 'hk') { }
0 0 elsif ($self->{'_country'} eq 'eu') { }
1059 0 0 if (subnet_matcher('185.10.104.0/22')->($ip)) { }
1069 0 0 if ($self->{'_cache'})
1070 0 0 if ($self->{'_logger'})
1084 0 0 if ($^O eq 'MSWin32' or -r '/usr/local/share/GeoIP/GeoIP.dat' or -r '/usr/share/GeoIP/GeoIP.dat') { }
1088 0 0 if ($@) { }
1093 0 0 if (-r '/usr/share/GeoIP/GeoIP.dat') { }
1125 0 1 if ($self->{'_locale'})
1133 1 0 if (defined $agent and $agent =~ /\((.+)\)/)
1139 0 5 if ($candidate =~ /^[a-zA-Z]{2}-([a-zA-Z]{2})$/)
1142 0 0 if ($c)
1150 1 0 if (eval {
1154 1 0 if ($browser and $browser->country)
1156 1 0 if ($c)
1167 0 0 if ($country)
1175 0 0 unless ($@)
1176 0 0 if ($c)
1184 0 0 if (defined $ENV{'GEOIP_COUNTRY_CODE'})
1187 0 0 if ($c)
1207 0 0 if ($self->{'_logger'})
1210 0 0 if ($self->{'_timezone'})
1211 0 0 if ($self->{'_logger'})
1217 0 0 if ($self->{'_have_geoip'} == -1)
1220 0 0 if (my $ip = $ENV{'REMOTE_ADDR'}) { }
1221 0 0 if ($self->{'_have_geoip'} == 1)
1224 0 0 unless ($self->{'_timezone'})
1225 0 0 if (eval {
1226 0 0 if ($self->{'_logger'})
1233 0 0 if (my $data = LWP::Simple::WithCache::get("http://ip-api.com/json/$ip"))
1242 0 0 if (open my $fin, '<', '/etc/timezone') { }
1251 0 0 if ($self->{'_logger'} and not defined $self->{'_timezone'})
1262 0 20 unless $code
1263 0 20 if ($self->{'_logger'})
1264 0 0 if (defined $self->{'_country'}) { }
1270 20 0 unless ($self->{'_cache'})
1274 0 0 if ($from_cache)
1275 0 0 if ($self->{'_logger'})
1280 0 0 if ($self->{'_logger'})
1291 0 18 unless $code
1292 0 18 if ($self->{'_logger'})
1293 0 0 if ($self->{'_country'}) { }
1300 0 1 if (not $_[0] =~ /No result found in country table/)
1314 0 13 unless $code
1315 0 13 if ($self->{'_logger'})
1318 13 0 unless ($self->{'_cache'})
1320 13 0 if (defined $country)
1326 0 0 if ($from_cache)
1327 0 0 if ($self->{'_logger'})
1332 0 0 if ($self->{'_logger'})
1336 0 0 if (defined $country)