#!env perl { package sillyServer; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); use Data::Dump 'pp'; # URL paths to monitor my %dispatch = ( '/hello' => \&resp_hello, ); # Look up the path and execute the associated routine, or # give a typical 404 error sub handle_request { my ($self, $cgi) = @_; my $path = $cgi->path_info(); my $handler = $dispatch{$path}; if ("CODE" eq ref $handler) { print "HTTP/1.0 200 OK\r\n"; $handler->($cgi); return; } print "HTTP/1.0 404 Not found\r\n", $cgi->header, $cgi->start_html("Nada Darn Thing To C Here"), $cgi->h1("Nuttin here"), $cgi->end_html; } # handler for "/hello" sub resp_hello { my $cgi = shift; return if !ref $cgi; print $cgi->header, $cgi->start_html("Hello"), $cgi->h1("Hi there!\n"), $cgi->p("Parameters from \$cgi: ", pp($cgi->{param})), $cgi->p("Parameters from ENV: $ENV{QUERY_STRING}"), $cgi->end_html; } } # Start up the server use strict; use warnings; my $pid = sillyServer->new(8088)->run; print "PID = $pid, press ^C to stop\n"; my $t = <>;