perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett W. McCoy" <>
Subject Re: modperl/ASP and MVC design pattern
Date Fri, 20 Apr 2001 15:32:43 GMT
On Fri, 20 Apr 2001, 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 ?

MVC isn't dependent on any particular language, it's a top level design
for your application.  I have used something similar to the MVC model
using just & DBI/DBD.  The basic idea is to decouple your data
model from the display of that data.  It's probably not textbook accurate
MVC, but it borrows heavily from the architecture.

I created a wrapper class for by database functionality (didn't sub-class
DBI, but encapsulated it and the specifics of my data retrieval in the
class).  This class had hogh-level methods like $data->get_id,
$data->list_ids, etc. I have used this same class with both PostgreSQL and
MySQL, and the top-level interface didn't have to change, even though the
underlying data structures did because of differences between PostgreSQL
and MySQL (for instance, I could't use views or referential integrity
contraints in MySQL).

Then I created a display class that handled displaying stuff on the
browser -- also encapsulating the CGI module in high-level methods like
$disp->registration_form, $disp->error_page, etc.  Again, here, I used
this class where I had a newer version of CGI, but had to retrofit the
class to a system that used an older version of CGI, so I had to recode a
couple of methods using raw HTML and here docs, since the older system
didn't have CGI methods available in the newer version.

Finally, my top-level layer was a simple script (this wasn't a class per
se) that was a 'driver' for the everything else -- I actually use a
modified form of Recipe 19.12 in the Perl cookbook.  I maintain state
between page access through a single state variable, and have a hash that
manages my data class and the display class, and the state variable is
used to determine what 'page' to display, and handles top-level error

-- Brett
genealogy, n.:
	An account of one's descent from an ancestor
	who did not particularly care to trace his own.
		-- Ambrose Bierce

View raw message