Greetings, Fellow Monks.

I am currently working on a project where I am using HTML::Template to populate our template files with the output of our CGI scripts.

Recently, I stumbled accross the fact that you can pass an already opened filehandle in to HTML::Template's new() method.

I had the idea of converting my CGI scripts to store their templates inside themselves - using the __END__ token, like so:

#!/usr/bin/perl -w ## stuff here __END__ <html> <!--template stuff here--> </html>

However, I can't figure out how to actually pass the DATA filehandle to my "Page" module, which is what I'm using to control my templates and output.

The Page module takes a hash of parameters, one of which is the parameter "template". I would like to convert this to be the filehandle that gets passed in to HTML::Template's new() method, but cannot seem to figure out how (Currently, it's the filename that gets passed).

Does anyone know how I would pass the DATA filehandle into my module's constructor function, so that I can use it in a call to HTML::Template->new() within my module?

Thanks,

Spidy



Resolution: As it turns out, HTML::Template has a 'feature' where if you set cache => 1 when you're passing in a filehandle, it does not work.


In reply to resolved: Converting code to use DATA filehandle instead of external templates by Spidy

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.