Subject: | Regex on uninitialized value when CGI fails |
When the CGI fails to run, and therefore emits no content, there is a warning:
Use of uninitialized value in pattern match (m//) at HTTP/Request/AsCGI.pm line 156
because the $message variable is not initialized. The current code:
my $message;
while ( my $line = $self->stdout->getline ) {
$message .= $line;
last if $message =~ /\x0d?\x0a\x0d?\x0a$/;
}
unless ( $message =~ /^HTTP/ ) {
$message = "HTTP/1.1 200 OK\x0d\x0a" . $message;
}
should become something like:
my $message;
while ( my $line = $self->stdout->getline ) {
$message .= $line;
last if $message =~ /\x0d?\x0a\x0d?\x0a$/;
}
unless ( defined $message ) {
$message = "HTTP/1.1 500 Internal Server Error\x0d\x0a"
}
unless ( $message =~ /^HTTP/ ) {
$message = "HTTP/1.1 200 OK\x0d\x0a" . $message;
}