I think the trick is using a templating system that allows you to use perl in it. This way, you can embed presentation logic in the presentation docs (templates) and keep the application logic clean.

In a typical web app you can manage the information flux like this:


 ---------       -------       ---------       -------       ----------
| REQUEST | --> | DISP. | --> | APPLIC. | --> | PRES. | --> | RESPONSE |
 ---------       -------      | LOGIC   |     | LOGIC |      ----------
                               ---------       -------
                                ^                 ^
                                |                 |
                                v                 v
                            -------            ----------
                           | CLASS |-         | TEMPLATE |-
                            -------  |-        ----------  |-
                              -------  |        -----------  |
                                -------           -----------


Note: DISP is for dispatcher

For templates, I am opting more and more for a mixed system, including ePerl for power and simple substitution/fixed chunks for speed when power is not needed.

In a sample case, the application subsystem can generate an object of class PersonList and the presentation subsystem passes it to a template supposed to show name and age of every person in the list. The template contains something along the lines of

<: # get parameter personList # this is the only way the template gets # information from other layers my $pList = param('personList'); :> ... <table> <tr><td><b>Name</b></td><td><b>Age</b></td></tr> <: for my $person ($pList->getAsList()) { print template('personRow')->apply( name=>$person->name, age=>$person->age ); } :> </table>
where template personRow is a simple substitution template of the form
<tr><td><:name:></td><td><:age:></td></tr>

The presentation subsystem can make use of modules and ad-hoc subroutines for automatic generation of HTML, which should not be accessed by the application subsystem.

One advantage of this approach is that even if things can get messy with the mixture of Perl and HTML, when something breaks it's easy to find where the error is located.


Cheers

Antonio Bellezza

The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket

In reply to Re: Meditations On HTML In Perl by abell
in thread Meditations On HTML In Perl by tadman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.