mod_perl and closures

Michael Stillwell mjs at beebo.org
Sun Jun 22 00:05:00 CDT 2003


I'm not too familiar with mod_perl; are there any mod_perl modules that 
maintain state on the server with closures?  I'm thinking about 
something Apache::ClosureManager in the following (incomplete, 
untested, untypoed, etc.) code:

   package Hangman;

   sub output_html {
     my ($self) = @_;

     my $c = Apache::ClosureManager->new(sub {
       $self->process_cgi_input; # see below
       $self->output_html;
     });

     $c->expires("1 hour");

     my $url = $c->url; # e.g. "/cgi-bin/invoke-closure.cgi?38f4a11bc3"

     print p("You have guessed: ", join(" ", @{$self->{GUESSES}}));
     print p("Enter next guess:");
     print qq{
       <form action="$url" method="post">
         <input type="text" name="guess"/>
         <input type="submit"/>
       </form>
     };

   sub process_cgi_input {
     my ($self) = @_;

     push @{$self->{GUESSES}}, param("guess");
   }

This would seem to be a nice way to maintain state in some 
circumstances (especially those where you don't/can't care about the 
readability of the URL).




--M.

* * *
http://beebo.org




More information about the Melbourne-pm mailing list