[Po4a-devel] [PATCH] Use File::Temp::tempfile instead of File::Temp->tempfile

Richard W.M. Jones rjones at redhat.com
Wed Apr 17 10:33:26 UTC 2013


On some versions of Perl, using File::Temp->tempfile gives the error:

  'tempfile' can't be called as a method at -e line 1.

which is true because tempfile shouldn't be used as a method.

This patch fixes the occurrences in the po4a-0.44 source.

Note this reveals a subtle bug too.  There was some code which did:

  File::Temp->tempfile ($filename, ...)

In this case, the first arg to the "method" tempfile is the File::Temp
object, so AFAICT the $filename is being ignored or at least not used
correctly.  In this case $filename contained a full path like
"po/pod/foo".  If you fix the method bug, $filename is suddenly being
used for the first time, and since it contains a full path, the
program breaks (because the parent directories don't exist).

Therefore I replaced that code with:

  $basename = basename ($filename);
  File::Temp::tempfile ($basename, ...)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
-------------- next part --------------
diff -ur po4a-0.44.old/lib/Locale/Po4a/Po.pm po4a-0.44/lib/Locale/Po4a/Po.pm
--- po4a-0.44.old/lib/Locale/Po4a/Po.pm	2012-10-21 00:03:24.000000000 +0100
+++ po4a-0.44/lib/Locale/Po4a/Po.pm	2013-04-17 11:26:54.749652129 +0100
@@ -572,7 +572,8 @@
 
     if (-e $filename) {
         my ($tmp_filename);
-        (undef,$tmp_filename)=File::Temp->tempfile($filename."XXXX",
+        my $basename = basename($filename);
+        (undef,$tmp_filename)=File::Temp::tempfile($basename."XXXX",
                                                    DIR    => "/tmp",
                                                    OPEN   => 0,
                                                    UNLINK => 0);
diff -ur po4a-0.44.old/lib/Locale/Po4a/Wml.pm po4a-0.44/lib/Locale/Po4a/Wml.pm
--- po4a-0.44.old/lib/Locale/Po4a/Wml.pm	2012-10-21 00:03:24.000000000 +0100
+++ po4a-0.44/lib/Locale/Po4a/Wml.pm	2013-04-17 11:27:43.904492845 +0100
@@ -81,7 +81,7 @@
 sub read {
     my ($self,$filename)=@_;
     my $tmp_filename;
-    (undef,$tmp_filename)=File::Temp->tempfile("po4aXXXX",
+    (undef,$tmp_filename)=File::Temp::tempfile("po4aXXXX",
                                                 DIR    => "/tmp",
                                                 SUFFIX => ".xml",
                                                 OPEN   => 0,
diff -ur po4a-0.44.old/po4a po4a-0.44/po4a
--- po4a-0.44.old/po4a	2012-10-21 00:03:24.000000000 +0100
+++ po4a-0.44/po4a	2013-04-17 11:26:05.938810267 +0100
@@ -1209,7 +1209,7 @@
     chdir $po4a_opts{"srcdir"}
 	if (defined $po4a_opts{"srcdir"});
     if ($po4a_opts{"split"}) {
-        (undef,$pot_filename)=File::Temp->tempfile("po4aXXXX",
+        (undef,$pot_filename)=File::Temp::tempfile("po4aXXXX",
                                                    DIR    => "/tmp",
                                                    SUFFIX => ".pot",
                                                    OPEN   => 0,
@@ -1239,7 +1239,7 @@
         # Create a temporary POT, and check if the old one needs to be
         # updated (unless --force was specified).
         unless ($po4a_opts{"force"}) {
-            (undef,$tmp_file)=File::Temp->tempfile("po4aXXXX",
+            (undef,$tmp_file)=File::Temp::tempfile("po4aXXXX",
                                                    DIR    => "/tmp",
                                                    SUFFIX => ".pot",
                                                    OPEN   => 0,
@@ -1270,7 +1270,7 @@
     # Generate a complete .po
     foreach my $lang (sort keys %po_filename) {
         my $tmp_bigpo;
-        (undef,$tmp_bigpo)=File::Temp->tempfile("po4aXXXX",
+        (undef,$tmp_bigpo)=File::Temp::tempfile("po4aXXXX",
                                                 DIR    => "/tmp",
                                                 SUFFIX => "-$lang.po",
                                                 OPEN   => 0,
@@ -1336,7 +1336,7 @@
             my $tmp_file;
             # Create a temporary PO, and check if the old one needs to be
             # updated (unless --force was specified).
-            (undef,$tmp_file)=File::Temp->tempfile("po4aXXXX",
+            (undef,$tmp_file)=File::Temp::tempfile("po4aXXXX",
                                                    DIR    => "/tmp",
                                                    SUFFIX => ".po",
                                                    OPEN   => 0,
diff -ur po4a-0.44.old/po4a-updatepo po4a-0.44/po4a-updatepo
--- po4a-0.44.old/po4a-updatepo	2012-10-21 00:03:24.000000000 +0100
+++ po4a-0.44/po4a-updatepo	2013-04-17 11:26:05.938810267 +0100
@@ -248,7 +248,7 @@
 	if $_ eq '-'  && !-e '-'} @pofiles;
 
 my ($pot_filename);
-(undef,$pot_filename)=File::Temp->tempfile("po4a-updatepoXXXX",
+(undef,$pot_filename)=File::Temp::tempfile("po4a-updatepoXXXX",
 					   DIR    => "/tmp",
 					   SUFFIX => ".pot",
 					   OPEN   => 0,
diff -ur po4a-0.44.old/scripts/msguntypot po4a-0.44/scripts/msguntypot
--- po4a-0.44.old/scripts/msguntypot	2012-10-21 00:03:24.000000000 +0100
+++ po4a-0.44/scripts/msguntypot	2013-04-17 11:26:05.939810264 +0100
@@ -195,7 +195,7 @@
 
 # Get all po files and report differences in them
 my ($pofile);
-(undef,$pofile)=File::Temp->tempfile("po4aXXXX",
+(undef,$pofile)=File::Temp::tempfile("po4aXXXX",
     DIR    => "/tmp",
     SUFFIX => ".po",
     OPEN   => 0,


More information about the Po4a-devel mailing list