File Coverage

blib/lib/HTTP/Response/CGI.pm
Criterion Covered Total %
statement 31 32 96.8
branch 9 14 64.2
condition 3 6 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 50 59 84.7


line stmt bran cond sub pod time code
1             package HTTP::Response::CGI;
2 4     4   116123 use base 'HTTP::Response';
  4         14  
  4         7946  
3              
4             $VERSION = "1.0";
5              
6 4     4   205212 use warnings;
  4         11  
  4         134  
7 4     4   21 use strict;
  4         16  
  4         2137  
8              
9              
10              
11             sub new
12             {
13 1     1 1 75 my $class = shift;
14 1         10 my $self = $class->SUPER::new(@_);
15 1         71 $self;
16             }
17              
18              
19             sub parse
20             {
21 5     5 1 5460 my($class, $str) = @_;
22             # borrowed from HTML::Response
23 5         9 my $status_line;
24 5 50       44 if ($str =~ m/^(.*)\n/) {
25 5         20 $status_line = $1;
26             }
27             else {
28 0         0 $status_line = $str;
29             }
30              
31 5         49 my $self = $class->SUPER::parse($str);
32              
33 5 100 66     1018 if (!$self->protocol || $self->protocol =~ /^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         104 my ($header, $value) = $status_line =~ /^([^:]+):\s*(.+)$/;
43 4 50 33     30 if ($header && $value) {
44             # remove carriage return, if it exists.
45 4 50       17 $value =~ s/\r$// if $value;
46 4         35 $self->header($header => $value);
47             }
48              
49             # if headers contain a Status: line, modify that into an HTTP header.
50 4 100       248 if ($self->header('Status')) {
51             # case: the CGI has set an explict Status:
52 1         40 my ($code, $message) = split(' ', $self->header('Status'), 2);
53 1         51 $self->protocol(undef);
54 1 50       14 $self->code($code) if defined($code);
55 1 50       15 $self->message($message) if defined($message);
56             } else {
57             # case: the CGI has not set an explict Status:
58             # Assume "200 OK".
59 3         165 $self->protocol(undef);
60 3         36 $self->code('200');
61 3         37 $self->message('OK');
62             }
63             }
64              
65 5         79 $self;
66             }
67              
68              
69             1;
70              
71              
72             __END__