#####################################################################
#
-# 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{ };
======================================================================
EOM
exit 1;
-}
+} ## end sub AUTOLOAD
sub DESTROY {
_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;
$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;
}
$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;
$self->logfile_output( EMPTY_STRING, "$out_str\n" );
}
return;
-}
+} ## end sub black_box
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;
------ ----- - - -------- -------------------------------------------
EOM
return;
-}
+} ## end sub write_column_headings
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 ) = @_;
}
}
return;
-}
+} ## end sub logfile_output
sub get_saw_brace_error {
my $self = shift;
$self->warning("No further warnings of this type will be given\n");
}
return;
-}
+} ## end sub brace_warning
sub complain {
$self->write_logfile_entry($msg);
}
return;
-}
+} ## end sub complain
sub warning {
}
}
return;
-}
+} ## end sub warning
sub report_definite_bug {
my $self = shift;
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
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;
-