logo       

FW: Hooking into template file accesses: msg#00130

Subject: FW: Hooking into template file accesses
Sorry if this is a re-post.  I had some list subscription trouble. 

> -----Original Message-----
> From: templates-admin-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx 
> [mailto:templates-admin-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx] On 
> Behalf Of Paul 
> LeoNerd Evans
> Sent: Monday, February 27, 2006 8:20 PM
> To: templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx
> Subject: [Templates] Hooking into template file accesses
> 
[snip]
>
>   2. It tracks the latest mtime of any file (or other data) used
during
>      the building of the page, in order to set the "Last_Modified:"
>      header on reply and to implement the "If_Modified_Since:" logic.

You could subclass Template::Provider::fetch and add your mtime checking
code to it.  (*untested code*) e.g.

    package My::Mtime::Provider;
    use base qw(Template::Provider);

    sub init_mtime {
        my ($self) = @_;
        $self->{_my_mtime} = 0;
    }

    sub check_mtime {
        my ($self,$doc) = @_;
        # remember this mtime if it's newer than
        # anything else we've seen
        if ($doc && $doc->modtime > $self->{_my_mtime}) {
            $self->{_my_mtime} = $doc->modtime;
        }
    }
    
    sub get_mtime {
        my ($self) = @_;
        return $self->{_my_mtime};
    }

    sub fetch {
        my $self = shift;
        my ($doc,$reason) = $self->SUPER::fetch(@_);
        $self->check_mtime($doc);
        return ($doc,$reason);
    }

    1;

Then you install the provider like this:

    my %config = ( COMPILE_DIR => '/wherever', @other_opts );
    my $provider = My::Mtime::Provider->new(\%config);
    my $template = Template->new(%config,
        LOAD_TEMPLATES => [$provider]);

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.

HTH
Philip


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe