1 #####################################################################
3 # The Perl::Tidy::Diagnostics class writes the DIAGNOSTICS file, which is
4 # useful for program development.
6 # Only one such file is created regardless of the number of input
7 # files processed. This allows the results of processing many files
8 # to be summarized in a single file.
10 # Output messages go to a file named DIAGNOSTICS, where
11 # they are labeled by file and line. This allows many files to be
12 # scanned at once for some particular condition of interest. It was
13 # particularly useful for developing guessing strategies.
15 # NOTE: This feature is deactivated in final releases but can be
16 # reactivated for debugging by un-commenting the 'I' options flag
18 #####################################################################
20 package Perl::Tidy::Diagnostics;
23 our $VERSION = '20220217';
27 # Catch any undefined sub calls so that we are sure to get
28 # some diagnostic information. This sub should never be called
29 # except for a programming error.
31 return if ( $AUTOLOAD =~ /\bDESTROY$/ );
32 my ( $pkg, $fname, $lno ) = caller();
33 my $my_package = __PACKAGE__;
35 ======================================================================
36 Error detected in package '$my_package', version $VERSION
37 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
38 Called from package: '$pkg'
39 Called from File '$fname' at line '$lno'
40 This error is probably due to a recent programming change
41 ======================================================================
48 # required to avoid call to AUTOLOAD in some versions of perl
55 _write_diagnostics_count => 0,
56 _last_diagnostic_file => "",
63 my ( $self, $input_file ) = @_;
64 $self->{_input_file} = $input_file;
68 sub write_diagnostics {
69 my ( $self, $msg ) = @_;
71 unless ( $self->{_write_diagnostics_count} ) {
72 open( $self->{_fh}, ">", "DIAGNOSTICS" )
73 or Perl::Tidy::Die("couldn't open DIAGNOSTICS: $!\n");
76 my $fh = $self->{_fh};
77 my $last_diagnostic_file = $self->{_last_diagnostic_file};
78 my $input_file = $self->{_input_file};
79 if ( $last_diagnostic_file ne $input_file ) {
80 $fh->print("\nFILE:$input_file\n");
82 $self->{_last_diagnostic_file} = $input_file;
83 my $input_line_number = Perl::Tidy::Tokenizer::get_input_line_number();
84 $fh->print("$input_line_number:\t$msg");
85 $self->{_write_diagnostics_count}++;