Blob Blame History Raw
--- bin/perltidy
+++ bin/perltidy
@@ -2632,9 +2632,8 @@ in any way.  And, of course, it does not
 =item Temporary files
 
 Under the -html option with the default --pod2html flag, a temporary file is
-required to pass text to Pod::Html.  Unix systems will try to use the POSIX
-tmpnam() function.  Otherwise the file F<perltidy.TMP> will be temporarily
-created in the current working directory.
+required to pass text to Pod::Html.  The temporary file is created using
+File::Temp::tempfile().
 
 =item Special files when standard input is used
 
--- lib/Perl/Tidy.pm
+++ lib/Perl/Tidy.pm
@@ -63,6 +63,7 @@ use vars qw{
 
 use IO::File;
 use File::Basename;
+use File::Temp qw(tempfile);
 
 BEGIN {
     ( $VERSION = q($Id: Tidy.pm,v 1.68 2007/08/01 16:22:38 perltidy Exp $) ) =~ s/^.*\s+(\d+)\/(\d+)\/(\d+).*$/$1$2$3/; # all one line for MakeMaker
@@ -222,39 +223,6 @@ sub catfile {
     return undef;
 }
 
-sub make_temporary_filename {
-
-    # Make a temporary filename.
-    #
-    # The POSIX tmpnam() function tends to be unreliable for non-unix
-    # systems (at least for the win32 systems that I've tested), so use
-    # a pre-defined name.  A slight disadvantage of this is that two
-    # perltidy runs in the same working directory may conflict.
-    # However, the chance of that is small and managable by the user.
-    # An alternative would be to check for the file's existance and use,
-    # say .TMP0, .TMP1, etc, but that scheme has its own problems.  So,
-    # keep it simple.
-    my $name = "perltidy.TMP";
-    if ( $^O =~ /win32|dos/i || $^O eq 'VMS' || $^O eq 'MacOs' ) {
-        return $name;
-    }
-    eval "use POSIX qw(tmpnam)";
-    if ($@) { return $name }
-    use IO::File;
-
-    # just make a couple of tries before giving up and using the default
-    for ( 0 .. 1 ) {
-        my $tmpname = tmpnam();
-        my $fh = IO::File->new( $tmpname, O_RDWR | O_CREAT | O_EXCL );
-        if ($fh) {
-            $fh->close();
-            return ($tmpname);
-            last;
-        }
-    }
-    return ($name);
-}
-
 # Here is a map of the flow of data from the input source to the output
 # line sink:
 #
@@ -4615,16 +4583,7 @@ sub pod_to_html {
     }
 
     # Pod::Html requires a real temporary filename
-    # If we are making a frame, we have a name available
-    # Otherwise, we have to fine one
-    my $tmpfile;
-    if ( $rOpts->{'frames'} ) {
-        $tmpfile = $self->{_toc_filename};
-    }
-    else {
-        $tmpfile = Perl::Tidy::make_temporary_filename();
-    }
-    my $fh_tmp = IO::File->new( $tmpfile, 'w' );
+    my ($fh_tmp,$tmpfile) = tempfile();
     unless ($fh_tmp) {
         warn "unable to open temporary file $tmpfile; cannot use pod2html\n";
         return $success_flag;