My task is to write Perl modules that, when plugged into xyz template system, produces flat HTML. If my Java terminology is correct, think of it as a servlet. The template system is not my concern, but rather how to best construct this type of modular Perl. The end goal is to have a series of files, that generate HTML. They can be used however, whenever, and as often as liked.
As an example, suppose someone down the hall created the following:
<html>
<body>
<table>
<tr>
<td>[% $monks->getNames() %]</td>
...etc...
The template system would know that '$monks->getNames()' is Perl and would trigger my code to return the expected HTML.
Here are my thoughts...
These modules would have the necessary HTML embedded within, as well as the Perl logic. My thought currently is to have the HTML stored under __DATA__ so that it is relatively seperate from all Perl code. What I want to avoid is having a seperate file, but instead having the module as a total package. The simplest case would return the contents of <DATA> as a string. The string would be plugged in by the template system.
I want to keep the modules fairly similar in concept. As in, I don't want to have 50 subroutines, all with different names. Instead, I'd rather have each module be contained within a seperate package, so that each module could have a subroutine called getContent() that would look to <DATA> and return the correct string. Thoughts?
I'll have to do some substitutions within the HTML code stored under __DATA__. I plan to use something similar to the "template" system in the Perl Cookbook. I will also need to "require" specific files that were written by other developers, for things like database connections, etc. Will this get tricky while using packages?
I'm hoping to get some input on the design aspect from someone who has perhaps tackled such an approach. Any and all information is appreciated..
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.