|Perl: the Markov chain saw|
resolved: Converting code to use DATA filehandle instead of external templatesby Spidy (Chaplain)
|on Nov 20, 2007 at 04:48 UTC||Need Help??|
Spidy has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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?
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.