#!/usr/bin/perl { package TestWebServer; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); my %dispatch = ( '/login' => \&resp_login, # ... ); sub handle_request { my $self = shift; my $cgi = shift; my $path = $cgi->path_info(); my $handler = $dispatch{$path}; if (ref($handler) eq "CODE") { print "HTTP/1.1 200 OK\r\n"; $handler->($cgi); } else { print "HTTP/1.1 404 Not found\r\n"; print $cgi->header, $cgi->start_html('Not found'), $cgi->h1('Not found'), $cgi->end_html; } } sub resp_login { my $cgi = shift; # CGI.pm object return if !ref $cgi; my %params = $cgi->Vars(); my ($user, $pass) = split /\0/, $params{DATA}; print $cgi->header, $cgi->start_html("Info"), $cgi->p("You sent: user='$user', pass='$pass'"), $cgi->end_html; } } my $pid = TestWebServer->new(8080)->background(); print "Use 'kill $pid' to stop server.\n";