> The following patch fixes the problem for me. I think what's going on is > that the two applications use different INCLUDE_PATHS to get to the > templates. When the application (which happens to be mod_perl in this case) > with the shorter include path writes the file, the file is shorter. Since > the files are being opened with sysopen without O_TRUNC, the characters at > the end of the file are left. Adding O_TRUNC causes the file to be truncated > on open, so no matter how short the resulting file, there should be no > trailing junk.
Nice work! Your fix is correct. Sorry about the bogus XS suggestion... This raises a related issue: TT doesn't appear to use any locking on the compiled template files. There is a race condition if multiple processes (eg: apache/mod_perl) try to write and/or load the compiled template files. A more robust way to write the compiled template file is to write to a unique file name (eg: use $$ as a suffix) and then do an unlink(old) and rename(old,new). That's still not perfect, but is probably reliable enough. More robust solutions would need to use locking or a similar mechanism, which often adds a performance hit and reduces portabilty. Craig
