It gives me great pleasure to introduce you to the world's first mod_perl6 handlers! They are run using Parrot's Perl6 compiler on top of mod_parrot, and are compiled on the fly the first time a handler is called. Each handler is passed an [Apache;RequestRec] object instantiated by mod_parrot, and the handlers can call methods on that object from Perl6 land.

First is Polly. Polly repeats everything from the query string of a URL. It uses the puts() method for output and args() to retrieve the query string from Apache.

sub polly_handler($r)
{
    $r.puts("<h1>Polly, a mod_perl6 handler</h1>\n");
    $r.puts("SQUAWK!  Polly says "~$r.args());
    0; # Apache OK
}

Second is the counter, which increments a counter each time it is called. It demonstrates the persistence of the interpreter and proper scoping of the counter variable using "our". Since each Apache process has its own interpreter, the count might seem to jump between calls, espcially if your browser isn't using keepalives.

sub counter_handler($r)
{
    our $x;
    unless ($x) {
        $x = 1;
    }
    $r.puts("<h1>Hello, I'm a mod_perl6 response handler!</h1>\n");
    $r.puts("Page views for this interpreter: $x\n");
    $x++;
    0; # Apache OK
}

Against my better judgment, here are URLs for each handler:

Polly: http://www.smashing.org/sandbox/perl6-handlers/polly?wanna_cracker
Counter: http://www.smashing.org/sandbox/perl6-handlers/counter

Hopefully the server stays up -- I guess this is a pretty good test of mod_parrot's stability. ;-)

Enjoy,

-jeff

Reply via email to