| 1 | package CGI::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Common Gateway Interface, with no frills | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # This file is part of CGI::Tiny which is released under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # See the documentation for CGI::Tiny for full license details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | our $VERSION = '1.003'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use constant DEFAULT_REQUEST_BODY_LIMIT => 16777216; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use constant DEFAULT_REQUEST_BODY_BUFFER => 262144; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use constant DEFAULT_RESPONSE_BODY_BUFFER => 131072; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | our @EXPORT = 'cgi'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # List from HTTP::Status 6.46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Unmarked codes are from RFC 7231 (2017-12-20) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | my %HTTP_STATUS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 100 => 'Continue', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 101 => 'Switching Protocols', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 102 => 'Processing', # RFC 2518: WebDAV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 103 => 'Early Hints', # RFC 8297: Indicating Hints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 200 => 'OK', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 201 => 'Created', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 202 => 'Accepted', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 203 => 'Non-Authoritative Information', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 204 => 'No Content', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 205 => 'Reset Content', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 206 => 'Partial Content', # RFC 7233: Range Requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 207 => 'Multi-Status', # RFC 4918: WebDAV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 208 => 'Already Reported', # RFC 5842: WebDAV bindings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 226 => 'IM Used', # RFC 3229: Delta encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 300 => 'Multiple Choices', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 301 => 'Moved Permanently', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 302 => 'Found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 303 => 'See Other', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 304 => 'Not Modified', # RFC 7232: Conditional Request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 305 => 'Use Proxy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 307 => 'Temporary Redirect', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 308 => 'Permanent Redirect', # RFC 9110: HTTP Semantics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 400 => 'Bad Request', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 401 => 'Unauthorized', # RFC 7235: Authentication | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 402 => 'Payment Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 403 => 'Forbidden', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 404 => 'Not Found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 405 => 'Method Not Allowed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 406 => 'Not Acceptable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 407 => 'Proxy Authentication Required', # RFC 7235: Authentication | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 408 => 'Request Timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 409 => 'Conflict', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 410 => 'Gone', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 411 => 'Length Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 412 => 'Precondition Failed', # RFC 7232: Conditional Request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 413 => 'Content Too Large', # RFC 9110: HTTP Semantics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 414 => 'URI Too Long', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 415 => 'Unsupported Media Type', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 416 => 'Range Not Satisfiable', # RFC 7233: Range Requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 417 => 'Expectation Failed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 418 => 'I\'m a teapot', # RFC 2324: HTCPC/1.0 1-april | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 421 => 'Misdirected Request', # RFC 9110: HTTP Semantics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 422 => 'Unprocessable Content', # RFC 9110: HTTP Semantics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 423 => 'Locked', # RFC 4918: WebDAV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 424 => 'Failed Dependency', # RFC 4918: WebDAV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 425 => 'Too Early', # RFC 8470: Using Early Data in HTTP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 426 => 'Upgrade Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 428 => 'Precondition Required', # RFC 6585: Additional Codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 429 => 'Too Many Requests', # RFC 6585: Additional Codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 431 => 'Request Header Fields Too Large', # RFC 6585: Additional Codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 451 => 'Unavailable For Legal Reasons', # RFC 7725: Legal Obstacles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 500 => 'Internal Server Error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 501 => 'Not Implemented', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 502 => 'Bad Gateway', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 503 => 'Service Unavailable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 504 => 'Gateway Timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 505 => 'HTTP Version Not Supported', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 506 => 'Variant Also Negotiates', # RFC 2295: Transparant Ngttn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 507 => 'Insufficient Storage', # RFC 4918: WebDAV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 508 => 'Loop Detected', # RFC 5842: WebDAV bindings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 509 => 'Bandwidth Limit Exceeded', # Apache / cPanel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 510 => 'Not Extended', # RFC 2774: Extension Framework | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 511 => 'Network Authentication Required', # RFC 6585: Additional Codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | my $cgi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # for cleanup in END in case of premature exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | $cgi ||= bless {pid => $$}, $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cgi ||= bless({"pid", $$}, $_[0])
MC/DC0%0/1
$cgi ||= bless({"pid", $$}, $_[0])
$cgi
Truth table50%1/2
A
A= $cgi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | goto &Exporter::import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 75 | ▶ | sub cgi (&) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgi: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 75 | my ($handler) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 75 | ▶ | $cgi ||= bless {pid => $$}, __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cgi ||= bless({"pid", $$}, __PACKAGE__)
MC/DC100%1/1
$cgi ||= bless({"pid", $$}, __PACKAGE__)
$cgi
Truth table100%2/2
A
A= $cgi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 75 | ▶ | if (@ARGV and !defined $ENV{REQUEST_METHOD}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@ARGV and not defined $ENV{"REQUEST_METHOD"}
MC/DC0%0/2
@ARGV and not defined $ENV{"REQUEST_METHOD"}
@ARGV
not defined $ENV{"REQUEST_METHOD"}
Truth table33%1/3
A and not(B)
A= @ARGVB= not defined $ENV{"REQUEST_METHOD"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | require CGI::Tiny::_Debug; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | CGI::Tiny::_Debug::debug_command($cgi, [@ARGV]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 75 | my ($error, $errored); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 75 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 75 | ▶ | eval { local $_ = $cgi; $handler->(); 1 } or do { $error = $@; $errored = 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 73 | ▶ | if ($errored) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | _handle_error($cgi, $error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } elsif (!$cgi->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 20 | _handle_error($cgi, "cgi completed without rendering a response\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 73 | undef $cgi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 73 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # cleanup of premature exit, more reliable than potentially doing this in global destruction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # ModPerl::Registry or CGI::Compile won't run END after each request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # but they override exit to throw an exception which we handle already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | ▶ | if (defined $cgi) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | _handle_error($cgi, "cgi exited without rendering a response\n") unless $cgi->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | undef $cgi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ▶ | sub _handle_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_error: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 33 | my ($cgi, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 33 | ▶ | return unless $cgi->{pid} == $$; # in case of fork | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $cgi->{response_status} = "500 $HTTP_STATUS{500}" unless $cgi->{headers_rendered} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 32 | ▶ | or (defined $cgi->{response_status} and $cgi->{response_status} =~ m/^[45][0-9]{2} /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$cgi->{"headers_rendered"} or defined $cgi->{"response_status"} and $cgi->{"response_status"} =~ /^[45][0-9]{2} /
defined $cgi->{"response_status"} and $cgi->{"response_status"} =~ /^[45][0-9]{2} /
MC/DC100%3/3
$cgi->{"headers_rendered"} or defined $cgi->{"response_status"} and $cgi->{"response_status"} =~ /^[45][0-9]{2} /
$cgi->{"headers_rendered"}
defined $cgi->{"response_status"}
$cgi->{"response_status"} =~ /^[45][0-9]{2} /
Truth table100%4/4
A or B and C
A= $cgi->{"headers_rendered"}B= defined $cgi->{"response_status"}C= $cgi->{"response_status"} =~ /^[45][0-9]{2} /
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 32 | ▶ | if (defined(my $handler = $cgi->{on_error})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 30 | my ($error_error, $error_errored); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 30 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | eval { $handler->($cgi, $error, !!$cgi->{headers_rendered}); 1 } or do { $error_error = $@; $error_errored = 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 30 | ▶ | return unless $cgi->{pid} == $$; # in case of fork in error handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 30 | ▶ | if ($error_errored) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | warn "Exception in error handler: $error_error"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | warn "Original error: $error"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | warn $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 32 | ▶ | $cgi->set_response_type('text/plain')->render(data => $cgi->{response_status}) unless $cgi->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 30 | ▶ | sub set_error_handler { $_[0]{on_error} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_error_handler: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub set_request_body_buffer { $_[0]{request_body_buffer} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_request_body_buffer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | sub set_request_body_limit { $_[0]{request_body_limit} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_request_body_limit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | sub set_multipart_form_options { $_[0]{multipart_form_options} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_multipart_form_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | sub set_multipart_form_charset { $_[0]{multipart_form_charset} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_multipart_form_charset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 75 | ▶ | sub set_input_handle { $_[0]{input_handle} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_input_handle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 75 | ▶ | sub set_output_handle { $_[0]{output_handle} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_output_handle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | sub auth_type { defined $ENV{AUTH_TYPE} ? $ENV{AUTH_TYPE} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_type: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub content_length { defined $ENV{CONTENT_LENGTH} ? $ENV{CONTENT_LENGTH} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_length: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | sub content_type { defined $ENV{CONTENT_TYPE} ? $ENV{CONTENT_TYPE} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_type: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | sub gateway_interface { defined $ENV{GATEWAY_INTERFACE} ? $ENV{GATEWAY_INTERFACE} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gateway_interface: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | sub path_info { defined $ENV{PATH_INFO} ? $ENV{PATH_INFO} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_info: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | *path = \&path_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub path_translated { defined $ENV{PATH_TRANSLATED} ? $ENV{PATH_TRANSLATED} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_translated: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | ▶ | sub query_string { defined $ENV{QUERY_STRING} ? $ENV{QUERY_STRING} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_string: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | *query = \&query_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | sub remote_addr { defined $ENV{REMOTE_ADDR} ? $ENV{REMOTE_ADDR} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_addr: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | sub remote_host { defined $ENV{REMOTE_HOST} ? $ENV{REMOTE_HOST} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_host: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | sub remote_ident { defined $ENV{REMOTE_IDENT} ? $ENV{REMOTE_IDENT} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_ident: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | sub remote_user { defined $ENV{REMOTE_USER} ? $ENV{REMOTE_USER} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_user: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | ▶ | sub request_method { defined $ENV{REQUEST_METHOD} ? $ENV{REQUEST_METHOD} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_method: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | *method = \&request_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | sub script_name { defined $ENV{SCRIPT_NAME} ? $ENV{SCRIPT_NAME} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script_name: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | sub server_name { defined $ENV{SERVER_NAME} ? $ENV{SERVER_NAME} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_name: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | sub server_port { defined $ENV{SERVER_PORT} ? $ENV{SERVER_PORT} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_port: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | sub server_protocol { defined $ENV{SERVER_PROTOCOL} ? $ENV{SERVER_PROTOCOL} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_protocol: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub server_software { defined $ENV{SERVER_SOFTWARE} ? $ENV{SERVER_SOFTWARE} : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_software: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | sub headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | unless (exists $self->{request_headers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | my %headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | foreach my $key (keys %ENV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 54 | my $name = $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 54 | ▶ | next unless $name =~ s/^HTTP_//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | $name =~ tr/_/-/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | $headers{lc $name} = $ENV{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $self->{request_headers} = \%headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | return {%{$self->{request_headers}}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | ▶ | sub header { (my $name = $_[1]) =~ tr/-/_/; $ENV{"HTTP_\U$name"} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | sub cookies { [map { [@$_] } @{$_[0]->_cookies->{ordered}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookies: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | ▶ | sub cookie_names { [@{$_[0]->_cookies->{names}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookie_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | sub cookie { my $c = $_[0]->_cookies->{keyed}; exists $c->{$_[1]} ? $c->{$_[1]}[-1] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookie: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | sub cookie_array { my $c = $_[0]->_cookies->{keyed}; exists $c->{$_[1]} ? [@{$c->{$_[1]}}] : [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookie_array: called CC=2 SCAR=7.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | ▶ | sub _cookies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cookies: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | ▶ | unless (exists $self->{request_cookies}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | $self->{request_cookies} = {names => \my @names, ordered => \my @ordered, keyed => \my %keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | ▶ | if (defined $ENV{HTTP_COOKIE}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | foreach my $pair (split /\s*;\s*/, $ENV{HTTP_COOKIE}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | ▶ | next unless length $pair; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | my ($name, $value) = split /=/, $pair, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | push @names, $name unless exists $keyed{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | push @ordered, [$name, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | push @{$keyed{$name}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | return $self->{request_cookies}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | sub params { [map { [@$_] } @{$_[0]->_query_params->{ordered}}, @{$_[0]->_body_params->{ordered}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | sub param_names { my $q = $_[0]->_query_params; [@{$q->{names}}, grep { !exists $q->{keyed}{$_} } @{$_[0]->_body_params->{names}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | sub param { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | my $p = $self->_body_params->{keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | ▶ | return $p->{$name}[-1] if exists $p->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | my $q = $self->_query_params->{keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | return exists $q->{$name} ? $q->{$name}[-1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | sub param_array { [map { exists $_->{$_[1]} ? @{$_->{$_[1]}} : () } $_[0]->_query_params->{keyed}, $_[0]->_body_params->{keyed}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param_array: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | sub query_params { [map { [@$_] } @{$_[0]->_query_params->{ordered}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | ▶ | sub query_param_names { [@{$_[0]->_query_params->{names}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_param_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | ▶ | sub query_param { my $p = $_[0]->_query_params->{keyed}; exists $p->{$_[1]} ? $p->{$_[1]}[-1] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_param: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | sub query_param_array { my $p = $_[0]->_query_params->{keyed}; exists $p->{$_[1]} ? [@{$p->{$_[1]}}] : [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_param_array: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 13 | ▶ | sub _query_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_query_params: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 13 | ▶ | unless (exists $self->{query_params}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | $self->{query_params} = {names => \my @names, ordered => \my @ordered, keyed => \my %keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | foreach my $pair (split /[&;]/, $self->query) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 10 | my ($name, $value) = split /=/, $pair, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 10 | ▶ | $value = '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | do { tr/+/ /; s/%([0-9a-fA-F]{2})/chr hex $1/ge; utf8::decode $_ } for $name, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 10 | ▶ | push @names, $name unless exists $keyed{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | push @ordered, [$name, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 10 | push @{$keyed{$name}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 13 | return $self->{query_params}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | ▶ | sub body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=9 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | ▶ | unless (exists $self->{body_content} or exists $self->{body_parts}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"body_content"} or exists $self->{"body_parts"}
MC/DC0%0/2
exists $self->{"body_content"} or exists $self->{"body_parts"}
exists $self->{"body_content"}
exists $self->{"body_parts"}
Truth table33%1/3
A or B
A= exists $self->{"body_content"}B= exists $self->{"body_parts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | $self->{body_content} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my $length = $self->_body_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | ▶ | my $in_fh = defined $self->{input_handle} ? $self->{input_handle} : *STDIN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | binmode $in_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | ▶ | my $buffer_size = 0 + ($self->{request_body_buffer} || $ENV{CGI_TINY_REQUEST_BODY_BUFFER} || DEFAULT_REQUEST_BODY_BUFFER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{'request_body_buffer'} || $ENV{'CGI_TINY_REQUEST_BODY_BUFFER'} || 262144
$self->{"request_body_buffer"} or $ENV{"CGI_TINY_REQUEST_BODY_BUFFER"}
MC/DC0%0/2
$self->{'request_body_buffer'} || $ENV{'CGI_TINY_REQUEST_BODY_BUFFER'} || 262144
$self->{"request_body_buffer"}
$ENV{"CGI_TINY_REQUEST_BODY_BUFFER"}
Truth table33%1/3
A or B
A= $self->{"request_body_buffer"}B= $ENV{"CGI_TINY_REQUEST_BODY_BUFFER"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | ▶ | while ($length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | ▶ | my $chunk = $length < $buffer_size ? $length : $buffer_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 5 | ▶ | last unless my $read = read $in_fh, $self->{body_content}, $chunk, length $self->{body_content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 5 | $length -= $read; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | return $self->{body_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 4 | ▶ | sub body_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_json: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | unless (exists $self->{body_json}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | $self->{body_json} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | ▶ | if ($ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^application\/json\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^application/json\b]i
MC/DC50%1/2
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^application/json\b]i
$ENV{"CONTENT_TYPE"}
$ENV{"CONTENT_TYPE"} =~ m[^application/json\b]i
Truth table66%2/3
A and B
A= $ENV{"CONTENT_TYPE"}B= $ENV{"CONTENT_TYPE"} =~ m[^application/json\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | $self->{body_json} = $self->_json->decode($self->body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | return $self->{body_json}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 8 | ▶ | sub body_params { [map { [@$_] } @{$_[0]->_body_params->{ordered}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 7 | ▶ | sub body_param_names { [@{$_[0]->_body_params->{names}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_param_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 8 | ▶ | sub body_param { my $p = $_[0]->_body_params->{keyed}; exists $p->{$_[1]} ? $p->{$_[1]}[-1] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_param: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | ▶ | sub body_param_array { my $p = $_[0]->_body_params->{keyed}; exists $p->{$_[1]} ? [@{$p->{$_[1]}}] : [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_param_array: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 37 | ▶ | sub _body_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_params: called CC=26 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 37 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 37 | ▶ | unless (exists $self->{body_params}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 9 | $self->{body_params} = {names => \my @names, ordered => \my @ordered, keyed => \my %keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 9 | ▶ | if ($ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^application\/x-www-form-urlencoded\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded\b]i
MC/DC100%2/2
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded\b]i
$ENV{"CONTENT_TYPE"}
$ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded\b]i
Truth table100%3/3
A and B
A= $ENV{"CONTENT_TYPE"}B= $ENV{"CONTENT_TYPE"} =~ m[^application/x-www-form-urlencoded\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | foreach my $pair (split /&/, $self->body) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | my ($name, $value) = split /=/, $pair, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | ▶ | $value = '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 8 | do { tr/+/ /; s/%([0-9a-fA-F]{2})/chr hex $1/ge; utf8::decode $_ } for $name, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 8 | ▶ | push @names, $name unless exists $keyed{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 8 | push @ordered, [$name, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 8 | push @{$keyed{$name}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ▶ | } elsif ($ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^multipart\/form-data\b/i) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
MC/DC50%1/2
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
$ENV{"CONTENT_TYPE"}
$ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
Truth table66%2/3
A and B
A= $ENV{"CONTENT_TYPE"}B= $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 6 | my $default_charset = $self->{multipart_form_charset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | $default_charset = 'UTF-8' unless defined $default_charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | foreach my $part (@{$self->_body_multipart}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 18 | ▶ | next if defined $part->{filename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 10 | my ($name, $headers, $content, $file) = @$part{'name','headers','content','file'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 10 | ▶ | if (length $default_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 10 | $name = Encode::decode($default_charset, "$name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 10 | my $value = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 10 | ▶ | if (defined $content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 9 | $value = $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } elsif (defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | binmode $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | seek $file, 0, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $value = do { local $/; readline $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | seek $file, 0, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 10 | my $value_charset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 10 | ▶ | if (defined $headers->{'content-type'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | ▶ | if (my ($charset_quoted, $charset_unquoted) = $headers->{'content-type'} =~ m/;\s*charset=(?:"((?:\\[\\"]|[^"])+)"|([^";]+))/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | ▶ | $charset_quoted =~ s/\\([\\"])/$1/g if defined $charset_quoted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 5 | ▶ | $value_charset = defined $charset_quoted ? $charset_quoted : $charset_unquoted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 10 | ▶ | if (defined $value_charset or !defined $headers->{'content-type'} or $headers->{'content-type'} =~ m/^text\/plain\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $value_charset or not defined $headers->{"content-type"} or $headers->{"content-type"} =~ m[^text/plain\b]i
defined $value_charset or not defined $headers->{"content-type"}
MC/DC0%0/3
defined $value_charset or not defined $headers->{"content-type"} or $headers->{"content-type"} =~ m[^text/plain\b]i
defined $value_charset
not defined $headers->{"content-type"}
$headers->{"content-type"} =~ m[^text/plain\b]i
Truth table50%2/4
A or not(B) or C
A= defined $value_charsetB= not defined $headers->{"content-type"}C= $headers->{"content-type"} =~ m[^text/plain\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 10 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 10 | ▶ | if (defined $value_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | $value = Encode::decode($value_charset, "$value"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } elsif (length $default_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | $value = Encode::decode($default_charset, "$value"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 10 | ▶ | push @names, $name unless exists $keyed{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 10 | push @ordered, [$name, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 10 | push @{$keyed{$name}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 37 | return $self->{body_params}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 9 | ▶ | sub body_parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_parts: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 9 | ▶ | return [] unless $ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^multipart\/form-data\b/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
MC/DC50%1/2
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
$ENV{"CONTENT_TYPE"}
$ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
Truth table66%2/3
A and B
A= $ENV{"CONTENT_TYPE"}B= $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 8 | return [map { +{%$_} } @{$self->_body_multipart}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 6 | ▶ | sub uploads { [map { [@$_] } @{$_[0]->_body_uploads->{ordered}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uploads: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 6 | ▶ | sub upload_names { [@{$_[0]->_body_uploads->{names}}] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 7 | ▶ | sub upload { my $u = $_[0]->_body_uploads->{keyed}; exists $u->{$_[1]} ? $u->{$_[1]}[-1] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 6 | ▶ | sub upload_array { my $u = $_[0]->_body_uploads->{keyed}; exists $u->{$_[1]} ? [@{$u->{$_[1]}}] : [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_array: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 25 | ▶ | sub _body_uploads { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_uploads: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 25 | ▶ | unless (exists $self->{body_uploads}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 6 | $self->{body_uploads} = {names => \my @names, ordered => \my @ordered, keyed => \my %keyed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 6 | ▶ | if ($ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^multipart\/form-data\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
MC/DC0%0/2
$ENV{"CONTENT_TYPE"} and $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
$ENV{"CONTENT_TYPE"}
$ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
Truth table33%1/3
A and B
A= $ENV{"CONTENT_TYPE"}B= $ENV{"CONTENT_TYPE"} =~ m[^multipart/form-data\b]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 6 | my $default_charset = $self->{multipart_form_charset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 6 | ▶ | $default_charset = 'UTF-8' unless defined $default_charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 6 | foreach my $part (@{$self->_body_multipart}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 18 | ▶ | next unless defined $part->{filename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 8 | my ($name, $filename, $size, $headers, $file, $content) = @$part{'name','filename','size','headers','file','content'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 8 | ▶ | if (length $default_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 8 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 8 | $name = Encode::decode($default_charset, "$name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 8 | $filename = Encode::decode($default_charset, "$filename"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | my $upload = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | size => $size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | content_type => $headers->{'content-type'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 8 | ▶ | $upload->{file} = $file if defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 8 | ▶ | $upload->{content} = $content if defined $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 8 | ▶ | push @names, $name unless exists $keyed{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | push @ordered, [$name, $upload]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | push @{$keyed{$name}}, $upload; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 25 | return $self->{body_uploads}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 12 | ▶ | sub _body_length { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_length: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 12 | my $limit = $self->{request_body_limit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | ▶ | $limit = $ENV{CGI_TINY_REQUEST_BODY_LIMIT} unless defined $limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | ▶ | $limit = DEFAULT_REQUEST_BODY_LIMIT unless defined $limit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 12 | ▶ | my $length = $ENV{CONTENT_LENGTH} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'CONTENT_LENGTH'} || 0
MC/DC0%0/1
$ENV{'CONTENT_LENGTH'} || 0
$ENV{'CONTENT_LENGTH'}
Truth table50%1/2
A
A= $ENV{'CONTENT_LENGTH'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | ▶ | if ($limit and $length > $limit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$limit and $length > $limit
MC/DC50%1/2
$limit and $length > $limit
$limit
$length > $limit
Truth table66%2/3
A and B
A= $limitB= $length > $limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | ▶ | $self->{response_status} = "413 $HTTP_STATUS{413}" unless $self->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | die "Request body limit exceeded\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 11 | return 0 + $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 20 | ▶ | sub _body_multipart { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_multipart: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 20 | ▶ | unless (exists $self->{body_parts}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | $self->{body_parts} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 8 | require CGI::Tiny::Multipart; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 8 | my $boundary = CGI::Tiny::Multipart::extract_multipart_boundary($ENV{CONTENT_TYPE}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 8 | ▶ | unless (defined $boundary) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | $self->{response_status} = "400 $HTTP_STATUS{400}" unless $self->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | die "Malformed multipart/form-data request\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 7 | my ($input, $length); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 7 | ▶ | if (exists $self->{body_content}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | $length = length $self->{body_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | $input = \$self->{body_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | $length = $self->_body_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | ▶ | $input = defined $self->{input_handle} ? $self->{input_handle} : *STDIN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | my $parts = CGI::Tiny::Multipart::parse_multipart_form_data($input, $length, $boundary, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | buffer_size => $self->{request_body_buffer} || $ENV{CGI_TINY_REQUEST_BODY_BUFFER}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 7 | ▶ | %{$self->{multipart_form_options} || {}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$self->{'request_body_buffer'} || $ENV{'CGI_TINY_REQUEST_BODY_BUFFER'}
$self->{'multipart_form_options'} || {}
MC/DC0%0/2
$self->{'request_body_buffer'} || $ENV{'CGI_TINY_REQUEST_BODY_BUFFER'}
$self->{'request_body_buffer'}
$ENV{'CGI_TINY_REQUEST_BODY_BUFFER'}
MC/DC100%1/1
$self->{'multipart_form_options'} || {}
$self->{'multipart_form_options'}
Truth table33%1/3
A || B
A= $self->{'request_body_buffer'}B= $ENV{'CGI_TINY_REQUEST_BODY_BUFFER'}
Truth table100%2/2
A
A= $self->{'multipart_form_options'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 7 | ▶ | unless (defined $parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | ▶ | $self->{response_status} = "400 $HTTP_STATUS{400}" unless $self->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | die "Malformed multipart/form-data request\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 6 | $self->{body_parts} = $parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 18 | return $self->{body_parts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | ▶ | sub set_nph { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_nph: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 2 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | Carp::carp "Attempted to set NPH response mode but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | ▶ | $self->{nph} = @_ < 2 ? 1 : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub set_response_body_buffer { $_[0]{response_body_buffer} = $_[1]; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_response_body_buffer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 15 | ▶ | sub set_response_status { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_response_status: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 15 | my ($self, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 15 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | Carp::carp "Attempted to set HTTP response status but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 15 | ▶ | if (defined $status and $status =~ m/\A[0-9]+ [^\r\n]*\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $status and $status =~ /\A[0-9]+ [^\r\n]*\z/
MC/DC50%1/2
defined $status and $status =~ /\A[0-9]+ [^\r\n]*\z/
defined $status
$status =~ /\A[0-9]+ [^\r\n]*\z/
Truth table66%2/3
A and B
A= defined $statusB= $status =~ /\A[0-9]+ [^\r\n]*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | $self->{response_status} = $status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } elsif (defined $status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 14 | ▶ | Carp::croak "Attempted to set unknown HTTP response status $status" unless exists $HTTP_STATUS{$status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 13 | $self->{response_status} = "$status $HTTP_STATUS{$status}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | delete $self->{response_status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 7 | my %DISPOSITIONS = (attachment => 1, inline => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | ▶ | sub set_response_disposition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_response_disposition: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | my ($self, $disposition, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | Carp::carp "Attempted to set HTTP response content disposition but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | ▶ | Carp::croak "Attempted to set unknown Content-Disposition value '$disposition'" unless exists $DISPOSITIONS{lc $disposition}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | $self->{response_disposition} = $disposition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # filename will be quoted/escaped later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | $self->{response_filename} = $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 7 | ▶ | sub set_response_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_response_type: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 36 | my ($self, $content_type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 36 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | Carp::carp "Attempted to set HTTP response content type but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 36 | ▶ | Carp::croak "Newline characters not allowed in HTTP response content type" if defined $content_type and $content_type =~ tr/\r\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $content_type and $content_type =~ tr/\n\r//
MC/DC0%0/2
defined $content_type and $content_type =~ tr/\n\r//
defined $content_type
$content_type =~ tr/\n\r//
Truth table66%2/3
A and B
A= defined $content_typeB= $content_type =~ tr/\n\r//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 36 | $self->{response_type} = $content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 36 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 2 | ▶ | sub set_response_charset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_response_charset: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 2 | my ($self, $charset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | ▶ | Carp::croak "Invalid characters in HTTP response charset" if defined $charset and $charset =~ m/[^a-zA-Z0-9!#\$%&'*+\-.^_`|~]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $charset and $charset =~ /[^a-zA-Z0-9!#\$%&'*+\-.^_`|~]/
MC/DC0%0/2
defined $charset and $charset =~ /[^a-zA-Z0-9!#\$%&'*+\-.^_`|~]/
defined $charset
$charset =~ /[^a-zA-Z0-9!#\$%&'*+\-.^_`|~]/
Truth table33%1/3
A and B
A= defined $charsetB= $charset =~ /[^a-zA-Z0-9!#\$%&'*+\-.^_`|~]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | $self->{response_charset} = $charset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | ▶ | sub add_response_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_response_header: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | Carp::carp "Attempted to add HTTP response header '$name' but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | ▶ | Carp::croak "Newline characters not allowed in HTTP response header '$name'" if $value =~ tr/\r\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | push @{$self->{response_headers}}, [$name, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 7 | my %COOKIE_ATTR_VALUE = (expires => 1, domain => 1, path => 1, secure => 0, httponly => 0, samesite => 1, 'max-age' => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 3 | ▶ | sub add_response_cookie { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_response_cookie: called CC=8 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 3 | my ($self, $name, $value, @attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 3 | ▶ | if ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | Carp::carp "Attempted to add HTTP response cookie '$name' but headers have already been rendered"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 3 | my $cookie_str = "$name=$value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 3 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 3 | ▶ | while ($i <= $#attrs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 10 | my ($key, $val) = @attrs[$i, $i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 10 | my $has_value = $COOKIE_ATTR_VALUE{lc $key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 10 | ▶ | if (!defined $has_value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | Carp::croak "Attempted to set unknown cookie attribute '$key' for HTTP response cookie '$name'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } elsif ($has_value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 6 | ▶ | $cookie_str .= "; $key=$val" if defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 4 | ▶ | $cookie_str .= "; $key" if $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } continue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 10 | $i += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 3 | ▶ | Carp::croak "Newline characters not allowed in HTTP response cookie '$name'" if $cookie_str =~ tr/\r\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | push @{$self->{response_headers}}, ['Set-Cookie', $cookie_str]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | ▶ | sub reset_response_headers { delete $_[0]{response_headers}; $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_response_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 15 | ▶ | sub response_status_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_status_code: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 15 | ▶ | if (defined $self->{response_status} and $self->{response_status} =~ m/\A([0-9]+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"response_status"} and $self->{"response_status"} =~ /\A([0-9]+)/
MC/DC0%0/2
defined $self->{"response_status"} and $self->{"response_status"} =~ /\A([0-9]+)/
defined $self->{"response_status"}
$self->{"response_status"} =~ /\A([0-9]+)/
Truth table33%1/3
A and B
A= defined $self->{"response_status"}B= $self->{"response_status"} =~ /\A([0-9]+)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 15 | return 0+$1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | return 200; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 7 | my %RENDER_TYPES = (text => 1, html => 1, xml => 1, json => 1, data => 1, file => 1, handle => 1, redirect => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 65 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=28 SCAR=33.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 65 | my ($self, $type, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 65 | ▶ | Carp::croak "Cannot render additional data with ->render; use ->render_chunk" if $self->{headers_rendered}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 65 | ▶ | $type = '' unless defined $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 65 | ▶ | Carp::croak "Don't know how to render '$type'" if length $type and !exists $RENDER_TYPES{$type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $type and not exists $RENDER_TYPES{$type}
MC/DC0%0/2
length $type and not exists $RENDER_TYPES{$type}
length $type
not exists $RENDER_TYPES{$type}
Truth table66%2/3
A and not(B)
A= length $typeB= not exists $RENDER_TYPES{$type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 65 | ▶ | Carp::croak "Cannot render from an open filehandle with ->render; use ->render_chunk" if $type eq 'handle'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 65 | my ($response_body, $response_length, $redirect_url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 65 | ▶ | if ($type eq 'redirect') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 3 | ▶ | Carp::croak "Newline characters not allowed in HTTP redirect" if $data =~ tr/\r\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 3 | $redirect_url = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ▶ | } elsif (uc($ENV{REQUEST_METHOD} || '') eq 'HEAD') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'REQUEST_METHOD'} || ''
MC/DC100%1/1
$ENV{'REQUEST_METHOD'} || ''
$ENV{'REQUEST_METHOD'}
Truth table100%2/2
A
A= $ENV{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # no response content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | ▶ | } elsif ($type eq 'text' or $type eq 'html' or $type eq 'xml') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$type eq "text" or $type eq "html" or $type eq "xml"
$type eq "text" or $type eq "html"
MC/DC100%3/3
$type eq "text" or $type eq "html" or $type eq "xml"
$type eq "text"
$type eq "html"
$type eq "xml"
Truth table100%4/4
A or B or C
A= $type eq "text"B= $type eq "html"C= $type eq "xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 5 | my $charset = $self->{response_charset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 5 | ▶ | $charset = 'UTF-8' unless defined $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 5 | ▶ | if (uc $charset eq 'UTF-8' and do { local $@; eval { require Unicode::UTF8; 1 } }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
uc $charset eq "UTF-8" and do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
MC/DC50%1/2
uc $charset eq "UTF-8" and do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
uc $charset eq "UTF-8"
do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
Truth table66%2/3
A and B
A= uc $charset eq "UTF-8"B= do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 4 | $response_body = Unicode::UTF8::encode_utf8($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | $response_body = Encode::encode($charset, "$data"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 5 | $response_length = length $response_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } elsif ($type eq 'json') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | $response_body = $self->_json->encode($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $response_length = length $response_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } elsif ($type eq 'data') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 32 | $response_body = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 32 | $response_length = length $response_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } elsif ($type eq 'file') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | $response_length = -s $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | ▶ | Carp::croak "Failed to retrieve size of file '$data': $!" unless defined $response_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 65 | ▶ | $response_length = 0 unless defined $response_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 65 | my $headers_str = $self->_response_headers($type, $response_length, $redirect_url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 65 | ▶ | my $out_fh = defined $self->{output_handle} ? $self->{output_handle} : *STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 65 | binmode $out_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 65 | $out_fh->printflush($headers_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 65 | $self->{headers_rendered} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 65 | $self->{response_fixed_length} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 65 | ▶ | return $self unless $response_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 38 | ▶ | if ($type eq 'file') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1 | ▶ | open my $in_fh, '<', $data or Carp::croak "Failed to open file '$data' for rendering: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | binmode $in_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | ▶ | my $buffer_size = 0 + ($self->{response_body_buffer} || $ENV{CGI_TINY_RESPONSE_BODY_BUFFER} || DEFAULT_RESPONSE_BODY_BUFFER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{'response_body_buffer'} || $ENV{'CGI_TINY_RESPONSE_BODY_BUFFER'} || 131072
$self->{"response_body_buffer"} or $ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
MC/DC0%0/2
$self->{'response_body_buffer'} || $ENV{'CGI_TINY_RESPONSE_BODY_BUFFER'} || 131072
$self->{"response_body_buffer"}
$ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
Truth table33%1/3
A or B
A= $self->{"response_body_buffer"}B= $ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | while (read $in_fh, my $buffer, $buffer_size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | $out_fh->print($buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | $out_fh->flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 37 | $out_fh->printflush($response_body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 38 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 17 | ▶ | sub render_chunk { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_chunk: called CC=25 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 17 | my ($self, $type, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 17 | ▶ | Carp::croak "Cannot render additional data after ->render" if $self->{response_fixed_length}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 17 | ▶ | $type = '' unless defined $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 17 | ▶ | Carp::croak "Don't know how to render '$type'" if length $type and !exists $RENDER_TYPES{$type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $type and not exists $RENDER_TYPES{$type}
MC/DC0%0/2
length $type and not exists $RENDER_TYPES{$type}
length $type
not exists $RENDER_TYPES{$type}
Truth table66%2/3
A and not(B)
A= length $typeB= not exists $RENDER_TYPES{$type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 17 | ▶ | Carp::croak "Cannot render a chunked redirect" if $type eq 'redirect'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 17 | ▶ | my $out_fh = defined $self->{output_handle} ? $self->{output_handle} : *STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 17 | ▶ | unless ($self->{headers_rendered}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 12 | my $headers_str = $self->_response_headers($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 12 | binmode $out_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 12 | $out_fh->printflush($headers_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 12 | $self->{headers_rendered} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 17 | ▶ | if (uc($ENV{REQUEST_METHOD} || '') eq 'HEAD') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition50%1/2
$ENV{'REQUEST_METHOD'} || ''
MC/DC0%0/1
$ENV{'REQUEST_METHOD'} || ''
$ENV{'REQUEST_METHOD'}
Truth table50%1/2
A
A= $ENV{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # no response content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | ▶ | } elsif ($type eq 'text' or $type eq 'html' or $type eq 'xml') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$type eq "text" or $type eq "html" or $type eq "xml"
$type eq "text" or $type eq "html"
MC/DC66%2/3
$type eq "text" or $type eq "html" or $type eq "xml"
$type eq "text"
$type eq "html"
$type eq "xml"
Truth table75%3/4
A or B or C
A= $type eq "text"B= $type eq "html"C= $type eq "xml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 4 | my $charset = $self->{response_charset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 4 | ▶ | $charset = 'UTF-8' unless defined $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 4 | my $response_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 4 | ▶ | if (uc $charset eq 'UTF-8' and do { local $@; eval { require Unicode::UTF8; 1 } }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
uc $charset eq "UTF-8" and do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
MC/DC50%1/2
uc $charset eq "UTF-8" and do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
uc $charset eq "UTF-8"
do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
Truth table66%2/3
A and B
A= uc $charset eq "UTF-8"B= do {
local $@;
eval {
do {
require Unicode::UTF8;
1
}
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 3 | $response_body = Unicode::UTF8::encode_utf8($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | $response_body = Encode::encode($charset, "$data"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 4 | $out_fh->printflush($response_body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } elsif ($type eq 'json') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 2 | my $response_body = $self->_json->encode($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 2 | $out_fh->printflush($response_body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } elsif ($type eq 'data') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 2 | $out_fh->printflush($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | ▶ | } elsif ($type eq 'file' or $type eq 'handle') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type eq "file" or $type eq "handle"
MC/DC100%2/2
$type eq "file" or $type eq "handle"
$type eq "file"
$type eq "handle"
Truth table100%3/3
A or B
A= $type eq "file"B= $type eq "handle"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | my $in_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 2 | ▶ | if ($type eq 'file') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | ▶ | open $in_fh, '<', $data or Carp::croak "Failed to open file '$data' for rendering: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | $in_fh = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 2 | binmode $in_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 2 | ▶ | my $buffer_size = 0 + ($self->{response_body_buffer} || $ENV{CGI_TINY_RESPONSE_BODY_BUFFER} || DEFAULT_RESPONSE_BODY_BUFFER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{'response_body_buffer'} || $ENV{'CGI_TINY_RESPONSE_BODY_BUFFER'} || 131072
$self->{"response_body_buffer"} or $ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
MC/DC0%0/2
$self->{'response_body_buffer'} || $ENV{'CGI_TINY_RESPONSE_BODY_BUFFER'} || 131072
$self->{"response_body_buffer"}
$ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
Truth table33%1/3
A or B
A= $self->{"response_body_buffer"}B= $ENV{"CGI_TINY_RESPONSE_BODY_BUFFER"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 2 | ▶ | while (read $in_fh, my $buffer, $buffer_size) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 2 | $out_fh->print($buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 2 | $out_fh->flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 17 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 7 | ▶ | sub _response_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_response_headers: called CC=38 SCAR=36.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 77 | my ($self, $type, $content_length, $location) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 77 | my $headers_str = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 77 | ▶ | return $headers_str if defined $self->{debug_method} and !$self->{debug_verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"debug_method"} and not $self->{"debug_verbose"}
MC/DC0%0/2
defined $self->{"debug_method"} and not $self->{"debug_verbose"}
defined $self->{"debug_method"}
not $self->{"debug_verbose"}
Truth table33%1/3
A and not(B)
A= defined $self->{"debug_method"}B= not $self->{"debug_verbose"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 77 | my %headers_set; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 77 | ▶ | foreach my $header (@{$self->{response_headers} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'response_headers'} || []
MC/DC100%1/1
$self->{'response_headers'} || []
$self->{'response_headers'}
Truth table100%2/2
A
A= $self->{'response_headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 4 | my ($name, $value) = @$header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 4 | $headers_str .= "$name: $value\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 4 | $headers_set{lc $name} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 77 | ▶ | if (!$headers_set{'content-length'} and defined $content_length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $headers_set{"content-length"} and defined $content_length
MC/DC50%1/2
not $headers_set{"content-length"} and defined $content_length
not $headers_set{"content-length"}
defined $content_length
Truth table66%2/3
not(A) and B
A= not $headers_set{"content-length"}B= defined $content_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 65 | $headers_str = "Content-Length: $content_length\r\n$headers_str"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 77 | ▶ | if (!$headers_set{'content-disposition'} and (defined $self->{response_disposition} or defined $self->{response_filename})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $headers_set{"content-disposition"} and defined $self->{"response_disposition"} || defined $self->{"response_filename"}
defined $self->{"response_disposition"} or defined $self->{"response_filename"}
MC/DC33%1/3
not $headers_set{"content-disposition"} and defined $self->{"response_disposition"} || defined $self->{"response_filename"}
not $headers_set{"content-disposition"}
defined $self->{"response_disposition"}
defined $self->{"response_filename"}
Truth table50%2/4
not(A) and B or C
A= not $headers_set{"content-disposition"}B= defined $self->{"response_disposition"}C= defined $self->{"response_filename"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 3 | ▶ | my $value = defined $self->{response_disposition} ? $self->{response_disposition} : 'inline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 3 | ▶ | if (defined(my $filename = $self->{response_filename})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 2 | my $quoted_filename = Encode::encode('ISO-8859-1', "$filename"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 2 | $quoted_filename =~ tr/\r\n/ /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 2 | $quoted_filename =~ s/([\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 2 | $value .= "; filename=\"$quoted_filename\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 2 | my $ext_filename = Encode::encode('UTF-8', "$filename"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 2 | $ext_filename =~ s/([^a-zA-Z0-9!#\$&+\-.^_`|~])/sprintf '%%%02X', ord $1/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 2 | $value .= "; filename*=UTF-8''$ext_filename"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 3 | ▶ | $headers_str = "Content-Disposition: $value\r\n$headers_str" unless lc $value eq 'inline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 77 | ▶ | if (!$headers_set{location} and $type eq 'redirect') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $headers_set{"location"} and $type eq "redirect"
MC/DC50%1/2
not $headers_set{"location"} and $type eq "redirect"
not $headers_set{"location"}
$type eq "redirect"
Truth table66%2/3
not(A) and B
A= not $headers_set{"location"}B= $type eq "redirect"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | $headers_str = "Location: $location\r\n$headers_str"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 77 | ▶ | if (!$headers_set{'content-type'} and $type ne 'redirect') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $headers_set{"content-type"} and $type ne "redirect"
MC/DC50%1/2
not $headers_set{"content-type"} and $type ne "redirect"
not $headers_set{"content-type"}
$type ne "redirect"
Truth table66%2/3
not(A) and B
A= not $headers_set{"content-type"}B= $type ne "redirect"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 74 | my $content_type = $self->{response_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 74 | my $charset = $self->{response_charset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 74 | ▶ | $charset = 'UTF-8' unless defined $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 74 | ▶ | $content_type = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%6/6
defined $content_type or defined $content_length and $content_length == 0
defined $content_length and $content_length == 0
MC/DC100%3/3
defined $content_type or defined $content_length and $content_length == 0
defined $content_type
defined $content_length
$content_length == 0
Truth table100%4/4
A or B and C
A= defined $content_typeB= defined $content_lengthC= $content_length == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | $type eq 'text' ? "text/plain;charset=$charset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | : $type eq 'html' ? "text/html;charset=$charset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | : $type eq 'xml' ? "application/xml;charset=$charset" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | : $type eq 'json' ? 'application/json;charset=UTF-8' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | : 'application/octet-stream' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | unless defined $content_type or (defined $content_length and $content_length == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 74 | ▶ | $headers_str = "Content-Type: $content_type\r\n$headers_str" if defined $content_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 77 | ▶ | if (!$headers_set{date}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 77 | my $date_str = epoch_to_date(time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 77 | $headers_str = "Date: $date_str\r\n$headers_str"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 77 | my $status = $self->{response_status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 77 | ▶ | $status = $self->{response_status} = "302 $HTTP_STATUS{302}" if $type eq 'redirect' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$type eq "redirect" and not defined $status && $status =~ /^3[0-9]{2} /
defined $status && $status =~ /^3[0-9]{2} /
MC/DC100%3/3
$type eq "redirect" and not defined $status && $status =~ /^3[0-9]{2} /
$type eq "redirect"
defined $status
$status =~ /^3[0-9]{2} /
Truth table100%4/4
A and not(B && C)
A= $type eq "redirect"B= defined $statusC= $status =~ /^3[0-9]{2} /
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | and !(defined $status and $status =~ m/^3[0-9]{2} /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 77 | ▶ | if ($self->{nph}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 2 | ▶ | $status = "200 $HTTP_STATUS{200}" unless defined $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 2 | my $protocol = $ENV{SERVER_PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | ▶ | $protocol = 'HTTP/1.0' unless defined $protocol and length $protocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $protocol and length $protocol
MC/DC0%0/2
defined $protocol and length $protocol
defined $protocol
length $protocol
Truth table33%1/3
A and B
A= defined $protocolB= length $protocol
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | $headers_str = "$protocol $status\r\n$headers_str"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | my $server = $ENV{SERVER_SOFTWARE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 2 | ▶ | $headers_str .= "Server: $server\r\n" if defined $server and length $server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $server and length $server
MC/DC50%1/2
defined $server and length $server
defined $server
length $server
Truth table66%2/3
A and B
A= defined $serverB= length $server
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | ▶ | } elsif (!$headers_set{status} and defined $status) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $headers_set{"status"} and defined $status
MC/DC50%1/2
not $headers_set{"status"} and defined $status
not $headers_set{"status"}
defined $status
Truth table66%2/3
not(A) and B
A= not $headers_set{"status"}B= defined $status
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 37 | $headers_str = "Status: $status\r\n$headers_str"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 77 | return "$headers_str\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 5 | ▶ | sub _json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 5 | ▶ | unless (exists $self->{json}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | ▶ | if (do { local $@; eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('4.09'); 1 } }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 3 | $self->{json} = Cpanel::JSON::XS->new->allow_dupkeys->stringify_infnan; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | require JSON::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | $self->{json} = JSON::PP->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 3 | $self->{json}->utf8->canonical->allow_nonref->allow_unknown->allow_blessed->convert_blessed->escape_slash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 5 | return $self->{json}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 7 | my @DAYS_OF_WEEK = qw(Sun Mon Tue Wed Thu Fri Sat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 7 | my @MONTH_NAMES = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 7 | my %MONTH_NUMS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 7 | @MONTH_NUMS{@MONTH_NAMES} = 0..11; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 79 | ▶ | sub epoch_to_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
epoch_to_date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 79 | my ($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 79 | return sprintf '%s, %02d %s %04d %02d:%02d:%02d GMT', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | $DAYS_OF_WEEK[$wday], $mday, $MONTH_NAMES[$mon], $year + 1900, $hour, $min, $sec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 19 | ▶ | sub date_to_epoch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date_to_epoch: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # RFC 1123 (Sun, 06 Nov 1994 08:49:37 GMT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 19 | my ($mday,$mon,$year,$hour,$min,$sec) = $_[0] =~ m/^ (?:Sun|Mon|Tue|Wed|Thu|Fri|Sat), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | [ ] ([0-9]{2}) [ ] (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ ] ([0-9]{4}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | [ ] ([0-9]{2}) : ([0-9]{2}) : ([0-9]{2}) [ ] GMT $/x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # RFC 850 (Sunday, 06-Nov-94 08:49:37 GMT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 19 | ▶ | ($mday,$mon,$year,$hour,$min,$sec) = $_[0] =~ m/^ (?:Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | [ ] ([0-9]{2}) - (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) - ([0-9]{2}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | [ ] ([0-9]{2}) : ([0-9]{2}) : ([0-9]{2}) [ ] GMT $/x unless defined $mday; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # asctime (Sun Nov 6 08:49:37 1994) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 19 | ▶ | ($mon,$mday,$hour,$min,$sec,$year) = $_[0] =~ m/^ (?:Sun|Mon|Tue|Wed|Thu|Fri|Sat) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | [ ] (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ ]{1,2} ([0-9]{1,2}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | [ ] ([0-9]{2}) : ([0-9]{2}) : ([0-9]{2}) [ ] ([0-9]{4}) $/x unless defined $mday; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 19 | ▶ | return undef unless defined $mday; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 18 | require Time::Local; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # 4 digit years interpreted literally, but may have leading zeroes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | # 2 digit years interpreted with best effort heuristic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 18 | ▶ | return scalar Time::Local::timegm($sec, $min, $hour, $mday, $MONTH_NUMS{$mon}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $year == 4 and $year < 1900
MC/DC0%0/2
length $year == 4 and $year < 1900
length $year == 4
$year < 1900
Truth table66%2/3
A and B
A= length $year == 4B= $year < 1900
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | (length($year) == 4 && $year < 1900) ? $year - 1900 : $year); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 7 | my %ESCAPES = ('&' => '&', '<' => '<', '>' => '>', '"' => '"', '\'' => '''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 3 | ▶ | sub escape_html { (my $escaped = $_[0]) =~ s/([&<>"'])/$ESCAPES{$1}/ge; $escaped } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape_html: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||