line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::MinimalCGI; |
2
|
1
|
|
|
1
|
|
786
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
5
|
use Scalar::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
5
|
1
|
|
|
1
|
|
1012
|
use HTTP::Headers::Fast (); |
|
1
|
|
|
|
|
4789
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
570
|
use HTTP::Engine::ResponseFinalizer (); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
20
|
|
7
|
1
|
|
|
1
|
|
5615
|
use CGI::Simple (); |
|
1
|
|
|
|
|
21950
|
|
|
1
|
|
|
|
|
1278
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $CRLF = "\015\012"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
7
|
|
|
7
|
0
|
14
|
my $class = shift; |
13
|
7
|
|
|
|
|
36
|
bless { @_ }, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub run { |
17
|
7
|
|
|
7
|
0
|
10
|
my ($self, ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
### run handler |
20
|
7
|
|
|
|
|
46
|
my $req = HTTP::Engine::Request->new(); |
21
|
7
|
|
|
|
|
165
|
my $res = $self->{request_handler}->( $req ); |
22
|
7
|
50
|
33
|
|
|
262
|
unless ( Scalar::Util::blessed($res) && $res->isa('HTTP::Engine::Response') ) { |
23
|
0
|
|
|
|
|
0
|
die "You should return instance of HTTP::Engine::Response."; |
24
|
|
|
|
|
|
|
} |
25
|
7
|
|
|
|
|
58
|
HTTP::Engine::ResponseFinalizer->finalize($req => $res); |
26
|
7
|
|
|
|
|
26
|
print join( |
27
|
|
|
|
|
|
|
'', |
28
|
|
|
|
|
|
|
$res->headers->as_string_without_sort($CRLF), |
29
|
|
|
|
|
|
|
$CRLF, |
30
|
|
|
|
|
|
|
$res->body |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
package # hide from pause |
36
|
|
|
|
|
|
|
HTTP::Engine; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
7
|
|
|
7
|
|
9606
|
my ($class, %args) = @_; |
40
|
7
|
50
|
|
|
|
38
|
unless (Scalar::Util::blessed($args{interface})) { |
41
|
7
|
50
|
|
|
|
30
|
if ($args{interface}->{module} ne 'MinimalCGI') { |
42
|
0
|
|
|
|
|
0
|
die "MinimalCGI is the only interface supported. Use the real HTTP::Engine for others."; |
43
|
|
|
|
|
|
|
} |
44
|
7
|
|
|
|
|
53
|
$args{interface} = HTTP::Engine::MinimalCGI->new( |
45
|
|
|
|
|
|
|
request_handler => $args{interface}->{request_handler} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
7
|
|
|
|
|
42
|
bless { interface => $args{interface} }, $class; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
7
|
|
36
|
sub run { $_[0]->{interface}->run() } |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
package # hide from pause |
57
|
|
|
|
|
|
|
HTTP::Engine::Response; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
7
|
|
|
7
|
|
92
|
my ($class, %args) = @_; |
61
|
7
|
|
|
|
|
46
|
bless { |
62
|
|
|
|
|
|
|
status => 200, |
63
|
|
|
|
|
|
|
body => '', |
64
|
|
|
|
|
|
|
headers => HTTP::Headers::Fast->new(), |
65
|
|
|
|
|
|
|
%args, |
66
|
|
|
|
|
|
|
}, $class; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub header { |
69
|
16
|
|
|
16
|
|
88
|
my $self = shift; |
70
|
16
|
|
|
|
|
59
|
$self->{headers}->header(@_); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
sub headers { |
73
|
8
|
|
|
8
|
|
15
|
my $self = shift; |
74
|
8
|
|
|
|
|
40
|
$self->{headers}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub status { |
77
|
14
|
|
|
14
|
|
23
|
my $self = shift; |
78
|
14
|
50
|
|
|
|
32
|
$self->{status} = shift if @_; |
79
|
14
|
|
|
|
|
70
|
$self->{status}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
sub body { |
82
|
35
|
|
|
35
|
|
606
|
my $self = shift; |
83
|
35
|
50
|
|
|
|
70
|
$self->{body} = shift if @_; |
84
|
35
|
|
|
|
|
225
|
$self->{body}; |
85
|
|
|
|
|
|
|
} |
86
|
21
|
|
|
21
|
|
99
|
sub protocol { 'HTTP/1.0' }; |
87
|
7
|
|
|
7
|
|
1164
|
sub content_length { my $self = shift; $self->{headers}->content_length(@_) }; |
|
7
|
|
|
|
|
53
|
|
88
|
14
|
|
|
14
|
|
89
|
sub content_type { my $self = shift; $self->{headers}->content_type(@_) }; |
|
14
|
|
|
|
|
48
|
|
89
|
|
|
|
|
|
|
sub cookies { |
90
|
8
|
|
|
8
|
|
51
|
my $self = shift; |
91
|
8
|
|
66
|
|
|
30
|
$self->{cookies} ||= do { |
92
|
7
|
50
|
|
|
|
18
|
if (my $header = $self->header('Cookie')) { |
93
|
0
|
|
|
|
|
0
|
+{ CGI::Simple::Cookie->parse($header) }; |
94
|
|
|
|
|
|
|
} else { |
95
|
7
|
|
|
|
|
214
|
+{}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
package # hide from pause |
103
|
|
|
|
|
|
|
HTTP::Engine::Request; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub new { |
106
|
7
|
|
|
7
|
|
11
|
my ($class, ) = @_; |
107
|
7
|
|
|
|
|
21
|
bless { }, $class; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
0
|
|
0
|
sub hostname { $ENV{HTTP_HOST} || $ENV{SERVER_HOST} } |
111
|
0
|
0
|
|
0
|
|
0
|
sub protocol { $ENV{SERVER_PROTOCOL} || 'HTTP/1.0' } |
112
|
15
|
50
|
|
15
|
|
129
|
sub method { $ENV{REQUEST_METHOD} || 'GET' } |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub param { |
115
|
1
|
|
|
1
|
|
10
|
my $self = shift; |
116
|
1
|
|
33
|
|
|
18
|
$self->{cs} ||= CGI::Simple->new(); |
117
|
1
|
|
|
|
|
153
|
$self->{cs}->param(@_); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
sub upload { |
120
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
121
|
0
|
|
0
|
|
|
0
|
$self->{cs} ||= CGI::Simple->new(); |
122
|
0
|
|
|
|
|
0
|
$self->{cs}->upload(@_); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
sub header { |
125
|
2
|
|
|
2
|
|
15
|
my ($self, $key) = @_; |
126
|
2
|
|
|
|
|
6
|
$key = uc $key; |
127
|
2
|
|
|
|
|
7
|
$key =~ s/-/_/; |
128
|
2
|
50
|
|
|
|
44
|
$ENV{'HTTP_' . $key} || $ENV{'HTTPS_' . $key}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |