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.

++t


diff -ru Template-Toolkit-2.05/lib/Template/Document.pm 
Template-Toolkit-2.05.new/lib/Template/Document.pm
--- Template-Toolkit-2.05/lib/Template/Document.pm      Tue Sep 11 08:10:41 
2001+++ Template-Toolkit-2.05.new/lib/Template/Document.pm  Mon Oct 22 
10:18:40 2001@@ -32,7 +32,7 @@
 use vars qw( $VERSION $ERROR $COMPERR $DEBUG $AUTOLOAD );
 use base qw( Template::Base );
 use Template::Constants;
-use Fcntl qw(O_WRONLY O_CREAT);
+use Fcntl qw(O_WRONLY O_CREAT O_TRUNC);
 
 $VERSION = sprintf("%d.%02d", q$Revision: 2.27 $ =~ /(\d+)\.(\d+)/);
 
@@ -248,7 +248,7 @@
        $ERROR = "invalid filename: $file";
        return undef;
     };
-    sysopen(CFH, $cfile, O_CREAT|O_WRONLY) or do {
+    sysopen(CFH, $cfile, O_CREAT|O_WRONLY|O_TRUNC) or do {
        $ERROR = $!;
        return undef;
     };

-- 
Tony Payne  :  Sr. Software Engineer  :  PETsMART.com  :  626-817-7151


Reply via email to