Wednesday, November 08, 2006

Practically Web Hacking in Perl6

Audrey Tang recently announced that the Pugs project has been moved to new facilities, and the subsequent reissuing of my commit bit spurred me to fix a long-standing issue with the modules CGI and HTTP::Server::Simple (think of Ruby's webrick). Just a couple of small fixes allowed me to finally use these two modules together to create simple a standalone web application in Perl6:

use v6;
use HTTP::Server::Simple;
use CGI;

class WebApp is HTTP::Server::Simple {
method handler {
my $cgi = CGI.new;
my $name = $cgi.param('name');
$.remote.say("<html><head><title>Web App</title></head><body>");
if $name {
$.remote.say("<p>Hello {$name}.</p>");
} else {
$.remote.say('<form method="get">Name: <input name="name" /></form>');
}
$.remote.say("</body></html>");
}
}

WebApp.new( port => 8080 ).run;


The above now works in Pugs, as of r14679 or so. The fixes required to make this work were trivial, but the result is enormously satisfying. I can tell this thing will require further investigation. More tests are certianly needed to ensure that these modules continue to interact properly. First thing's first, however. I think I'll enjoy some nice Perl6 web hacking before bed tonight.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home