Tidy/Diagnostics.pm

filter: Statementstmt 35.0% 14 / 40 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 3 totaltotal 29.0% 18 / 62 CC 6 SCAR 25.0
CC
6
Cov
28%
write_diagnostics
30.0
AUTOLOAD
6.0
new
2.0
CRAP 12.2
« Tidy/VerticalAligner.pm ↑ Summary Tidy/IOScalarArray.pm »
1 package Perl::Tidy::Diagnostics;
2  
3 #####################################################################
4 #
5 # The Perl::Tidy::Diagnostics class writes the DIAGNOSTICS file, which is
6 # useful for program development.
7 #
8 # Only one such file is created regardless of the number of input
9 # files processed. This allows the results of processing many files
10 # to be summarized in a single file.
11  
12 # Output messages go to a file named DIAGNOSTICS, where
13 # they are labeled by file and line. This allows many files to be
14 # scanned at once for some particular condition of interest. It was
15 # particularly useful for developing guessing strategies.
16 #
17 #####################################################################
18  
19 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 45 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 45 our $VERSION = '20260826';
23  
24 45 ▶use constant EMPTY_STRING => q{};
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
27  
28 # Catch any undefined sub calls so that we are sure to get
29 # some diagnostic information. This sub should never be called
30 # except for a programming error.
31 0 our $AUTOLOAD;
32 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::Diagnostics::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
33 0 my ( $pkg, $fname, $lno ) = caller();
34 0 my $my_package = __PACKAGE__;
35 0 print {*STDERR} <<EOM;
36 ======================================================================
37 Error detected in package '$my_package', version $VERSION
38 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
39 Called from package: '$pkg'
40 Called from File '$fname' at line '$lno'
41 This error is probably due to a recent programming change
42 ======================================================================
43 EOM
44 0 exit 1;
45 } ## end sub AUTOLOAD
46  
47 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
48  
49 # required to avoid call to AUTOLOAD in some versions of perl
50 }
51  
52 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
53  
54 0 my $class = shift;
55 0 return bless {
56 _write_diagnostics_count => 0,
57 _last_diagnostic_file => EMPTY_STRING,
58 _input_file => EMPTY_STRING,
59 _fh => undef,
60 }, $class;
61 } ## end sub new
62  
63 0 ▶sub set_input_file {
Subroutine set_input_file: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my ( $self, $input_file ) = @_;
65 0 $self->{_input_file} = $input_file;
66 0 return;
67 }
68  
69 0 ▶sub write_diagnostics {
Subroutine write_diagnostics: not called CC=5 SCAR=34.0
Pod undocumented
70 0 my ( $self, $msg, $line_number ) = @_;
71  
72 # Write a message to the diagnostics file
73 # Input parameters:
74 # $msg = string describing the event
75 # $line_number = optional line number
76  
77 0 ▶ if ( !$self->{_write_diagnostics_count} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_write_diagnostics_count"}) 0 0 0
78 0 ▶ open( $self->{_fh}, ">", "DIAGNOSTICS" )
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"_fh"}, ">", "DIAGNOSTICS" or Perl::Tidy::Die("couldn't open DIAGNOSTICS: $Perl::Tidy::Diagnostics::OS_ERROR\n") 0 0 0
79 or Perl::Tidy::Die("couldn't open DIAGNOSTICS: $OS_ERROR\n");
80 }
81  
82 0 ▶ if ( defined($line_number) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line_number) 0 0 0
83 0 $msg = "$line_number:\t$msg";
84 }
85  
86 0 my $fh = $self->{_fh};
87 0 my $last_diagnostic_file = $self->{_last_diagnostic_file};
88 0 my $input_file = $self->{_input_file};
89 0 ▶ if ( $last_diagnostic_file ne $input_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_diagnostic_file ne $input_file) 0 0 0
90 0 $fh->print("\nFILE:$input_file\n");
91 }
92 0 $self->{_last_diagnostic_file} = $input_file;
93 0 $fh->print($msg);
94 0 $self->{_write_diagnostics_count}++;
95 0 return;
96 } ## end sub write_diagnostics
97  
98 45 1;
« Tidy/VerticalAligner.pm ↑ Summary Tidy/IOScalarArray.pm »