line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# The Perl::Tidy::Diagnostics class writes the DIAGNOSTICS file, which is |
4
|
|
|
|
|
|
|
# useful for program development. |
5
|
|
|
|
|
|
|
# |
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. |
9
|
|
|
|
|
|
|
|
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. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
##################################################################### |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Perl::Tidy::Diagnostics; |
18
|
38
|
|
|
38
|
|
256
|
use strict; |
|
38
|
|
|
|
|
83
|
|
|
38
|
|
|
|
|
1115
|
|
19
|
38
|
|
|
38
|
|
244
|
use warnings; |
|
38
|
|
|
|
|
80
|
|
|
38
|
|
|
|
|
977
|
|
20
|
38
|
|
|
38
|
|
204
|
use English qw( -no_match_vars ); |
|
38
|
|
|
|
|
118
|
|
|
38
|
|
|
|
|
263
|
|
21
|
|
|
|
|
|
|
our $VERSION = '20230701'; |
22
|
|
|
|
|
|
|
|
23
|
38
|
|
|
38
|
|
14374
|
use constant EMPTY_STRING => q{}; |
|
38
|
|
|
|
|
84
|
|
|
38
|
|
|
|
|
20114
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub AUTOLOAD { |
26
|
|
|
|
|
|
|
|
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. |
30
|
0
|
|
|
0
|
|
|
our $AUTOLOAD; |
31
|
0
|
0
|
|
|
|
|
return if ( $AUTOLOAD =~ /\bDESTROY$/ ); |
32
|
0
|
|
|
|
|
|
my ( $pkg, $fname, $lno ) = caller(); |
33
|
0
|
|
|
|
|
|
my $my_package = __PACKAGE__; |
34
|
0
|
|
|
|
|
|
print STDERR <<EOM; |
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
|
|
|
|
|
|
|
====================================================================== |
42
|
|
|
|
|
|
|
EOM |
43
|
0
|
|
|
|
|
|
exit 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
0
|
|
|
sub DESTROY { |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# required to avoid call to AUTOLOAD in some versions of perl |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
54
|
0
|
|
|
|
|
|
return bless { |
55
|
|
|
|
|
|
|
_write_diagnostics_count => 0, |
56
|
|
|
|
|
|
|
_last_diagnostic_file => EMPTY_STRING, |
57
|
|
|
|
|
|
|
_input_file => EMPTY_STRING, |
58
|
|
|
|
|
|
|
_fh => undef, |
59
|
|
|
|
|
|
|
}, $class; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub set_input_file { |
63
|
0
|
|
|
0
|
0
|
|
my ( $self, $input_file ) = @_; |
64
|
0
|
|
|
|
|
|
$self->{_input_file} = $input_file; |
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub write_diagnostics { |
69
|
0
|
|
|
0
|
0
|
|
my ( $self, $msg, $line_number ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Write a message to the diagnostics file |
72
|
|
|
|
|
|
|
# Input parameters: |
73
|
|
|
|
|
|
|
# $msg = string describing the event |
74
|
|
|
|
|
|
|
# $line_number = optional line number |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
unless ( $self->{_write_diagnostics_count} ) { |
77
|
0
|
0
|
|
|
|
|
open( $self->{_fh}, ">", "DIAGNOSTICS" ) |
78
|
|
|
|
|
|
|
or Perl::Tidy::Die("couldn't open DIAGNOSTICS: $ERRNO\n"); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ( defined($line_number) ) { |
82
|
0
|
|
|
|
|
|
$msg = "$line_number:\t$msg"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $fh = $self->{_fh}; |
86
|
0
|
|
|
|
|
|
my $last_diagnostic_file = $self->{_last_diagnostic_file}; |
87
|
0
|
|
|
|
|
|
my $input_file = $self->{_input_file}; |
88
|
0
|
0
|
|
|
|
|
if ( $last_diagnostic_file ne $input_file ) { |
89
|
0
|
|
|
|
|
|
$fh->print("\nFILE:$input_file\n"); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
$self->{_last_diagnostic_file} = $input_file; |
92
|
0
|
|
|
|
|
|
$fh->print($msg); |
93
|
0
|
|
|
|
|
|
$self->{_write_diagnostics_count}++; |
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |