sure thing - see attached.

I have a few other ideas about enhancements which you may or may not
be interested in - should I furnish a list of ideas?

Mathew

Sam Tregar wrote:
> On Fri, 17 Nov 2006, Mathew Robertson wrote:
> 
>> Since you mentioned that you are hoping to do a release sooner or
>> later, could you consider the following two changes:
> 
> Good stuff.  Any chance I could get it in unified diff format (diff
> -u)?
> 
> -sam
--- Template.pm 2006-11-17 14:24:47.000000000 +1100
+++ Template.pm.new     2006-11-17 14:28:31.000000000 +1100
@@ -2319,9 +2319,12 @@
     $fcounter += scalar(@{[$chunk =~ m/(\n)/g]});
     # if we just crossed the end of an included file
     # pop off the record and re-alias to the enclosing file's info
-    pop(@fstack), (*fname, *fcounter, *fmax) = \ ( @{$fstack[$#fstack]} )
-      if ($fcounter > $fmax);
-    
+    while ($fcounter > $fmax) {
+      my $counter_offset = $fcounter - $fmax;
+      pop(@fstack), (*fname, *fcounter, *fmax) = \ ( @{$fstack[$#fstack]} );
+      $fcounter += $counter_offset;
+    }
+
   } # next CHUNK
 
   # make sure we don't have dangling IF or LOOP blocks
@@ -2622,28 +2625,39 @@
   # support the associate magic, searching for undefined params and
   # attempting to fill them from the associated objects.
   if (scalar(@{$options->{associate}})) {
-    # prepare case-mapping hashes to do case-insensitive matching
-    # against associated objects.  This allows CGI.pm to be
-    # case-sensitive and still work with asssociate.
-    my (%case_map, $lparam);
-    foreach my $associated_object (@{$options->{associate}}) {
-      # what a hack!  This should really be optimized out for case_sensitive.
-      if ($options->{case_sensitive}) {
-        map {
-          $case_map{$associated_object}{$_} = $_
-        } $associated_object->param();
-      } else {
-        map {
-          $case_map{$associated_object}{lc($_)} = $_
-        } $associated_object->param();
-      }
-    }
-
+    my @undef_params;
     foreach my $param (keys %{$self->{param_map}}) {
-      unless (defined($self->param($param))) {
-      OBJ: foreach my $associated_object (reverse @{$options->{associate}}) {
-          $self->param($param, scalar 
$associated_object->param($case_map{$associated_object}{$param})), last OBJ
-            if (exists($case_map{$associated_object}{$param}));
+      next if (defined $self->param($param));
+      push @undef_params, $param;
+    }
+    if (scalar(@undef_params)) {
+      my $value;
+      # if case sensitive mode or no CGI objects, we can use the fast path
+      if ($options->{case_sensitive} or (grep { !/^1/ } map { 
UNIVERSAL::isa($_,'HTML::Template') } @{$options->{associate}}) == 0) {
+        foreach my $param (@undef_params) {
+          foreach my $associated_object (reverse
[EMAIL PROTECTED]>{associate}}) {
+            $value = $associated_object->param($param);
+            next unless (defined $value);
+            $self->param($param, scalar $value);
+            last;
+          }
+        }
+      } else {
+        my %case_map;
+        foreach my $associated_object (@{$options->{associate}}) {
+          map { $case_map{$associated_object}{lc($_)} = $_ } 
$associated_object->param();
+        }
+        my $associated_param;
+        foreach my $param (@undef_params) {
+          foreach my $associated_object (reverse @{$options->{associate}}) {
+            $associated_param = $case_map{$associated_object}{$param};
+            next unless (defined $associated_param);
+            $value = $associated_object->param($associated_param);
+            next unless (defined $value);
+            $self->param($param, scalar $value);
+            last;
+          }
         }
       }
     }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to