[htmltmpl] H::T bug
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-02-25 00:29:21
|
Hi Sam and others, One problem I have encountered frequently enough to be annoying (but not = enough to do anything about) was that ocassionally the line numbers of a = TMPL error, didn't match up with the line that the error occurred on. = As a result of my work on making H::T support custom TMPL_xxxx tag = definitions, I came across this bug as it become rather blatent, and = thus have found the solution for it. On line 2259/2260 H::T implements: pop(@fstack), (*fname, *fcounter, *fmax) =3D \ ( = @{$fstack[$#fstack]} ) if ($fcounter > $fmax); The implementation of TMPL_INCLUDE essentially inserts the included = files' text at the current point of the statement, thus any text after = the TMPL_INCLUDE (before the next 'chunk'), is essentially appended to = the end of the included text.=20 This code suffers the problem that if a TMPL_INCLUDE is referenced near = the end of a template file, then it doesn't correctly unroll the = @fstack, thus it: - incorrectly handles the end of the previous file -> as the previous = file ends up with the wrong line number - doesn't unroll more than one included file (thus each previous file = will also end up with the wrong line number, as well) - it is possible to hit a max include limit (ie TMPL_INCLUDE's > = max_includes), due to the mis-handling of the end of the included = template file(s). The solution to this is to take into account the number of '\n's = introduced by the appending of the text before the next chunk. The code = should read: while ($fcounter > $fmax) { my $counter_offset =3D $fcounter - $fmax; pop(@fstack), (*fname, *fcounter, *fmax) =3D \ ( = @{$fstack[$#fstack]} ); $fcounter +=3D $counter_offset; } cheers, Mathew PS. I was able to find this error by adding a support to H::T for an = 'includes_debug' option (ie. I added this option and the following code = around line 2208). Which if set, the following code gets executed: if ($options->{includes_debug}) { require 'Data/Dumper.pm'; print STDERR "TMPL_INCLUDE stack: ", = Data::Dumper::Dumper(\@fstack); } ie: I think this would be a useful addition to compliment the existing = debug options. |