line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
18057
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
66
|
|
2
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
95
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package HTTP::Server::Simple; |
5
|
3
|
|
|
3
|
|
1344
|
use FileHandle; |
|
3
|
|
|
|
|
21759
|
|
|
3
|
|
|
|
|
13
|
|
6
|
3
|
|
|
3
|
|
1211
|
use Socket; |
|
3
|
|
|
|
|
2511
|
|
|
3
|
|
|
|
|
1091
|
|
7
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
130
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
10
|
use vars qw($VERSION $bad_request_doc); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
1366
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.52'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
HTTP::Server::Simple - Lightweight HTTP server |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use warnings; |
19
|
|
|
|
|
|
|
use strict; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use HTTP::Server::Simple; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $server = HTTP::Server::Simple->new(); |
24
|
|
|
|
|
|
|
$server->run(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
However, normally you will sub-class the HTTP::Server::Simple::CGI |
27
|
|
|
|
|
|
|
module (see L); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Your::Web::Server; |
30
|
|
|
|
|
|
|
use base qw(HTTP::Server::Simple::CGI); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub handle_request { |
33
|
|
|
|
|
|
|
my ($self, $cgi) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#... do something, print output to default |
36
|
|
|
|
|
|
|
# selected filehandle... |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This is a simple standalone HTTP server. By default, it doesn't thread |
45
|
|
|
|
|
|
|
or fork. It does, however, act as a simple frontend which can be used |
46
|
|
|
|
|
|
|
to build a standalone web-based application or turn a CGI into one. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
It is possible to use L classes to create forking, |
49
|
|
|
|
|
|
|
pre-forking, and other types of more complicated servers; see |
50
|
|
|
|
|
|
|
L. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
By default, the server traps a few signals: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item HUP |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
When you C the server, it lets the current request finish being |
59
|
|
|
|
|
|
|
processed, then uses the C method to re-exec itself. Please note that |
60
|
|
|
|
|
|
|
in order to provide restart-on-SIGHUP, HTTP::Server::Simple sets a SIGHUP |
61
|
|
|
|
|
|
|
handler during initialisation. If your request handling code forks you need to |
62
|
|
|
|
|
|
|
make sure you reset this or unexpected things will happen if somebody sends a |
63
|
|
|
|
|
|
|
HUP to all running processes spawned by your app (e.g. by "kill -HUP |