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

mod_perl6 update

Thread Next
Jeff Horwitz
September 6, 2007 00:08
mod_perl6 update
Message ID:
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 

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");
     0; # Apache OK

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


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



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About