Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
In my spare time, I am working on a homegrown content management system. It's built around a fairly standard setup that consists of:
  • perl, with CGI, XML::Twig, XML::RSS and DBI
  • MySQL
  • Apache (still have to figure out mod_perl)
  • X(HT)ML templates, styled using CSS
So, on any page that this system serves up, when a user clicks on a link, the request goes to the server, it sends a perl script into action which asks XML::Twig (which I think is fantastic) to parse an XHTML layout template and deploy the twighandlers that populate the page with content from the database based on the conditions set by the CGI parameters. For example, when the parsing process comes along a <span class="timestamp"/> it inserts the 'last updated' timestamp for that page from the database as element text for the <span/>. Once the parsing is done, the twig is printed out, the server sends it back to the user, who is happy with the results.

As I was working on this I noticed that I work from the underlying idea that different languages (perl, SQL, XHTML, CSS) must not be combined within the same code block or file because they are meant to do different things (request processing, database interaction, layout and style, respectively). So that, for example, if you know a wizard in web design, she can work on the layout without having to work around perl code in the same file.

Most examples that demonstrate CGI programming show how a perl script might send out strings of HTML or text that are more or less hardcoded into the script, e.g.
print qq{Content-type: text/plain\n\nHello World!\n};
This strikes me as bad practice because two different things (the code that gets executed on the server side and whatever is sent back to the user) are combined in the same file, creating a maintainability nightmare.

Similarly, most examples on php start out by embedding PHP code into HTML files, and the same is true for embedded perl and for things like Mason (I think), as well as most other systems commonly used to generate dynamic web pages, such as ASP. Aren't these all bad approaches? Shouldn't different languages that are meant to do different things be separated one from another? Wasn't there a sage who spoke wise words about this?

What's your view?

In reply to Code Conflation: Considered Harmful? by rvosa

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2018-02-23 12:55 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (302 votes). Check out past polls.