From da1acc4f047b4247f5679b94bbd95f7b56196534 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 2 Oct 2008 21:17:04 +0200 Subject: [PATCH] Moved template variables and functions to a separate package. --- UCW/Temple.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/UCW/Temple.pm b/UCW/Temple.pm index 32526d7..904a2cf 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -11,7 +11,6 @@ no strict 'vars'; use IO::File; our @cond; -our $temp; sub get_nested($$$) { my ($r,$left,$right) = @_; @@ -35,7 +34,7 @@ sub get_nested($$$) { sub eval_if_ok($) { if ($cond[0] > 0) { my $x = shift; - my $res = eval $x; + my $res = eval "package T; $x"; return $res unless $@; die "Error evaluating $x: $@"; } else { @@ -147,16 +146,20 @@ sub process_string($) { finish(); } -### Commands available from the templates +### Perl commands embedded in the templates are evaluated in this package ### + +package T; + +our $temp; sub include { my $fn = shift @_; while (@_) { my $v = shift @_; $temp = shift @_; - eval_if_ok("\$$v = \$temp"); + UCW::Temple::eval_if_ok("\$$v = \$temp"); } - parse_file($fn); + UCW::Temple::parse_file($fn); } sub load { -- 2.39.5