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

Zohar Kelrich lumi at musicgenome.com
Tue Mar 23 17:31:15 PST 2004


On Wed, 24 Mar 2004 01:16:02 +0200
"Ran Eilam" <eilara at cortext.co.il> wrote:

> > How do you write a prompt() that will allow flow() to run 
> > unchanged, but as a web app consisting of 3 pages?

Attached is answer
That does not use disk state files.
So, I get a beer? :P

--- >8 cut here
#!/bin/perl -w
use strict;
use CGI qw/:standard/;

# This is the Sacred Function. We do not change the Sacred Function.
sub flow {
	my $a = prompt('Enter a number:');
	my $b = prompt('Enter another number:');
	prompt('Sum is: '. ($a + $b). '. Hit Enter to continue.');
}

sub hashcaller { # Hashes the caller return to obtain a URL-able field name
	my ($package,$sub,$line)=@_;	# In a real app,
					# Hash all of these little things.
	return 'u'.$line;		# I just use the line.
}
sub prompt {
	my $message=shift;
	my ($package,$sub,$line)=caller;
	my $hashed=hashcaller($package,$sub,$line);
	
	if(param($hashed)) {		# If we've asked this once,
					# Answer is on the query.
		return param($hashed);	# Return it and go.
		
	}
	else {	# Otherwise, display 
		# a page and then go away.
		# Cherry blossom. Um.
		print start_form(-action=>url(-path_info=>1,-query=>1)), $message,
textfield($hashed),submit,end_form,end_html;		exit;
	}
}
print header,start_html("Wub Application: Addition!");

flow;

--- >8 Cut again, methodically.
-- 
sig.






More information about the Perl mailing list