line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::MinimalCGI; |
2
|
1
|
|
|
1
|
|
441
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
4
|
1
|
|
|
1
|
|
3
|
use Scalar::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
5
|
1
|
|
|
1
|
|
514
|
use HTTP::Headers::Fast (); |
|
1
|
|
|
|
|
3610
|
|
|
1
|
|
|
|
|
18
|
|
6
|
1
|
|
|
1
|
|
330
|
use HTTP::Engine::ResponseFinalizer (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
7
|
1
|
|
|
1
|
|
723
|
use CGI::Simple (); |
|
1
|
|
|
|
|
9296
|
|
|
1
|
|
|
|
|
593
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $CRLF = "\015\012"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
6
|
|
|
6
|
0
|
7
|
my $class = shift; |
13
|
6
|
|
|
|
|
15
|
bless { @_ }, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub run { |
17
|
6
|
|
|
6
|
0
|
6
|
my ($self, ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
### run handler |
20
|
6
|
|
|
|
|
17
|
my $req = HTTP::Engine::Request->new(); |
21
|
6
|
|
|
|
|
82
|
my $res = $self->{request_handler}->( $req ); |
22
|
6
|
50
|
33
|
|
|
191
|
unless ( Scalar::Util::blessed($res) && $res->isa('HTTP::Engine::Response') ) { |
23
|
0
|
|
|
|
|
0
|
die "You should return instance of HTTP::Engine::Response."; |
24
|
|
|
|
|
|
|
} |
25
|
6
|
|
|
|
|
28
|
HTTP::Engine::ResponseFinalizer->finalize($req => $res); |
26
|
6
|
|
|
|
|
10
|
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
|
6
|
|
|
6
|
|
1859
|
my ($class, %args) = @_; |
40
|
6
|
50
|
|
|
|
26
|
unless (Scalar::Util::blessed($args{interface})) { |
41
|
6
|
50
|
|
|
|
13
|
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
|
|
|
|
|
|
|
$args{interface} = HTTP::Engine::MinimalCGI->new( |
45
|
|
|
|
|
|
|
request_handler => $args{interface}->{request_handler} |
46
|
6
|
|
|
|
|
21
|
); |
47
|
|
|
|
|
|
|
} |
48
|
6
|
|
|
|
|
16
|
bless { interface => $args{interface} }, $class; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
6
|
|
17
|
sub run { $_[0]->{interface}->run() } |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
package # hide from pause |
57
|
|
|
|
|
|
|
HTTP::Engine::Response; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
6
|
|
|
6
|
|
53
|
my ($class, %args) = @_; |
61
|
6
|
|
|
|
|
23
|
bless { |
62
|
|
|
|
|
|
|
status => 200, |
63
|
|
|
|
|
|
|
body => '', |
64
|
|
|
|
|
|
|
headers => HTTP::Headers::Fast->new(), |
65
|
|
|
|
|
|
|
%args, |
66
|
|
|
|
|
|
|
}, $class; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub header { |
69
|
14
|
|
|
14
|
|
43
|
my $self = shift; |
70
|
14
|
|
|
|
|
25
|
$self->{headers}->header(@_); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
sub headers { |
73
|
7
|
|
|
7
|
|
7
|
my $self = shift; |
74
|
7
|
|
|
|
|
17
|
$self->{headers}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub status { |
77
|
12
|
|
|
12
|
|
7
|
my $self = shift; |
78
|
12
|
50
|
|
|
|
18
|
$self->{status} = shift if @_; |
79
|
12
|
|
|
|
|
32
|
$self->{status}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
sub body { |
82
|
30
|
|
|
30
|
|
249
|
my $self = shift; |
83
|
30
|
50
|
|
|
|
40
|
$self->{body} = shift if @_; |
84
|
30
|
|
|
|
|
110
|
$self->{body}; |
85
|
|
|
|
|
|
|
} |
86
|
18
|
|
|
18
|
|
53
|
sub protocol { 'HTTP/1.0' }; |
87
|
6
|
|
|
6
|
|
716
|
sub content_length { my $self = shift; $self->{headers}->content_length(@_) }; |
|
6
|
|
|
|
|
15
|
|
88
|
12
|
|
|
12
|
|
44
|
sub content_type { my $self = shift; $self->{headers}->content_type(@_) }; |
|
12
|
|
|
|
|
22
|
|
89
|
|
|
|
|
|
|
sub cookies { |
90
|
7
|
|
|
7
|
|
22
|
my $self = shift; |
91
|
7
|
|
66
|
|
|
16
|
$self->{cookies} ||= do { |
92
|
6
|
50
|
|
|
|
17
|
if (my $header = $self->header('Cookie')) { |
93
|
0
|
|
|
|
|
0
|
+{ CGI::Simple::Cookie->parse($header) }; |
94
|
|
|
|
|
|
|
} else { |
95
|
6
|
|
|
|
|
109
|
+{}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
package # hide from pause |
103
|
|
|
|
|
|
|
HTTP::Engine::Request; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub new { |
106
|
6
|
|
|
6
|
|
5
|
my ($class, ) = @_; |
107
|
6
|
|
|
|
|
11
|
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
|
12
|
50
|
|
12
|
|
57
|
sub method { $ENV{HTTP_METHOD} || 'GET' } |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub param { |
115
|
1
|
|
|
1
|
|
7
|
my $self = shift; |
116
|
1
|
|
33
|
|
|
12
|
$self->{cs} ||= CGI::Simple->new(); |
117
|
1
|
|
|
|
|
119
|
$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
|
|
10
|
my ($self, $key) = @_; |
126
|
2
|
|
|
|
|
3
|
$key = uc $key; |
127
|
2
|
|
|
|
|
4
|
$key =~ s/-/_/; |
128
|
2
|
50
|
|
|
|
23
|
$ENV{'HTTP_' . $key} || $ENV{'HTTPS_' . $key}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |