]> git.donarmstrong.com Git - perltidy.git/blobdiff - lib/Perl/Tidy/Logger.pm
New upstream version 20230309
[perltidy.git] / lib / Perl / Tidy / Logger.pm
index 194ca81c7e3a4f824f1451b0096fad44b107fc40..fa3f5284286f5f06bc1869199422f6b144ed8a12 100644 (file)
@@ -1,15 +1,17 @@
 #####################################################################
 #
-# The Perl::Tidy::Logger class writes the .LOG and .ERR files
+# The Perl::Tidy::Logger class writes any .LOG and .ERR files
+# and supplies some basic run information for error handling.
 #
 #####################################################################
 
 package Perl::Tidy::Logger;
 use strict;
 use warnings;
-our $VERSION = '20220613';
+our $VERSION = '20230309';
 use English qw( -no_match_vars );
 
+use constant DEVEL_MODE   => 0;
 use constant EMPTY_STRING => q{};
 use constant SPACE        => q{ };
 
@@ -32,7 +34,7 @@ This error is probably due to a recent programming change
 ======================================================================
 EOM
     exit 1;
-}
+} ## end sub AUTOLOAD
 
 sub DESTROY {
 
@@ -99,13 +101,14 @@ sub new {
         _warning_count                 => 0,
         _complaint_count               => 0,
         _is_encoded_data               => $is_encoded_data,
-        _saw_code_bug      => -1,                   # -1=no 0=maybe 1=for sure
+        _saw_code_bug      => -1,                    # -1=no 0=maybe 1=for sure
         _saw_brace_error   => 0,
         _output_array      => [],
         _input_stream_name => $input_stream_name,
         _filename_stamp    => $filename_stamp,
+        _save_logfile      => $rOpts->{'logfile'},
     }, $class;
-}
+} ## end sub new
 
 sub get_input_stream_name {
     my $self = shift;
@@ -140,14 +143,14 @@ sub interrupt_logfile {
     $self->warning("\n");
     $self->write_logfile_entry( '#' x 24 . "  WARNING  " . '#' x 25 . "\n" );
     return;
-}
+} ## end sub interrupt_logfile
 
 sub resume_logfile {
     my $self = shift;
     $self->write_logfile_entry( '#' x 60 . "\n" );
     $self->{_use_prefix} = 1;
     return;
-}
+} ## end sub resume_logfile
 
 sub we_are_at_the_last_line {
     my $self = shift;
@@ -156,7 +159,7 @@ sub we_are_at_the_last_line {
     }
     $self->{_at_end_of_file} = 1;
     return;
-}
+} ## end sub we_are_at_the_last_line
 
 # record some stuff in case we go down in flames
 use constant MAX_PRINTED_CHARS => 35;
@@ -195,7 +198,7 @@ sub black_box {
         $self->logfile_output( EMPTY_STRING, "$out_str\n" );
     }
     return;
-}
+} ## end sub black_box
 
 sub write_logfile_entry {
 
@@ -204,7 +207,7 @@ sub write_logfile_entry {
     # add leading >>> to avoid confusing error messages and code
     $self->logfile_output( ">>>", "@msg" );
     return;
-}
+} ## end sub write_logfile_entry
 
 sub write_column_headings {
     my $self = shift;
@@ -223,7 +226,7 @@ lines  levels i k            (code begins with one '.' per indent level)
 ------  ----- - - --------   -------------------------------------------
 EOM
     return;
-}
+} ## end sub write_column_headings
 
 sub make_line_information_string {
 
@@ -277,7 +280,7 @@ sub make_line_information_string {
 "L$input_line_number:$output_line_number$extra_space i$guessed_indentation_level:$structural_indentation_level $ci_level $bk $nesting_string";
     }
     return $line_information_string;
-}
+} ## end sub make_line_information_string
 
 sub logfile_output {
     my ( $self, $prompt, $msg ) = @_;
@@ -299,7 +302,7 @@ sub logfile_output {
         }
     }
     return;
-}
+} ## end sub logfile_output
 
 sub get_saw_brace_error {
     my $self = shift;
@@ -328,7 +331,7 @@ sub brace_warning {
         $self->warning("No further warnings of this type will be given\n");
     }
     return;
-}
+} ## end sub brace_warning
 
 sub complain {
 
@@ -347,7 +350,7 @@ sub complain {
         $self->write_logfile_entry($msg);
     }
     return;
-}
+} ## end sub complain
 
 sub warning {
 
@@ -437,7 +440,7 @@ sub warning {
         }
     }
     return;
-}
+} ## end sub warning
 
 sub report_definite_bug {
     my $self = shift;
@@ -447,26 +450,21 @@ sub report_definite_bug {
 
 sub get_save_logfile {
 
-    # To be called after tokenizer has finished to make formatting more
-    # efficient.
-    my $self         = shift;
-    my $saw_code_bug = $self->{_saw_code_bug};
-    my $rOpts        = $self->{_rOpts};
-    return $saw_code_bug == 1 || $rOpts->{'logfile'};
-}
+    # Returns a true/false flag indicating whether or not
+    # the logfile will be saved.
+    my $self = shift;
+    return $self->{_save_logfile};
+} ## end sub get_save_logfile
 
 sub finish {
 
     # called after all formatting to summarize errors
-    my ( $self, $formatter ) = @_;
+    my ($self) = @_;
 
-    my $rOpts         = $self->{_rOpts};
     my $warning_count = $self->{_warning_count};
-    my $saw_code_bug  = $self->{_saw_code_bug};
+    my $save_logfile  = $self->{_save_logfile};
+    my $log_file      = $self->{_log_file};
 
-    my $save_logfile = $saw_code_bug == 1
-      || $rOpts->{'logfile'};
-    my $log_file = $self->{_log_file};
     if ($warning_count) {
         if ($save_logfile) {
             $self->block_log_output();    # avoid echoing this to the logfile
@@ -496,11 +494,13 @@ sub finish {
             my $routput_array = $self->{_output_array};
             foreach my $line ( @{$routput_array} ) { $fh->print($line) }
             if ( $log_file ne '-' && !ref $log_file ) {
-                eval { $fh->close() };
+                my $ok = eval { $fh->close(); 1 };
+                if ( !$ok && DEVEL_MODE ) {
+                    Fault("Could not close file handle(): $EVAL_ERROR\n");
+                }
             }
         }
     }
     return;
-}
+} ## end sub finish
 1;
-