Hi,

some weeks ago i did a little "improvement" to HTML::Template, at least i
think it is a improvement ;)

It changes the way arrays/loops are handled.
1.) If you pass in a array-reference, it will be not dereferenced anymore
    I did this, so i can use a small Wrapper-class, which allows me to
    tie a database-statement to an array, and returning the results row by
    row, so i don't need to waste memory inside of mod_perl(Reading all
    results at once).

2.) HTML::Template::Loop::output was changed, so it appends to a given
    scalar-reference(the one from HTML::Template::output), this saves much
    memory if you have a big loop and combine it with the print_to-option.

I would be really happy if someone else could test these patch, and give
me some feedback/results/benchmarks/changes in memory-usage.

I send this patch to Sam Tregar weeks ago, and i never answered, but maybe
someone here thinks that it's worth to have a look at it, because AFAIK
many ppl use mod_perl+HTML::Template (i do it myself) ;)


ciao, Nico
--- Template.pm Sat Feb  2 00:01:37 2002
+++ Template.pm.x       Tue Jun 11 18:54:29 2002
@@ -1,6 +1,6 @@
 package HTML::Template;
 
-$HTML::Template::VERSION = '2.5';
+$HTML::Template::VERSION = '2.5-masta';
 
 =head1 NAME
 
@@ -2364,7 +2364,8 @@
     if (defined($value_type) and length($value_type) and ($value_type eq 'ARRAY' or 
((ref($value) !~ /^(CODE)|(HASH)|(SCALAR)$/) and $value->isa('ARRAY')))) {
       (ref($param_map->{$param}) eq 'HTML::Template::LOOP') or
         croak("HTML::Template::param() : attempt to set parameter '$param' with an 
array ref - parameter is not a TMPL_LOOP!");
-      $param_map->{$param}[HTML::Template::LOOP::PARAM_SET] = [@{$value}];
+#_masta_      $param_map->{$param}[HTML::Template::LOOP::PARAM_SET] = [@{$value}];
+      $param_map->{$param}[HTML::Template::LOOP::PARAM_SET] = $value;
     } else {
       (ref($param_map->{$param}) eq 'HTML::Template::VAR') or
         croak("HTML::Template::param() : attempt to set parameter '$param' with a 
scalar - parameter is not a TMPL_VAR!");
@@ -2508,7 +2509,7 @@
       defined($$line) and $result .= $$line;
     } elsif ($type eq 'HTML::Template::LOOP') {
       if (defined($line->[HTML::Template::LOOP::PARAM_SET])) {
-        eval { $result .= $line->output($x, $options->{loop_context_vars}); };
+        eval { $line->output($x, $options->{loop_context_vars},\$result); };
         croak("HTML::Template->output() : fatal error in loop output : $@") 
           if $@;
       }
@@ -2768,14 +2769,15 @@
   my $self = shift;
   my $index = shift;
   my $loop_context_vars = shift;
+  my $result_ref = shift;
   my $template = $self->[TEMPLATE_HASH]{$index};
   my $value_sets_array = $self->[PARAM_SET];
   return unless defined($value_sets_array);  
   
-  my $result = '';
   my $count = 0;
   my $odd = 0;
-  foreach my $value_set (@$value_sets_array) {
+  foreach my $value_set_x (@$value_sets_array) {
+    my $value_set = $value_set_x;
     if ($loop_context_vars) {
       if ($count == 0) {
         @{$value_set}{qw(__first__ __inner__ __last__)} = (1,0,$#{$value_sets_array} 
== 0);
@@ -2787,14 +2789,14 @@
       $odd = $value_set->{__odd__} = not $odd;
     }
     $template->param($value_set);    
-    $result .= $template->output;
+    $$result_ref .= $template->output;
     $template->clear_params;
     @{$value_set}{qw(__first__ __last__ __inner__ __odd__)} = (0,0,0,0)
       if ($loop_context_vars);
     $count++;
   }
 
-  return $result;
+#  return $result;
 }
 
 package HTML::Template::COND;

Reply via email to