]> mj.ucw.cz Git - temple.git/commitdiff
Moved template variables and functions to a separate package.
authorMartin Mares <mj@ucw.cz>
Thu, 2 Oct 2008 19:17:04 +0000 (21:17 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 2 Oct 2008 19:17:04 +0000 (21:17 +0200)
UCW/Temple.pm

index 32526d7c19157c569b929bf029cd7caace4ad082..904a2cf91cb8b64460fbedbdebc479e52c5ce40a 100644 (file)
@@ -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 {