[Bps-public-commit] r10857 - in HTTP-Server-Simple: .
jesse at bestpractical.com
jesse at bestpractical.com
Fri Feb 15 11:44:49 EST 2008
Author: jesse
Date: Fri Feb 15 11:44:47 2008
New Revision: 10857
Modified:
HTTP-Server-Simple/ (props changed)
HTTP-Server-Simple/Changes
HTTP-Server-Simple/SIGNATURE
HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
Log:
r27674 at 124: jesse | 2008-02-15 11:44:31 -0500
* 0.29 - new example section from almut @ perlmonks
Modified: HTTP-Server-Simple/Changes
==============================================================================
--- HTTP-Server-Simple/Changes (original)
+++ HTTP-Server-Simple/Changes Fri Feb 15 11:44:47 2008
@@ -1,3 +1,7 @@
+0.29 Fri Feb 15 11:43:29 EST 2008
+
+* new example section from almut on perlmonks
+
0.28 Tue Jan 15 09:33:58 EST 2008
* New restartability support from Mark Stosberg
Modified: HTTP-Server-Simple/SIGNATURE
==============================================================================
--- HTTP-Server-Simple/SIGNATURE (original)
+++ HTTP-Server-Simple/SIGNATURE Fri Feb 15 11:44:47 2008
@@ -14,7 +14,7 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
-SHA1 675ffe663efe035cc65047502345938904d9d0e1 Changes
+SHA1 1169fda38432a0b835a619128f524a44dbf913cc Changes
SHA1 0ac508c50476dcc2bf8fe3094cb341425291e1ee MANIFEST
SHA1 de5abaa8229fa5378d21eeb328081c8f14a7b488 META.yml
SHA1 3a02ba613b11b07dd1fa97e2a6b962ee3e039c98 Makefile.PL
@@ -28,7 +28,7 @@
SHA1 5d6189b2cad15cf9932a28faafd55130c8247e83 inc/Module/Install/Metadata.pm
SHA1 02af973fae2ac3531fa6b704574b2b8cb2a08148 inc/Module/Install/Win32.pm
SHA1 3a2eab96e91cca8d99938cda7791759ae9d97b3a inc/Module/Install/WriteAll.pm
-SHA1 1ed5f4a8a4aa0a6bf5cc9a7be817a913dbed174e lib/HTTP/Server/Simple.pm
+SHA1 f3dc37bcbde91e7842c39a9aed62e68f188ea5cf lib/HTTP/Server/Simple.pm
SHA1 40f24374f2b5845a3025e14ca4b91bd58298de03 lib/HTTP/Server/Simple/CGI.pm
SHA1 47ef836a1cdd03add505dd4c90819cafb61dc565 lib/HTTP/Server/Simple/CGI/Environment.pm
SHA1 db064af54cab345a71daec576e32e64b8fb1033d t/00smoke.t
@@ -37,9 +37,9 @@
SHA1 a7024d0d8e7b80d26f75a3551a1406a797b382f8 t/03podcoverage.t
SHA1 bc9dc786924d61aa0dc8747c1d68f47cf421ec37 t/04cgi.t
-----BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
+Version: GnuPG v1.4.8 (Darwin)
-iD8DBQFHjMRyEi9d9xCOQEYRAg5UAKC6K4D3TqcEiAoGSMZW7WtAZtdz2wCgieho
-SnitUjgps/2KV99Xuv1Dchc=
-=sEH7
+iD8DBQFHtcFPEi9d9xCOQEYRAsxZAKDA8ITW0PRKPl/szr3nRGyy0dIIuwCbBUqW
+vZRZsBd3mlE7l0EkMlxXV1M=
+=nUTd
-----END PGP SIGNATURE-----
Modified: HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
==============================================================================
--- HTTP-Server-Simple/lib/HTTP/Server/Simple.pm (original)
+++ HTTP-Server-Simple/lib/HTTP/Server/Simple.pm Fri Feb 15 11:44:47 2008
@@ -1,13 +1,14 @@
-package HTTP::Server::Simple;
use strict;
use warnings;
+
+package HTTP::Server::Simple;
use FileHandle;
use Socket;
use Carp;
use URI::Escape;
use vars qw($VERSION $bad_request_doc);
-$VERSION = '0.28';
+$VERSION = '0.29';
=head1 NAME
@@ -73,6 +74,60 @@
=back
+=head1 EXAMPLE
+
+ #!/usr/bin/perl
+ {
+ package MyWebServer;
+
+ use HTTP::Server::Simple::CGI;
+ use base qw(HTTP::Server::Simple::CGI);
+
+ my %dispatch = (
+ '/hello' => \&resp_hello,
+ # ...
+ );
+
+ 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.0 200 OK\r\n";
+ $handler->($cgi);
+
+ } else {
+ print "HTTP/1.0 404 Not found\r\n";
+ print $cgi->header,
+ $cgi->start_html('Not found'),
+ $cgi->h1('Not found'),
+ $cgi->end_html;
+ }
+ }
+
+ sub resp_hello {
+ my $cgi = shift; # CGI.pm object
+ return if !ref $cgi;
+
+ my $who = $cgi->param('name');
+
+ print $cgi->header,
+ $cgi->start_html("Hello"),
+ $cgi->h1("Hello $who!"),
+ $cgi->end_html;
+ }
+
+ }
+
+ # start the server on port 8080
+ my $pid = MyWebServer->new(8080)->background();
+ print "Use 'kill $pid' to stop server.\n";
+
+=head1 METHODS
+
=head2 HTTP::Server::Simple->new($port)
API call to start a new server. Does not actually start listening
@@ -645,7 +700,7 @@
=head1 AUTHOR
-Copyright (c) 2004-2006 Jesse Vincent, <jesse at bestpractical.com>.
+Copyright (c) 2004-2008 Jesse Vincent, <jesse at bestpractical.com>.
All rights reserved.
Marcus Ramberg <drave at thefeed.no> contributed tests, cleanup, etc
@@ -653,6 +708,8 @@
Sam Vilain, <samv at cpan.org> contributed the CGI.pm split-out and
header/setup API.
+Example section by almut on perlmonks, suggested by Mark Fuller.
+
=head1 BUGS
There certainly are some. Please report them via rt.cpan.org
More information about the Bps-public-commit
mailing list