Re: Linear web programming in Mason?
Dave Rolsky <[email protected]>
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 16 Jun 2004, Autrijus Tang wrote:
> Hi. Does anyone know if there were any attempts or discussion to bring Mason
> toward the "linear web programming model", ala Seaside
> (http://beta4.com/seaside2/) or Borges (http://borges.rubyforge.org/)?
>
> This is so one can write components that resembles sequential programs
> instead of state machines. A short example follows:
>
> %# Counter.mas:
> <& /header &>
> <h1>Current Counter: <% $count %></h1>
> <&|/button, $m->run_method('Incr') &>++</&>
> <&|/button, $m->run_method('Decr') &>--</&>
> <%INIT>
> my $count = 0;
> </%INIT>
> <%METHOD Incr>
> % $count++;
> </%METHOD>
> <%METHOD Decr>
> % if ($count == 0) {
> % # to the user, the next line brings up a new page...
> % my $ok = $m->run_comp('Confirm.mas', Text => 'Go negative?');
> % # ...after the user clicks "Yes"/"No" we are back here!
> % return if !$ok;
> % }
> % $count--;
> </%METHOD>
>
> %# Confirm.mas:
> <& /header &>
> <p>Please confirm: <b><% $Text %></b></p>
> <&|/button, $m->yield(1) &>Yes</&>
> <&|/button, $m->yield(0) &>No</&>
> <%ARGS>
> $Text
> </%ARGS>
>
> I understand the subtleties involved (serializing Coro::Cont state for
> lexical variables; make continuation-passing-style $m facades; separate
> backtrackable methods with nonbacktrackable ones); I merely wish to
> check if were prior arts or discussions about this in the Mason/Perl
> space, and if this is an obviously insane approach to try with Mason.
I've _thought_ about it a little bit, but that's about it.
However, I was thinking of doing it more like this:
sub new_user {
my %input = new_user_data(); # dispatches to Mason which displays a form
while ( my @errors = check_user_data(%input) ) {
%input = new_user_data(%input, @errors);
}
make_new_user(%input);
redirect(...);
}
I don't really like the idea of doing that sort of thing within Mason. I
thought the whole idea of this was to make web programming (with multiple
requests) look like more like regular apps.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND