| 1 | package HTTP::Response::CGI; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use base 'HTTP::Response'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | $VERSION = "1.0"; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 1 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 15 | 1 | $self; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub parse | ||||||||||||||||||||||||||||
| 20 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 5 | my($class, $str) = @_; | |||||||||||||||||||||||||||
| 22 | # borrowed from HTML::Response | ||||||||||||||||||||||||||||
| 23 | 5 | my $status_line; | |||||||||||||||||||||||||||
| 24 | 5 | ▶ | if ($str =~ m/^(.*)\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 5 | $status_line = $1; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 0 | $status_line = $str; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5 | my $self = $class->SUPER::parse($str); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if (!$self->protocol || $self->protocol =~ /^HTTP\/[\d\.]+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->protocol or $self->protocol =~ m[^HTTP/[\d\.]+]
MC/DC50%1/2
not $self->protocol or $self->protocol =~ m[^HTTP/[\d\.]+]
not $self->protocol
$self->protocol =~ m[^HTTP/[\d\.]+]
Truth table66%2/3
not(A) or B
A= not $self->protocolB= $self->protocol =~ m[^HTTP/[\d\.]+]
| |||||||||||||||||||||||||||||
| 34 | # Everything was already set correctly by SUPER::parse(). | ||||||||||||||||||||||||||||
| 35 | # This may not be CGI output. | ||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||
| 37 | # Parsed the $status_line "incorrectly". | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # If there was a header on the first line, it will get snarfed into | ||||||||||||||||||||||||||||
| 40 | # protocol()/code(). | ||||||||||||||||||||||||||||
| 41 | # Re-parse that header out here. | ||||||||||||||||||||||||||||
| 42 | 4 | my ($header, $value) = $status_line =~ /^([^:]+):\s*(.+)$/; | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | if ($header && $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$header and $value
MC/DC0%0/2
$header and $value
$header
$value
Truth table33%1/3
A and B
A= $headerB= $value
| |||||||||||||||||||||||||||||
| 44 | # remove carriage return, if it exists. | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | $value =~ s/\r$// if $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 4 | $self->header($header => $value); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # if headers contain a Status: line, modify that into an HTTP header. | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | if ($self->header('Status')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | # case: the CGI has set an explict Status: | ||||||||||||||||||||||||||||
| 52 | 1 | my ($code, $message) = split(' ', $self->header('Status'), 2); | |||||||||||||||||||||||||||
| 53 | 1 | $self->protocol(undef); | |||||||||||||||||||||||||||
| 54 | 1 | ▶ | $self->code($code) if defined($code); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | $self->message($message) if defined($message); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | # case: the CGI has not set an explict Status: | ||||||||||||||||||||||||||||
| 58 | # Assume "200 OK". | ||||||||||||||||||||||||||||
| 59 | 3 | $self->protocol(undef); | |||||||||||||||||||||||||||
| 60 | 3 | $self->code('200'); | |||||||||||||||||||||||||||
| 61 | 3 | $self->message('OK'); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | $self; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 4 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||