develooper Front page | perl.perl6.internals | Postings from September 2007

mod_perl6 update

Thread Next
From:
Jeff Horwitz
Date:
September 6, 2007 00:08
Subject:
mod_perl6 update
Message ID:
Pine.LNX.4.62.0709051606500.10531@booger.sixgeeks.org
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About