It seems that TMPL_LOOP doesn't obey global_vars. I attached a fix that
borrows code from variable handling, but I'm not completely comfortable
with C code interfacing with perl so :)

tugrul@gandalf:~/HT_Bug$ ./test.pl 
HTML::Template 2.5
----------------------------------------------------------------------
Outside loop: B_VAR

        Inside loop: B_VAR; C_VAR_INLOOP1

                Inner loop: B_VAR; C_VAR_INLOOP1

                Inner loop: B_VAR; C_VAR_INLOOP2


        Inside loop: B_VAR; C_VAR_INLOOP2

                Inner loop: B_VAR; C_VAR_INLOOP1

                Inner loop: B_VAR; C_VAR_INLOOP2


----------------------------------------------------------------------

HTML::Template::JIT 0.03
----------------------------------------------------------------------
Outside loop: B_VAR

        Inside loop: B_VAR; C_VAR_INLOOP1


        Inside loop: B_VAR; C_VAR_INLOOP2


----------------------------------------------------------------------

#!/usr/bin/perl
use strict;
use HTML::Template;
use HTML::Template::JIT;

my $params = { 'B' => 'B_VAR', 'A' => [ { 'C' => 'C_VAR_INLOOP1' }, { 'C' => 'C_VAR_INLOOP2' } ] };

print "HTML::Template $HTML::Template::VERSION\n";
print "----------------------------------------------------------------------\n";
my $template_normal = HTML::Template->new(filename => 'test.tmpl', global_vars => 1);
$template_normal->param($params);
print $template_normal->output;
print "----------------------------------------------------------------------\n\n";

print "HTML::Template::JIT $HTML::Template::JIT::VERSION\n";
print "----------------------------------------------------------------------\n";
my $template_jit = HTML::Template::JIT->new(filename => 'test.tmpl', global_vars => 1, jit_path => '.');
$template_jit->param($params);
print $template_jit->output;
print "----------------------------------------------------------------------\n";
Outside loop: <TMPL_VAR NAME=B>
<TMPL_LOOP NAME=A>
        Inside loop: <TMPL_VAR NAME=B>; <TMPL_VAR NAME=C>
        <TMPL_LOOP NAME=A>
                Inner loop: <TMPL_VAR NAME=B>; <TMPL_VAR NAME=C>
        </TMPL_LOOP>
</TMPL_LOOP>
--- Compiler.pm.orig    Wed Jun 26 10:09:01 2002
+++ Compiler.pm Wed Jun 26 10:39:47 2002
@@ -218,8 +218,23 @@
       # remember text_size before loop
       my $old_text_size = $self->{text_size};
 
+      # get name for this variable from reverse map
+      $name = $reverse_param_map{$line};
+
+      # check var cache - can't use it for escaped variables
+      if (exists $vars{$name}) {
+        $var = $vars{$name};
+      } 
+      
+      # load a new one if needed
+      else {
+        $var = $self->_get_var("SV *", "&PL_sv_undef", \@pool);
+        push @top, _load_var($name, $var, $offset, $self->{global_vars});
+        $vars{$name} = $var;
+      }
+      
       # output the loop start
-      push @code, $self->_start_loop($reverse_param_map{$line}, $offset, 
+      push @code, $self->_start_loop($var, $offset, 
                                     $loop_offset);
 
       # output the loop code
@@ -328,9 +343,8 @@
   }
 
   push @code, <<END;
-temp_svp = hv_fetch(param_map[$offset], "$name_string", $name_len, 0);
-if (temp_svp && (*temp_svp != &PL_sv_undef)) {
-   $av = (AV *) SvRV(*temp_svp);      
+if ($name != &PL_sv_undef) {
+   $av = (AV *) SvRV($name);      
    $av_len = av_len($av);
 
    for($counter = 0; $counter <= $av_len; $counter++) {

Reply via email to