Quoting Joshua Chamas <[EMAIL PROTECTED]>:

> > Francesco Pasqualini wrote:
> > 
> > an interesting feature of JSP is the possibility to use the MVC design
> pattern (INPUT/OUTPUT/LOGIC separation)
> > This is obtained  with the "forward" instruction.
> > How the MVC design pattern can be implemented in the mod_perl (and
> specifically Apache::ASP) architecture ?
> > 
> 
> If you do use Apache::ASP in this way, how are you doing it.
> I don't know much about what you are going after, so it would
> be neat to hear how you accomplish it.

...mmh...
Developing an Apache::ASP application I encountered the problem/feature that it 
is not possible to use global variables inside subs in a page.
For example:
   page test.asp
   $name='default name';
   ...
   HelloWord();
   sub HelloWord{ 
     print $name; ## WRONG using global var is incosistent in mod_perl
   }
The correct approach if you have sub in a asp Page is to pass it everything it 
need:
   page test.asp
   $name='default name';
   ...
   HelloWord($name);
   sub HelloWord{ 
     my $name = shift; #OK
     print $name;      ## OK $name is not global
   }

To avoid passing many parameters to the subs I become using a $cx (cx stand for 
context) global hash containig everything the subs needed, passed to each sub. 

   page test.asp
   $cx = {};
   $cx->{'name'} = 'default name';
   $cx->{'age'} = 30;
   ...
   HelloWord($cx);
   ...
   sub HelloWord{
     my $cx = shift; 
     my $name = $cx->{'name'}; #OK
     print $name;      ## OK $name is not global
   }


...at the end of the work I realized that the idea of such a context is exactly 
what it is used in MVC tools like:
- JSP templates, 
- www.webmacro.org, 
- jakarta.apache.org/velocity, 
- www.freemarker.org.
But in such a way I've done a MVC architecture in a single page, where a part 
of the page is the View and a part is the Controller(logic).
If Apache::ASP will support the 'forward' directive we could start developing 
MVC application in a way similar to the JSP world.
Useful Links to MVC documentations are in:
    http://jakarta.apache.org/velocity/ymtd/ymtd.html
JSP  Specification:
    http://java.sun.com/aboutJava/communityprocess/first/jsr053/jsp12.pdf

Francesco

> 
> --Josh
> 
> _________________________________________________________________
> Joshua Chamas                         Chamas Enterprises Inc.
> NodeWorks >> free web link monitoring Huntington Beach, CA  USA 
> http://www.nodeworks.com                1-714-625-4051
> 


-----------------------------------------------------------
This mail sent through the IMP demo site: demo.horde.org
     Find out more at http://www.horde.org/imp/

Reply via email to