From: Martin Mares Date: Thu, 2 Oct 2008 19:17:04 +0000 (+0200) Subject: Moved template variables and functions to a separate package. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;ds=sidebyside;h=da1acc4f047b4247f5679b94bbd95f7b56196534;p=temple.git Moved template variables and functions to a separate package. --- 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 {