On Tue, Feb 28, 2006 at 12:04:34PM -0500, Garrett, Philip (MAN-Corporate) wrote: > You could subclass Template::Provider::fetch and add your mtime checking > code to it. (*untested code*) e.g.
<snip>
I tried that; it worked exactly as I'd expected. :)
> Then, every time you process a template, do this:
>
> $provider->init_mtime();
> $template->process($template_name) || die $template->error;
> my $mtime = $provider->get_mtime();
>
> I hope the code doesn't have too many bugs in it.
Ah, well, now you come to mention it.... :)
The code does run and does work, in that after that line, $mtime does
contain the latest modification date of any file it read. This is
suitable for the FastCGI script to set the "Last-Modified" header for
the HTTP response.
But, the mtime is also needed earlier than that; I place it in a
template variable, so the page template can put a "Last modified: .."
footer on the bottom; thus:
Last modified: [% strftime( "%Y/%m/%d %H:%M:%S", mtime ) %]
So the mtime has to be available earlier than this. But the problem is,
how do we know what it will be without expanding the template? We could
of course just expand the template twice; first time just to get the
times, then again to actually run it. Seems rather wasteful though...
Perhaps cache the results, so we can prefil the hash with what we think
is likely the time, and only run it a second time if we noted a later
time than we were expecting? Again, sounds quite wasteful though...
So my question is really a matter of knowing exactly when the value from
the variables hash will be read. If it is read sufficiently late, then
all the code would need to do is update a reference to that particular
hash element, and if it was looked at late enough, it should be fine. I
do at least know the mtime of the actual page template, and of the
WRAPPER template containing it, so I could start off with those. If the
expansion is done late enough, the only things that would miss then
would be any file INCLUDEd after the "Last modified:" line in the text.
But that's near the bottom anyway, so it should be OK.
Thoughts?
--
Paul "LeoNerd" Evans
[EMAIL PROTECTED]
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
signature.asc
Description: Digital signature
