The
Model-View-Controller
(MVC) pattern separates an application into three components:
- Model - maintains the state of the program, contains the data store
- View - creates a 'view', that is it transforms the model data into
a form accessible to the user
- Controller - implements a user interface that allows the user to
interact with the model
The MVC pattern is an updated version of the old adage that computer
programs come in three parts: input, processing, and output. It is a
nice way to describe the high-level architecture of an application
because Views and Models naturally separate form from
content. Separating form from content usually leads to cleaner code
and greater flexibility.
For a future web application, I am meditating on the best approach to
take for the view and model. There are two general approaches I am
looking at.
The first is a traditional perl templating scheme. The model would be
a flat file or relational database, bound to a perl program through
DBI. The view would consist of a set of template documents
that would transform data to various formats (HTML, plain text, CSV,
etc.) using, for example, Template::Toolkit.
The second approach is to build an XML application. The model stores
data in an XML format and is accessed directly, or perhaps using
XML::LibXML. The view would consist of a set of template
documents that would transform data to various formats (HTML, plain text, CSV,
etc.) using the XSLT language via, e.g., XML::LibXSLT.
I have little experience with either templating scheme, and I am
seeking advice on the pros and cons of these two approaches. I
understand that the subject of XML vs. relational databases is
contentious. Let's assume that I am comfortable implementing either
variety. and that the database will be small enough that performance
considerations will not be foremost in the design. Also, if
performance becomes a problem, I could create an XML wrapper around
DBI results. So the comparison becomes that of a perl templating
language vs. XSLT.
Some questions pertaining to the comparison are
- I'd like the code to be maintainable after I leave. Is it
reasonable to expect novice programmers to be able to learn to manipulate
and modify Template Toolkit templates? What about XSLT?
- XSLT seems like a cool language in theory, but how is it in
practice? Does it DWIM, or is it fussy and frustrating?
- One aspect of XML/XSLT I like is that they are language
neutral. Once the docs and templates are written, they can be
processed in any number of languages: Perl, Java, C, C++, Python,
etc. On the other hand, Perl and associated templating systems are in
widespread use and not going away any time soon, so perhaps language
neutrality is not so important?
- Associated with XSLT is XSL-FO, an XML formatting language. Is
XSL-FO commonly used as part of the transformation process?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.