You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joachim Zobel <nc...@netcologne.de> on 2001/11/15 21:08:30 UTC

Re: [Maybe OT] Modular design - calling pages like a subroutine with a twist.

At 08:42 15.11.01 -0800, you wrote:
>Say I have a page that encapsulates some functionality, such as
>sending a form then validating the contents that are returned. I'd
>call that PageB.
>
>PageB could be more than one page or a page calling itself, etc.
>
>When PageA calls PageB, as soon as PageB finishes presenting
>the form it doesn't stop but drops out the bottom and returns
>immediately to PageA.  There are commands in some of the tools
>(Mason and soon Embperl - maybe others) to force it to stop there
>but this doesn't make for the modularity I have in mind.
>
>PageB then gets submitted by the user and it either calls itself
>(using conditionals to then do the data validation) or another page.
>After things are validated Ok, I'd like to have it return right back to
>PageA, just where it left off using a "Return" statement. Thus,
>PageA could call a "PageB" and have it do all it's processing then
>return, just like calling a regular subroutine.

I'm using what I call the post2redirect pattern 
(http://www.catstep.de/zobel/post2redirect.html): Every POST request 
(normally a request that changes server state) must end up doing a 
redirect. This way I get two kinds of scripts: pages (GETs) and actions 
(POST).

The point is that the action scripts decide which page is to be displayed 
next (eg. same form with error messages or "data written" page)

Well, the aproach has some problems (302 is not allowed by RFC 2616 to 
change from POST to GET but works, 303 is not implemented by browsers yet) 
but it gives a good design with a very simple principle.

Hth,
Joachim

--
"... ein Geschlecht erfinderischer Zwerge, die fuer alles gemietet werden
koennen."                            - Bertolt Brecht - Leben des Galilei