]> git.donarmstrong.com Git - perltidy.git/commitdiff
cleaned up backup-in-place coding to use streamhandle
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 22 Mar 2020 23:42:54 +0000 (16:42 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 22 Mar 2020 23:42:54 +0000 (16:42 -0700)
lib/Perl/Tidy.pm

index 90abd8c5758b41c732447c2fe02f342a2616639e..6523b2285a3f269f4ebe37093f337dc803bd8b82 100644 (file)
@@ -1421,15 +1421,13 @@ EOM
             seek( $output_file, 0, 0 )
               or Die("unable to rewind a temporary file for -b option: $!\n");
 
-            # TODO: maybe use streamhandle here
-            my $fout = IO::File->new("> $input_file")
-              or Die(
+            my ( $fout, $iname ) =
+              Perl::Tidy::streamhandle( $input_file, 'w', $is_encoded_data );
+            if ( !$fout ) {
+                Die(
 "problem re-opening $input_file for write for -b option; check file and directory permissions: $!\n"
-              );
-            if ($is_encoded_data) {
-                binmode $fout, ":raw:encoding(UTF-8)";
+                );
             }
-            else { binmode $fout }
 
             my $line;
             while ( $line = $output_file->getline() ) {