http://qs1969.pair.com?node_id=423821

I've been delaying with this one -- hoping that I could get it a little more finished before mentioning it. But I've decided that what I really need is brainpower and feedback from my fellow monks. So sorry if this is a bit muttled... I just want to get it out there.

In case you haven't heard of it, continuation-based web programming is a neat trick for building stateful applications on top of the statelessness that is the web. It is a conceptual change -- imagine that your program is running in a direct interactive environment, on the command line for example. When you prompt a user for input, your program hangs until the user enters something, and then continues on the next line.

You might have:
print "Enter the first number: "; my $a = <>; print "Enter the second number: "; my $b = <>; print "The sum of $a and $b is " . ($a + $b) . "\n";
or similar. So, using continuations, we could do this in a web environment like this:
sub addTwo { my ($self) = @_; my $a = $self->getNum("Enter first number: "); my $b = $self->getNum("Enter second number: "); $self->disp("The sum of $a and $b is " . ($a + $b)); }

In order to set all this up, I first had to give perl continuations. We have Coro::Cont, but I couldn't figure out how to save these continuations to disk (which is necessary for my desired model, which is running through apache). So I created fake pure-perl continuations with Contize. Thats a story unto itself.

Once I had Contize, it was a short trip to create Continuity, which is the whole framework. This is already functional, though there are some known-issues (mostly with suspending objects to-disk, not as easy as it first may seem). I have some larger examples on my website, and I'm looking for others to try this out and help me find/fix the weaknesses.

Here is some more source to give you the idea:

##### --- index.pl ---- #!/usr/bin/perl use strict; use Continuity; use Guess; my $c = new Continuity( appname => 'Guess', print_html_header => 1, print_form => 1, ); $c->go(); ##### --- Guess.pm ---- #!/usr/bin/perl package Guess; use strict; use base 'Continuity::Application'; sub setNumber { my $self = shift; $self->{number} = int(rand(100)) + 1; } sub getNum { my $self = shift; my $f = $self->disp(qq{ Enter Guess: <input name="num"> <input type=submit value="Guess"><br> }); return $f->{'num'}; } sub main { my $self = shift; $self->setNumber(); my $guess; my $tries = 0; print "Hi! I'm thinking of a number from 1 to 100... can you guess i +t?<br>\n"; do { $tries++; $guess = $self->getNum(); print "It is smaller than $guess.<br>\n" if($guess > $self->{numbe +r}); print "It is bigger than $guess.<br>\n" if($guess < $self->{number +}); } until ($guess == $self->{number}); print "You got it! My number was in fact $self->{number}.<br>\n"; print "It took you $tries tries.<br>\n"; print '<a href="index.pl">Play Again</a>'; } 1;

And the live version of the above is at http://thelackthereof.org/dev/guess/index.pl. Also see the website for the project, http://thelackthereof.org/wiki.pl/Continuity

Update: Fixed demo URL.