[Israel.pm] Talk: A natural flow for web apps

Jason Elbaum Jason.Elbaum at motorola.com
Wed Mar 24 04:36:30 PST 2004

I'm starting to understand. Correct me if I'm wrong.

>   sub flow_replace_product {
>      my $old_name= prompt('Enter old product name:');
>      delete_product_from_database($old_name);
>      my $new_name= prompt('Enter new product name:');  
>      add_product_to_database($new_name); 
>      prompt('Thanx!');
>   }

When you call prompt(), you want the following to happen:

1. The user is sent a web page with a form requesting input.
2. flow_replace_product() goes into some sort of dormant state until 
such time as the user presses the submit button.
3. The submitted data will be sent to a web request handler whenever it 
happens to arrive, with some sort of session id linking it to the 
correct user.
4. The web request handler will extract the user's response, and somehow 
reactivate flow_replace_product(), resuming where it left off and 
passing it the correct return value.
5. Unless prompt() was called in a void context, in which no response is 
expected - and in that case, no form or submit button need be written 
out in the first place.

This is essentially event-driven code - is the challenge any different 
than it would be if prompt() manipulated GUI elements?

Regarding the flow control, it looks like you need some form of 
coroutines or continuations, which would allow prompt() to save the 
complete calling state of its caller, and restore control to it at a 
later time. A bit like setjmp() / longjmp() (remember them, C mavens?).

I'm not aware of built-in support for this in Perl 5, though CPAN is 
always full of surprises (for me, at least!).

Jason Elbaum

More information about the Perl mailing list