Branch Coverage

blib/lib/CGI/Info.pm
Criterion Covered Total %
branch 356 470 75.7


line true false branch
81 0 154 ref $_[0] eq 'HASH' ? :
83 1 153 if ($args{'expect'} and ref $args{'expect'} ne "ARRAY")
88 1 152 if (not defined $class) { }
4 148 elsif (ref $class) { }
127 9 6 unless ($self->{'script_name'})
139 11 4 if ($ENV{'SCRIPT_NAME'}) { }
148 1 14 if ($ENV{'SCRIPT_FILENAME'}) { }
5 9 elsif ($ENV{'SCRIPT_NAME'} and $ENV{'DOCUMENT_ROOT'}) { }
5 4 elsif ($ENV{'SCRIPT_NAME'} and not $ENV{'DOCUMENT_ROOT'}) { }
0 4 elsif ('File::Spec'->file_name_is_absolute($0)) { }
152 3 2 if ($script_name =~ m[^/(.+)])
158 1 4 if ('File::Spec'->file_name_is_absolute($ENV{'SCRIPT_NAME'}) and -r $ENV{'SCRIPT_NAME'}) { }
167 2 2 if ($script_name =~ m[^/(.+)])
208 5 17 unless ($self->{'script_path'})
230 1 10 unless ($self->{'script_path'})
235 0 11 if ($^O eq 'MSWin32') { }
236 0 0 if ($self->{'script_path'} =~ /(.+)\\.+?$/)
240 11 0 if ($self->{'script_path'} =~ m[(.+)/.+?$])
271 2 6 unless ($self->{'site'})
281 4 3 if ($self->{'logger'})
284 2 0 if ($self->{'site'} and $self->{'cgi_site'})
291 1 4 if ($ENV{'HTTP_HOST'}) { }
3 1 elsif ($ENV{'SERVER_NAME'}) { }
295 1 0 if ($self->{'cgi_site'} =~ /(.*)\.+$/)
300 1 2 if (defined $self->protocol and $self->protocol ne "http")
308 1 0 if ($self->{'logger'})
315 5 0 unless ($self->{'site'})
318 4 1 if ($self->{'site'} =~ m[^https?://(.+)])
321 1 4 unless ($self->{'cgi_site'} =~ m[^https?://])
324 0 1 unless ($protocol)
329 0 5 unless ($self->{'site'} and $self->{'cgi_site'})
332 3 2 if ($self->{'logger'})
347 3 2 if ($self->{'domain'})
352 2 0 if ($self->{'site'})
354 1 1 if ($self->{'domain'} =~ /^www\.(.+)/)
371 3 4 unless ($self->{'cgi_site'})
481 4 158 ref $_[0] eq 'HASH' ? :
483 93 1 if (defined $self->{'paramref'} and !defined($args{'allow'}) || defined $self->{'allow'} && $args{'allow'} eq $self->{'allow'})
487 4 65 if (defined $args{'allow'})
490 3 66 if (defined $args{'expect'})
491 2 1 if (ref $args{'expect'} eq 'ARRAY') { }
497 1 68 if (defined $args{'upload_dir'})
500 1 68 if (defined $args{'logger'})
503 2 67 if ($self->{'logger'})
511 6 63 if (not $ENV{'GATEWAY_INTERFACE'} && $ENV{'REQUEST_METHOD'}) { }
44 19 elsif ($ENV{'REQUEST_METHOD'} eq 'GET' or $ENV{'REQUEST_METHOD'} eq 'HEAD') { }
16 3 elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { }
0 3 elsif ($ENV{'REQUEST_METHOD'} eq 'OPTIONS') { }
1 2 elsif ($ENV{'REQUEST_METHOD'} eq 'DELETE') { }
512 5 1 if (@ARGV) { }
0 1 elsif ($stdin_data) { }
1 0 elsif (not $self->{'args_read'}) { }
514 5 0 if (defined $pairs[0])
515 1 4 if ($pairs[0] eq '--robot') { }
1 3 elsif ($pairs[0] eq '--mobile') { }
1 2 elsif ($pairs[0] eq '--search-engine') { }
1 1 elsif ($pairs[0] eq '--tablet') { }
544 1 1 if $line eq "quit"
550 41 3 if (my $query = $ENV{'QUERY_STRING'}) { }
551 1 40 if (defined $content_type and $content_type =~ m[multipart/form-data]i)
560 2 14 unless (defined $ENV{'CONTENT_LENGTH'})
565 0 14 if ($self->{'max_upload_size'} >= 0 and $content_length > $self->{'max_upload_size'})
573 3 11 if (not defined $content_type or $content_type =~ m[application/x-www-form-urlencoded]) { }
8 3 elsif ($content_type =~ m[multipart/form-data]i) { }
1 2 elsif ($content_type =~ m[text/xml]i) { }
1 1 elsif ($content_type =~ m[application/json]i) { }
575 1 2 if ($stdin_data) { }
578 1 1 if (read(STDIN, $buffer, $content_length) != $content_length)
590 1 7 unless (defined $self->{'upload_dir'})
596 1 6 unless ("File::Spec"->file_name_is_absolute($self->{'upload_dir'}))
603 2 4 unless (-d $self->{'upload_dir'})
610 0 4 unless (-w $self->{'upload_dir'})
618 4 0 if ($content_type =~ /boundary=(\S+)$/)
626 0 1 if ($stdin_data) { }
629 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
644 0 1 if ($stdin_data) { }
650 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
665 0 1 if ($stdin_data) { }
668 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
695 1 52 unless (scalar @pairs)
707 4 98 unless $key
711 98 0 if (defined $value) { }
720 25 73 if ($self->{'allow'})
722 11 14 unless (exists $self->{'allow'}{$key})
723 0 11 if ($self->{'logger'})
730 9 5 if (defined $self->{'allow'}{$key})
731 7 2 unless ($value =~ /$self->{'allow'}{$key}/)
732 0 7 if ($self->{'logger'})
740 2 78 if ($self->{'expect'} and &List::MoreUtils::none(sub { $_ eq $key; } , @{$$self{"expect"};}))
745 67 11 if (not defined $ENV{'REQUEST_METHOD'} or $ENV{'REQUEST_METHOD'} eq "GET")
747 0 64 if ($value =~ /(\%27)|(\')|(\-\-)|(\%23)|(\#)/xi or $value =~ /((\%3D)|(=))[^\n]*((\%27)|(\')|(\-\-)|(\%3B)|(;))/i or $value =~ /\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/xi or $value =~ /((\%27)|(\'))union/xi or $value =~ /select[[a-z]\s\*]from/xi or $value =~ /\sAND\s1=1/xi or $value =~ /exec(\s|\+)+(s|x)p\w+/xi)
754 0 3 if ($self->{'logger'})
755 0 0 if ($ENV{'REMOTE_ADDR'}) { }
764 0 64 if ($value =~ m[((\%3C)|<)((\%2F)|/)*[a-z0-9\%]+((\%3E)|>)]xi or $value =~ /((\%3C)|<)[^\n]+((\%3E)|>)/i)
766 0 0 if ($self->{'logger'})
772 0 64 if ($value eq "../")
773 0 0 if ($self->{'logger'})
780 71 4 if (length $value > 0)
782 5 66 if ($FORM{$key} and $FORM{$key} ne $value) { }
790 9 40 unless (%FORM)
794 2 38 if ($self->{'logger'})
834 1 25 unless (defined $field)
838 4 21 if ($self->{'allow'} and not exists $self->{'allow'}{$field})
845 20 1 if (defined $self->params)
856 11 8 if (ref $_[0] eq 'HASH') { }
0 8 elsif (scalar(@_) % 2 == 0) { }
866 0 19 unless $warning
867 0 19 if ($self eq "CGI::Info")
874 0 19 if ($self->{'syslog'})
878 0 0 if (ref($self->{'syslog'} eq "HASH"))
886 0 19 if ($self->{'logger'}) { }
19 0 elsif (not defined $self->{'syslog'}) { }
913 0 4 if ($self->{'logger'})
918 0 4 if ($self->{'logger'})
921 0 4 if ($total_bytes == 0)
925 4 0 unless ($stdin_data)
931 0 4 unless ($stdin_data)
946 2 32 if ($line =~ /^--\Q$boundary\E--$/)
949 8 24 if ($line =~ /^--\Q$boundary\E$/) { }
16 8 elsif ($in_header) { }
950 0 8 if ($writing_file) { }
4 4 elsif (defined $key) { }
959 6 10 if (length $line == 0) { }
8 2 elsif ($line =~ /^Content-Disposition: (.+)/i) { }
963 8 0 if ($field =~ /name="(.+?)"/)
966 4 4 if ($field =~ /filename="(.+)?"/)
968 2 2 do { $filename =~ m[[\\/\|]] } ? :
4 0 defined $filename ? :
981 0 2 unless (open $fout, ">", $full_path)
991 4 4 if ($writing_file) { }
999 2 0 if ($writing_file)
1016 35 0 if ($args->{'filename'} =~ m<(^[\w\+_\040\#\(\)\{\}\[\]/\-\^,\.:;&%\@\\~]+\$?$)>)
1033 13 27 if (defined $self->{'is_mobile'})
1038 3 24 if (my $ch_ua_mobile = $ENV{'HTTP_SEC_CH_UA_MOBILE'})
1039 1 2 if ($ch_ua_mobile eq "?1")
1044 1 25 if ($ENV{'HTTP_X_WAP_PROFILE'})
1051 16 9 if (my $agent = $ENV{'HTTP_USER_AGENT'})
1052 2 14 if ($agent =~ /.+(Android|iPhone).+/)
1058 1 13 if ($agent =~ m[(android|bb\d+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino]i or substr($ENV{'HTTP_USER_AGENT'}, 0, 4) =~ m[1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-]i)
1065 0 9 if (defined $remote and $self->{'cache'})
1067 0 0 if (defined $is_mobile)
1073 7 6 unless ($self->{'browser_detect'})
1074 7 0 if (eval { do { require HTTP::BrowserDetect } })
1079 13 0 if ($self->{'browser_detect'})
1082 0 13 if ($self->{'cache'} and defined $remote)
1102 1 5 if (defined $self->{'is_tablet'})
1106 1 4 if ($ENV{'HTTP_USER_AGENT'} and $ENV{'HTTP_USER_AGENT'} =~ /.+(iPad|TabletPC).+/) { }
1126 7 28 unless ($self->params)
1138 12 28 if (defined $rc) { }
1144 1 27 if ($rc and $self->{'logger'})
1148 28 0 defined $rc ? :
1161 2 19 if ($ENV{'SCRIPT_URI'} and $ENV{'SCRIPT_URI'} =~ m[^(.+)://.+])
1164 2 17 if ($ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} =~ m[^HTTP/])
1169 14 3 if (defined $port)
1170 14 0 if (defined(my $name = getservbyport($port, 'tcp'))) { }
0 0 elsif ($port == 80) { }
0 0 elsif ($port == 443) { }
1171 12 2 if ($name =~ /https?/) { }
0 2 elsif ($name eq 'www') { }
1186 0 5 if ($ENV{'REMOTE_ADDR'})
1221 1 14 ref $_[0] eq 'HASH' ? :
1224 0 15 if ($^O eq "MSWin32")
1230 3 12 unless (ref $self)
1234 4 11 if ($ENV{'C_DOCUMENT_ROOT'} and -d $ENV{'C_DOCUMENT_ROOT'})
1236 2 2 if (-d $dir and -w $dir)
1240 2 0 if (-d $dir and -w $dir)
1244 1 10 if ($ENV{'DOCUMENT_ROOT'} and -d $ENV{'DOCUMENT_ROOT'})
1246 1 0 if (-d $dir and -w $dir)
1250 3 7 $params{'default'} ? :
1268 0 9 if ($ENV{'C_DOCUMENT_ROOT'} and -d $ENV{'C_DOCUMENT_ROOT'}) { }
3 10 elsif ($ENV{'DOCUMENT_ROOT'} and -d $ENV{'DOCUMENT_ROOT'}) { }
1275 6 0 unless ("File::Spec"->file_name_is_absolute($script_name))
1278 0 6 if ($script_name =~ /.cgi\-bin.*/)
1281 6 0 if (-f $script_name)
1282 0 6 if ($^O eq 'MSWin32') { }
1283 0 0 if ($script_name =~ /(.+)\\.+?$/)
1287 6 0 if ($script_name =~ m[(.+)/.+?$])
1305 1 3 unless (ref $self)
1309 1 3 if (defined $dir)
1315 3 2 if (defined $rc and length $rc and -d $rc and -w $rc)
1320 0 3 if not defined $dir or length $dir == 0
1342 4 16 if (defined $self->{'is_robot'})
1349 7 9 unless ($remote and $agent)
1354 3 6 if ($agent =~ /.+bot|bytespider|msnptc|is_archiver|backstreet|spider|scoutjet|gingersoftware|heritrix|dodnetdotcom|yandex|nutch|ezooms|plukkie|nova\.6scan\.com|Twitterbot|adscanner|python-requests|Mediatoolkitbot|NetcraftSurveyAgent|Expanse|serpstatbot/i)
1359 2 4 if (my $referrer = $ENV{'HTTP_REFERER'})
1401 2 0 if ($referrer =~ /\)/ or &List::MoreUtils::any(sub { $_ =~ /^$referrer/; } , @crawler_lists))
1402 2 0 if ($self->{'logger'})
1412 0 4 if ($self->{'cache'})
1414 0 0 if (defined(my $is_robot = $self->{'cache'}->get($key)))
1420 3 1 unless ($self->{'browser_detect'})
1421 3 0 if (eval { do { require HTTP::BrowserDetect } })
1426 4 0 if ($self->{'browser_detect'})
1428 1 1 if (defined $is_robot and $self->{'logger'})
1431 2 2 defined $is_robot && $is_robot ? :
1432 2 2 if ($self->{'logger'})
1436 2 2 if ($is_robot)
1437 0 2 if ($self->{'cache'})
1445 0 2 if ($self->{'cache'})
1469 8 19 if (defined $self->{'is_search_engine'})
1476 8 11 unless ($remote and $agent)
1483 0 11 if ($self->{'cache'})
1487 0 0 if (defined $is_search)
1495 0 11 if ($agent =~ /www\.majestic12\.co\.uk|facebookexternal/)
1496 0 0 if ($self->{'cache'})
1502 7 4 unless ($self->{'browser_detect'})
1503 7 0 if (eval { do { require HTTP::BrowserDetect } })
1508 11 0 if (my $browser = $self->{'browser_detect'})
1510 1 10 if (not $is_search and $agent =~ m[SeznamBot/])
1513 0 11 if ($self->{'cache'})
1523 0 0 if (defined $hostname and $hostname =~ /google|msnbot|bingbot|amazonbot/ and not $hostname =~ /^google-proxy/)
1524 0 0 if ($self->{'cache'})
1531 0 0 if ($self->{'cache'})
1565 8 15 if ($self->is_mobile)
1568 7 8 if ($self->is_search_engine)
1571 4 4 if ($self->is_robot)
1598 3 10 if (ref $_[0] eq 'HASH') { }
9 1 elsif (scalar(@_) % 2 == 0) { }
1606 3 10 unless (defined $params{'cookie_name'})
1611 4 6 unless ($self->{'jar'})
1612 1 3 unless (defined $ENV{'HTTP_COOKIE'})
1623 6 3 if (exists $self->{'jar'}{$params{'cookie_name'}})
1645 0 2 unless (defined $field)
1650 0 2 unless ($self->{'jar'})
1651 0 0 unless (defined $ENV{'HTTP_COOKIE'})
1662 2 0 if (exists $self->{'jar'}{$field})
1677 4 8 if (my $status = shift()) { }
5 3 elsif (not defined $self->{'status'}) { }
1680 4 1 if (defined(my $method = $ENV{'REQUEST_METHOD'}))
1681 1 3 if ($method eq 'OPTIONS' or $method eq 'DELETE') { }
1 4 elsif ($method eq 'POST' and not defined $ENV{'CONTENT_LENGTH'}) { }
1704 1 2 if (ref $_[0] eq 'HASH') { }
1 1 elsif (scalar(@_) % 2 == 0) { }
1727 1 10 unless ($class eq "CGI::Info")
1741 153 4 if $param eq "DESTROY"
1745 0 4 if ref $self ne "CGI::Info"