# subroutine name: process_template # Input: template filename, reference to hash {tag_name=>tag_value} # Processes tags and tags # inside template file. tags are replaced with corresponding values. # Returns: string (result of tempate file processing). # Global variables used: # %template_subst - hash for templates substitutions # %templates_cache - caching hash for small templates (<5000 bytes) # $templates_dir - filesystem path to templates dir (without trailing slash) # $admin - admin works with script (disable template substitution feature) sub process_template { local ($templatefile, $namespace) = @_; my $template_content; if ($template_subst{$templatefile} ne "" && !$admin) { # replace filename, if this name found in template substitution hash $templatefile=$template_subst{$templatefile}; } if ($templatefile=~m/^[\w\.\-\~]+$/s) { if (defined $templates_cache{$templatefile}) { $template_content = $templates_cache{$templatefile}; } else { my $fn="$templates_dir/$templatefile"; $| = 1; # Open template and read in open(TEMPLATE,"<$fn") or die("Error in subroutine process_template: can't open $fn. Reason: $!"); { local($/) = undef; $template_content =