2 package HTTP::Server::Simple::CGI;
4 use base qw(HTTP::Server::Simple HTTP::Server::Simple::CGI::Environment);
10 use vars qw($VERSION $default_doc);
11 $VERSION = $HTTP::Server::Simple::VERSION;
15 HTTP::Server::Simple::CGI - CGI.pm-style version of HTTP::Server::Simple
19 HTTP::Server::Simple was already simple, but some smart-ass pointed
20 out that there is no CGI in HTTP, and so this module was born to
21 isolate the CGI.pm-related parts of this handler.
26 The accept_hook in this sub-class clears the environment to the
33 $self->setup_environment(@_);
36 =head2 post_setup_hook
38 Initializes the global L<CGI> object, as well as other environment
45 $self->setup_server_url;
46 CGI::initialize_globals();
51 This method sets up CGI environment variables based on various
52 meta-headers, like the protocol, remote host name, request path, etc.
54 See the docs in L<HTTP::Server::Simple> for more detail.
60 $self->setup_environment_from_metadata(@_);
63 =head2 handle_request CGI
65 This routine is called whenever your server gets a request it can
68 It's called with a CGI object that's been pre-initialized.
69 You want to override this method in your subclass
74 $default_doc = ( join "", <DATA> );
77 my ( $self, $cgi ) = @_;
79 print "HTTP/1.0 200 OK\r\n"; # probably OK by now
80 print "Content-Type: text/html\r\nContent-Length: ", length($default_doc),
81 "\r\n\r\n", $default_doc;
86 Handler implemented as part of HTTP::Server::Simple API
93 eval { $self->handle_request($cgi) };
105 <title>Hello!</title>
108 <h1>Congratulations!</h1>
110 <p>You now have a functional HTTP::Server::Simple::CGI running.
113 <p><i>(If you're seeing this page, it means you haven't subclassed
114 HTTP::Server::Simple::CGI, which you'll need to do to make it