]> ruin.nu Git - ndwebbie.git/blobdiff - index.pl
cache templates in memory
[ndwebbie.git] / index.pl
index f9a534539ba86c8d1272a8feb00be22db666af47..ddc22f4ac6365b49190304eb01c75d0b8ae1488a 100755 (executable)
--- a/index.pl
+++ b/index.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -T
 #**************************************************************************
 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
 #                                                                         *
@@ -25,16 +25,24 @@ use DBI;
 use DBD::Pg qw(:pg_types);
 use strict;
 
-
 my $cgi = new CGI;
-
-chdir $ENV{'DOCUMENT_ROOT'};
+local $ND::DBH;
+local $ND::USER;
+local $ND::UID;
+local $ND::PLANET;
+local $ND::TEMPLATE;
+local $ND::BODY;
+local $ND::TICK;
 
 our $DBH = undef;
 our $USER = $ENV{'REMOTE_USER'};
 my $error;
 
-our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1);
+if ($ENV{'DOCUMENT_ROOT'} =~ m{((\w|/)+)}){
+       chdir $1;
+}
+
+our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1, cache => 1);
 
 for my $file ("db.pl","include.pl"){
        unless (my $return = do $file){
@@ -76,10 +84,10 @@ our $AJAX = 1;
 my $type = 'text/html';
 if ($XML){
        $type = 'text/xml';
-       $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl");
-       $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl");
+       $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl", cache => 1);
+       $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl", cache => 1);
 }else{
-       $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl", global_vars => 1);
+       $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl", global_vars => 1, cache => 1);
        $ND::BODY->param(PAGE => $page);
 }