Tidy/Logger.pm

filter: Statementstmt 60.1% 154 / 256 Branchbran 39.2% 40 / 102 Conditioncond 33.3% 8 / 24 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 62.8% 22 / 35 Podpod 0.0% 0 / 23 totaltotal 50.0% 227 / 454 CC 61 SCAR 35.5
CC
61
Cov
53%
warning
161.5
finish
51.2
new
11.8
CRAP 34.7
« Tidy/Tokenizer.pm ↑ Summary Tidy/VerticalAligner.pm »
1 package Perl::Tidy::Logger;
2  
3 #####################################################################
4 #
5 # The Perl::Tidy::Logger class writes any .LOG and .ERR files
6 # and supplies some basic run information for error handling.
7 #
8 #####################################################################
9  
10 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 45 our $VERSION = '20260808';
13 45 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 45 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 45 ▶use constant EMPTY_STRING => q{};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 45 ▶use constant SPACE => q{ };
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub AUTOLOAD {
20  
21 # Catch any undefined sub calls so that we are sure to get
22 # some diagnostic information. This sub should never be called
23 # except for a programming error.
24 0 ▶ our $AUTOLOAD;
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
25 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::Logger::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
26 0 my ( $pkg, $fname, $lno ) = caller();
27 0 my $my_package = __PACKAGE__;
28 0 print {*STDERR} <<EOM;
29 ======================================================================
30 Error detected in package '$my_package', version $VERSION
31 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
32 Called from package: '$pkg'
33 Called from File '$fname' at line '$lno'
34 This error is probably due to a recent programming change
35 ======================================================================
36 EOM
37 0 exit 1;
38 } ## end sub AUTOLOAD
39  
40 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
41  
42 # required to avoid call to AUTOLOAD in some versions of perl
43 }
44  
45 45 ▶use constant DEFAULT_LOGFILE_GAP => 50;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 sub new {
48  
49 660 ▶ my ( $class, @arglist ) = @_;
Subroutine new: called CC=11 SCAR=24.7
Pod undocumented
50 660 ▶ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (@arglist % 2) 0 660 660
51  
52 660 my %defaults = (
53 rOpts => undef,
54 log_file => undef,
55 warning_file => undef,
56 fh_stderr => undef,
57 display_name => undef,
58 is_encoded_data => undef,
59 );
60  
61 660 my %args = ( %defaults, @arglist );
62  
63 660 my $rOpts = $args{rOpts};
64 660 my $log_file = $args{log_file};
65 660 my $warning_file = $args{warning_file};
66 660 my $fh_stderr = $args{fh_stderr};
67 660 my $display_name = $args{display_name};
68 660 my $is_encoded_data = $args{is_encoded_data};
69  
70 660 ▶ my $fh_warnings = $rOpts->{'standard-error-output'} ? $fh_stderr : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rOpts->{'standard-error-output'} ? : 3 657 660
71  
72 # remove any old error output file if we might write a new one
73 660 ▶ if ( !$fh_warnings && !ref($warning_file) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh_warnings or ref $warning_file) 16 644 660
Condition100%3/3
$fh_warnings or ref $warning_file
l!l&&r!l&&!r
364116
MC/DC100%2/2
$fh_warnings or ref $warning_file
$fh_warnings ref $warning_file
Truth table100%3/3
A or B
A= $fh_warningsB= ref $warning_file
ABresult
1X1
011
000
74 16 ▶ if ( -e $warning_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $warning_file) 0 16 16
75 0 ▶ unlink($warning_file)
Branch: 1 branch
BranchTrueFalseTotal
unlink $warning_file or Perl::Tidy::Die("couldn't unlink warning file ${warning_file}: $Perl::Tidy::Logger::OS_ERROR\n") 0 0 0
76 or Perl::Tidy::Die(
77 "couldn't unlink warning file $warning_file: $OS_ERROR\n");
78 }
79 }
80  
81 my $logfile_gap =
82 defined( $rOpts->{'logfile-gap'} )
83 660 ▶ ? $rOpts->{'logfile-gap'}
Branch: 1 branch
BranchTrueFalseTotal
defined $rOpts->{'logfile-gap'} ? : 1 659 660
84 : DEFAULT_LOGFILE_GAP;
85 660 ▶ if ( $logfile_gap == 0 ) { $logfile_gap = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($logfile_gap == 0) 1 659 660
86  
87 660 ▶ my $filename_stamp = $display_name ? $display_name . ':' : "??";
Branch: 1 branch
BranchTrueFalseTotal
$display_name ? : 660 0 660
88 660 ▶ my $input_stream_name = $display_name ? $display_name : "??";
Branch: 1 branch
BranchTrueFalseTotal
$display_name ? : 660 0 660
89 return bless {
90 _log_file => $log_file,
91 _logfile_gap => $logfile_gap,
92 _rOpts => $rOpts,
93 _fh_warnings => $fh_warnings,
94 _last_input_line_written => 0,
95 _last_input_line_number => undef,
96 _at_end_of_file => 0,
97 _use_prefix => 1,
98 _block_log_output => 0,
99 _line_of_tokens => undef,
100 _output_line_number => undef,
101 _wrote_line_information_string => 0,
102 _wrote_column_headings => 0,
103 _warning_file => $warning_file,
104 _warning_count => 0,
105 _complaint_count => 0,
106 _is_encoded_data => $is_encoded_data,
107 _saw_code_bug => -1, # -1=no 0=maybe 1=for sure
108 _saw_brace_error => 0,
109 _output_array => [],
110 _input_stream_name => $input_stream_name,
111 _filename_stamp => $filename_stamp,
112 660 _save_logfile => $rOpts->{'logfile'},
113 }, $class;
114 } ## end sub new
115  
116 sub get_input_stream_name {
117 0 ▶ my $self = shift;
Subroutine get_input_stream_name: not called CC=1 SCAR=6.9
Pod undocumented
118 0 return $self->{_input_stream_name};
119 }
120  
121 sub set_last_input_line_number {
122 660 ▶ my ( $self, $lno ) = @_;
Subroutine set_last_input_line_number: called CC=1 SCAR=0.0
Pod undocumented
123 660 $self->{_last_input_line_number} = $lno;
124 660 return;
125 }
126  
127 sub get_warning_count {
128 0 ▶ my $self = shift;
Subroutine get_warning_count: not called CC=1 SCAR=6.9
Pod undocumented
129 0 return $self->{_warning_count};
130 }
131  
132 sub get_use_prefix {
133 0 ▶ my $self = shift;
Subroutine get_use_prefix: not called CC=1 SCAR=6.9
Pod undocumented
134 0 return $self->{_use_prefix};
135 }
136  
137 sub block_log_output {
138 0 ▶ my $self = shift;
Subroutine block_log_output: not called CC=1 SCAR=6.9
Pod undocumented
139 0 $self->{_block_log_output} = 1;
140 0 return;
141 }
142  
143 sub unblock_log_output {
144 0 ▶ my $self = shift;
Subroutine unblock_log_output: not called CC=1 SCAR=6.9
Pod undocumented
145 0 $self->{_block_log_output} = 0;
146 0 return;
147 }
148  
149 sub interrupt_logfile {
150 0 ▶ my $self = shift;
Subroutine interrupt_logfile: not called CC=1 SCAR=6.9
Pod undocumented
151 0 $self->{_use_prefix} = 0;
152 0 $self->warning("\n");
153 0 $self->write_logfile_entry( '#' x 24 . " WARNING " . '#' x 25 . "\n" );
154 0 return;
155 } ## end sub interrupt_logfile
156  
157 sub resume_logfile {
158 0 ▶ my $self = shift;
Subroutine resume_logfile: not called CC=1 SCAR=6.9
Pod undocumented
159 0 $self->write_logfile_entry( '#' x 60 . "\n" );
160 0 $self->{_use_prefix} = 1;
161 0 return;
162 } ## end sub resume_logfile
163  
164 sub we_are_at_the_last_line {
165 659 ▶ my $self = shift;
Subroutine we_are_at_the_last_line: called CC=2 SCAR=7.4
Pod undocumented
166 659 ▶ if ( !$self->{_wrote_line_information_string} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_wrote_line_information_string"}) 0 659 659
167 0 $self->write_logfile_entry("Last line\n\n");
168 }
169 659 $self->{_at_end_of_file} = 1;
170 659 return;
171 } ## end sub we_are_at_the_last_line
172  
173 # record some stuff in case we go down in flames
174 45 ▶use constant MAX_PRINTED_CHARS => 35;
Subroutine BEGIN: called CC=1 SCAR=0.0
175  
176 sub black_box {
177 3 ▶ my ( $self, $line_of_tokens, $output_line_number ) = @_;
Subroutine black_box: called CC=5 SCAR=16.6
Pod undocumented
178  
179 # This routine saves information comparing the indentation of input
180 # and output lines when a detailed logfile is requested.
181 # This was very useful during the initial development of perltidy.
182  
183 3 my $input_line = $line_of_tokens->{_line_text};
184 3 my $input_line_number = $line_of_tokens->{_line_number};
185  
186 3 $self->{_line_of_tokens} = $line_of_tokens;
187 3 $self->{_output_line_number} = $output_line_number;
188 3 $self->{_wrote_line_information_string} = 0;
189  
190 3 my $last_input_line_written = $self->{_last_input_line_written};
191 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line_number - $last_input_line_written >= $self->{"_logfile_gap"} or $input_line =~ /^\s*(sub|package)\s+(\w+)/) 3 0 3
Condition33%1/3
$input_line_number - $last_input_line_written >= $self->{"_logfile_gap"} or $input_line =~ /^\s*(sub|package)\s+(\w+)/
l!l&&r!l&&!r
300
MC/DC0%0/2
$input_line_number - $last_input_line_written >= $self->{"_logfile_gap"} or $input_line =~ /^\s*(sub|package)\s+(\w+)/
$input_line_number - $last_input_line_written >= $self->{"_logfile_gap"} $input_line =~ /^\s*(sub|package)\s+(\w+)/
Truth table33%1/3
A or B
A= $input_line_number - $last_input_line_written >= $self->{"_logfile_gap"}B= $input_line =~ /^\s*(sub|package)\s+(\w+)/
ABresult
1X1
011
000
192 (
193 ( $input_line_number - $last_input_line_written ) >=
194 $self->{_logfile_gap}
195 )
196 || ( $input_line =~ /^\s*(sub|package)\s+(\w+)/ )
197 )
198 {
199 3 my $structural_indentation_level = $line_of_tokens->{_level_0};
200 3 ▶ $structural_indentation_level = 0
Branch: 1 branch
BranchTrueFalseTotal
if $structural_indentation_level < 0 0 3 3
201 if ( $structural_indentation_level < 0 );
202 3 $self->{_last_input_line_written} = $input_line_number;
203 3 ( my $out_str = $input_line ) =~ s/^\s+//;
204 3 chomp $out_str;
205  
206 3 $out_str = ( '.' x $structural_indentation_level ) . $out_str;
207  
208 3 ▶ if ( length($out_str) > MAX_PRINTED_CHARS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $out_str > 35) 0 3 3
209 0 $out_str = substr( $out_str, 0, MAX_PRINTED_CHARS ) . " ....";
210 }
211 3 $self->logfile_output( EMPTY_STRING, "$out_str\n" );
212 }
213 3 return;
214 } ## end sub black_box
215  
216 sub write_logfile_entry {
217  
218 8601 ▶ my ( $self, @msg ) = @_;
Subroutine write_logfile_entry: called CC=1 SCAR=0.0
Pod undocumented
219  
220 # add leading >>> to avoid confusing error messages and code
221 8601 $self->logfile_output( ">>>", "@msg" );
222 8601 return;
223 } ## end sub write_logfile_entry
224  
225 sub write_column_headings {
226 1 ▶ my $self = shift;
Subroutine write_column_headings: called CC=1 SCAR=0.0
Pod undocumented
227  
228 1 $self->{_wrote_column_headings} = 1;
229 1 my $routput_array = $self->{_output_array};
230 1 push @{$routput_array}, <<EOM;
231  
232 Starting formatting pass...
233 The nesting depths in the table below are at the start of the lines.
234 The indicated output line numbers are not always exact.
235 ci = levels of continuation indentation; bk = 1 if in BLOCK, 0 if not.
236  
237 in:out indent c b nesting code + messages; (messages begin with >>>)
238 lines levels i k (code begins with one '.' per indent level)
239 ------ ----- - - -------- -------------------------------------------
240 EOM
241 1 return;
242 } ## end sub write_column_headings
243  
244 sub make_line_information_string {
245  
246 # make columns of information when a logfile message needs to go out
247 5124 ▶ my $self = shift;
Subroutine make_line_information_string: called CC=10 SCAR=24.2
Pod undocumented
248 5124 my $line_of_tokens = $self->{_line_of_tokens};
249 5124 my $input_line_number = $line_of_tokens->{_line_number};
250 5124 my $line_information_string = EMPTY_STRING;
251 5124 ▶ if ($input_line_number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line_number) 3 5121 5124
252  
253 3 my $output_line_number = $self->{_output_line_number};
254 3 my $brace_depth = $line_of_tokens->{_curly_brace_depth};
255 3 my $paren_depth = $line_of_tokens->{_paren_depth};
256 3 my $square_bracket_depth = $line_of_tokens->{_square_bracket_depth};
257 my $guessed_indentation_level =
258 3 $line_of_tokens->{_guessed_indentation_level};
259  
260 3 my $structural_indentation_level = $line_of_tokens->{_level_0};
261  
262 $self->write_column_headings()
263 3 ▶ unless ( $self->{_wrote_column_headings} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wrote_column_headings"} 1 2 3
264  
265 # keep logfile columns aligned for scripts up to 999 lines;
266 # for longer scripts it doesn't really matter
267 3 my $extra_space = EMPTY_STRING;
268 3 ▶ $extra_space .=
Branch: 2 branches
BranchTrueFalseTotal
$input_line_number < 10 ? : 3 0 3
$input_line_number < 100 ? : 0 0 0
269 ( $input_line_number < 10 ) ? SPACE x 2
270 : ( $input_line_number < 100 ) ? SPACE
271 : EMPTY_STRING;
272 3 ▶ $extra_space .=
Branch: 2 branches
BranchTrueFalseTotal
$output_line_number < 10 ? : 3 0 3
$output_line_number < 100 ? : 0 0 0
273 ( $output_line_number < 10 ) ? SPACE x 2
274 : ( $output_line_number < 100 ) ? SPACE
275 : EMPTY_STRING;
276  
277 # there are 2 possible nesting strings:
278 # the original which looks like this: (0 [1 {2
279 # the new one, which looks like this: {{[
280 # the new one is easier to read, and shows the order, but
281 # could be arbitrarily long, so we use it unless it is too long
282 3 my $nesting_string =
283 "($paren_depth [$square_bracket_depth {$brace_depth";
284 3 my $nesting_string_new = $line_of_tokens->{_nesting_tokens_0};
285 3 my $ci_level = $line_of_tokens->{_ci_level_0};
286 3 ▶ if ( $ci_level > 9 ) { $ci_level = '*' }
Branch: 1 branch
BranchTrueFalseTotal
if ($ci_level > 9) 0 3 3
287 3 ▶ my $bk = ( $line_of_tokens->{_nesting_blocks_0} =~ /1$/ ) ? '1' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$line_of_tokens->{'_nesting_blocks_0'} =~ /1$/ ? : 3 0 3
288  
289 3 ▶ if ( length($nesting_string_new) <= 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $nesting_string_new <= 8) 3 0 3
290 3 $nesting_string =
291 $nesting_string_new . SPACE x ( 8 - length($nesting_string_new) );
292 }
293 $line_information_string =
294 3 "L$input_line_number:$output_line_number$extra_space i$guessed_indentation_level:$structural_indentation_level $ci_level $bk $nesting_string";
295 }
296 5124 return $line_information_string;
297 } ## end sub make_line_information_string
298  
299 sub logfile_output {
300  
301 8604 ▶ my ( $self, $prompt, $msg ) = @_;
Subroutine logfile_output: called CC=5 SCAR=16.1
Pod undocumented
302  
303 # Write a message to the log file
304  
305 8604 ▶ return if ( $self->{_block_log_output} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_block_log_output"} 0 8604 8604
306  
307 8604 my $routput_array = $self->{_output_array};
308 8604 ▶ if ( $self->{_at_end_of_file} || !$self->{_use_prefix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_at_end_of_file'} or not $self->{'_use_prefix'}) { } 3480 5124 8604
Condition66%2/3
$self->{"_at_end_of_file"} or not $self->{"_use_prefix"}
l!l&&r!l&&!r
348005124
MC/DC50%1/2
$self->{"_at_end_of_file"} or not $self->{"_use_prefix"}
$self->{"_at_end_of_file"} not $self->{"_use_prefix"}
Truth table66%2/3
A or not(B)
A= $self->{"_at_end_of_file"}B= not $self->{"_use_prefix"}
ABresult
1X1
011
000
309 3480 push @{$routput_array}, "$msg";
310 }
311 else {
312 5124 my $line_information_string = $self->make_line_information_string();
313 5124 $self->{_wrote_line_information_string} = 1;
314  
315 5124 ▶ if ($line_information_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_information_string) { } 3 5121 5124
316 3 push @{$routput_array}, "$line_information_string $prompt$msg";
317 }
318 else {
319 5121 push @{$routput_array}, "$msg";
320 }
321 }
322 8604 return;
323 } ## end sub logfile_output
324  
325 sub get_saw_brace_error {
326 659 ▶ my $self = shift;
Subroutine get_saw_brace_error: called CC=1 SCAR=0.0
Pod undocumented
327 659 return $self->{_saw_brace_error};
328 }
329  
330 sub increment_brace_error {
331 0 ▶ my $self = shift;
Subroutine increment_brace_error: not called CC=1 SCAR=6.9
Pod undocumented
332 0 $self->{_saw_brace_error}++;
333 0 return;
334 }
335  
336 sub brace_warning {
337 0 ▶ my ( $self, $msg, $msg_line_number ) = @_;
Subroutine brace_warning: not called CC=3 SCAR=20.6
Pod undocumented
338  
339 45 ▶ use constant BRACE_WARNING_LIMIT => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
340 0 my $saw_brace_error = $self->{_saw_brace_error};
341  
342 0 ▶ if ( $saw_brace_error < BRACE_WARNING_LIMIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_brace_error < 10) 0 0 0
343 0 $self->warning( $msg, $msg_line_number );
344 }
345 0 $saw_brace_error++;
346 0 $self->{_saw_brace_error} = $saw_brace_error;
347  
348 0 ▶ if ( $saw_brace_error == BRACE_WARNING_LIMIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_brace_error == 10) 0 0 0
349 0 $self->warning("No further warnings of this type will be given\n");
350 }
351 0 return;
352 } ## end sub brace_warning
353  
354 sub complain {
355  
356 # handle non-critical warning messages based on input flag
357 46 ▶ my ( $self, $msg, $msg_line_number ) = @_;
Subroutine complain: called CC=3 SCAR=11.3
Pod undocumented
358 46 my $rOpts = $self->{_rOpts};
359  
360 # these appear in .ERR output only if -w flag is used
361 46 ▶ if ( $rOpts->{'warning-output'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts->{'warning-output'}) { } 0 46 46
362 0 $self->warning( $msg, $msg_line_number );
363 }
364  
365 # otherwise, they go to the .LOG file
366 else {
367 46 $self->{_complaint_count}++;
368 46 ▶ if ($msg_line_number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_line_number) 46 0 46
369  
370 # NOTE: consider using same prefix as warning()
371 46 $msg = $msg_line_number . ':' . $msg;
372 }
373 46 $self->write_logfile_entry($msg);
374 }
375 46 return;
376 } ## end sub complain
377  
378 sub warning {
379  
380 0 ▶ my ( $self, $msg, ($msg_line_number) ) = @_;
Subroutine warning: not called CC=13 SCAR=50.8
Pod undocumented
381  
382 # Report errors to .ERR file (or stdout)
383 # Given:
384 # $msg = a string with the warning message
385 # $msg_line_number = optional line number prefix
386  
387 45 ▶ use constant WARNING_LIMIT => 50;
Subroutine BEGIN: called CC=1 SCAR=0.0
388  
389 # Always bump the warn count, even if no message goes out
390 0 Perl::Tidy::Warn_count_bump();
391  
392 0 my $rOpts = $self->{_rOpts};
393 0 ▶ if ( !$rOpts->{'quiet'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rOpts->{"quiet"}) 0 0 0
394  
395 0 my $warning_count = $self->{_warning_count};
396 0 my $fh_warnings = $self->{_fh_warnings};
397 0 my $is_encoded_data = $self->{_is_encoded_data};
398 0 ▶ if ( !$fh_warnings ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh_warnings) 0 0 0
399 0 my $warning_file = $self->{_warning_file};
400 0 $fh_warnings =
401 Perl::Tidy::streamhandle( $warning_file, 'w', $is_encoded_data );
402 0 ▶ if ( !$fh_warnings ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh_warnings) 0 0 0
403 0 Perl::Tidy::Die("couldn't open warning file '$warning_file'\n");
404 }
405 0 Perl::Tidy::nag_flush($fh_warnings);
406 0 ▶ Perl::Tidy::Warn_msg("## Please see file $warning_file\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $warning_file 0 0 0
407 unless ( ref($warning_file) );
408 0 $self->{_fh_warnings} = $fh_warnings;
409 0 $fh_warnings->print("Perltidy version is $Perl::Tidy::VERSION\n");
410 }
411  
412 0 my $filename_stamp = $self->{_filename_stamp};
413  
414 0 ▶ if ( $warning_count < WARNING_LIMIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warning_count < 50) 0 0 0
415  
416 0 ▶ if ( !$warning_count ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warning_count) 0 0 0
417  
418 # On first error always write a line with the filename. Note
419 # that the filename will be 'perltidy' if input is from stdin
420 # or from a data structure.
421 0 ▶ if ($filename_stamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename_stamp) 0 0 0
422 0 $fh_warnings->print(
423 "\n$filename_stamp Begin Error Output Stream\n");
424 }
425  
426 # Turn off filename stamping unless error output is directed
427 # to the standard error output (with -se flag)
428 0 ▶ if ( !$rOpts->{'standard-error-output'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rOpts->{"standard-error-output"}) 0 0 0
429 0 $filename_stamp = EMPTY_STRING;
430 0 $self->{_filename_stamp} = $filename_stamp;
431 }
432 }
433  
434 0 ▶ if ( $self->get_use_prefix() > 0 && defined($msg_line_number) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_use_prefix > 0 and defined $msg_line_number) { } 0 0 0
Condition0%0/3
$self->get_use_prefix > 0 and defined $msg_line_number
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_use_prefix > 0 and defined $msg_line_number
$self->get_use_prefix > 0 defined $msg_line_number
Truth table0%0/3
A and B
A= $self->get_use_prefix > 0B= defined $msg_line_number
ABresult
0X0
100
111
435 0 $self->write_logfile_entry("WARNING: $msg");
436  
437 # add prefix 'filename:line_no: ' to message lines
438 0 my $pre_string = $filename_stamp . $msg_line_number . ': ';
439 0 chomp $msg;
440 0 $msg =~ s/\n/\n$pre_string/g;
441 0 $msg = $pre_string . $msg . "\n";
442  
443 0 $fh_warnings->print($msg);
444  
445 }
446 else {
447 0 $self->write_logfile_entry($msg);
448  
449 # add prefix 'filename: ' to message lines
450 0 ▶ if ($filename_stamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename_stamp) 0 0 0
451 0 my $pre_string = $filename_stamp . SPACE;
452 0 chomp $msg;
453 0 $msg =~ s/\n/\n$pre_string/g;
454 0 $msg = $pre_string . $msg . "\n";
455 }
456  
457 0 $fh_warnings->print($msg);
458 }
459 }
460 0 $warning_count++;
461 0 $self->{_warning_count} = $warning_count;
462  
463 0 ▶ if ( $warning_count == WARNING_LIMIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warning_count == 50) 0 0 0
464 0 $fh_warnings->print(
465 $filename_stamp . "No further warnings will be given\n" );
466 }
467 }
468 0 return;
469 } ## end sub warning
470  
471 sub report_definite_bug {
472 0 ▶ my $self = shift;
Subroutine report_definite_bug: not called CC=1 SCAR=6.9
Pod undocumented
473 0 $self->{_saw_code_bug} = 1;
474 0 return;
475 }
476  
477 sub get_save_logfile {
478 1978 ▶ my $self = shift;
Subroutine get_save_logfile: called CC=1 SCAR=0.0
Pod undocumented
479 1978 return $self->{_save_logfile};
480 }
481  
482 sub finish {
483  
484 # called after all formatting to summarize errors
485 660 ▶ my ($self) = @_;
Subroutine finish: called CC=16 SCAR=39.4
Pod undocumented
486  
487 660 my $warning_count = $self->{_warning_count};
488 660 my $save_logfile = $self->{_save_logfile};
489 660 my $log_file = $self->{_log_file};
490 660 my $msg_line_number = $self->{_last_input_line_number};
491  
492 660 my $logfile_display_name = EMPTY_STRING;
493 660 ▶ if ($save_logfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save_logfile) 1 659 660
494 1 my $ref = ref($log_file);
495 1 ▶ $logfile_display_name = $ref ? "(ref to $ref)" : $log_file;
Branch: 1 branch
BranchTrueFalseTotal
$ref ? : 1 0 1
496 }
497  
498 660 ▶ if ($warning_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warning_count) 0 660 660
499 0 ▶ if ($save_logfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save_logfile) 0 0 0
500 0 $self->block_log_output(); # avoid echoing this to the logfile
501 0 $self->warning(
502 "The logfile '$logfile_display_name' may contain useful information\n",
503 $msg_line_number
504 );
505 0 $self->unblock_log_output();
506 }
507  
508 0 ▶ if ( $self->{_complaint_count} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_complaint_count"} > 0) 0 0 0
509 0 $self->warning(
510 "To see $self->{_complaint_count} non-critical warnings rerun with -w\n",
511 $msg_line_number
512 );
513 }
514  
515 0 ▶ if ( $self->{_saw_brace_error}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_saw_brace_error"} and $self->{"_logfile_gap"} > 1 || !$save_logfile) 0 0 0
Condition0%0/6
$self->{"_saw_brace_error"} and $self->{"_logfile_gap"} > 1 || !$save_logfile
!ll&&!rl&&r
000
$self->{"_logfile_gap"} > 1 or not $save_logfile
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"_saw_brace_error"} and $self->{"_logfile_gap"} > 1 || !$save_logfile
$self->{"_saw_brace_error"} $self->{"_logfile_gap"} > 1 not $save_logfile
Truth table0%0/4
A and B or not(C)
A= $self->{"_saw_brace_error"}B= $self->{"_logfile_gap"} > 1C= not $save_logfile
ABCresult
0XX0
1000
11X1
1011
516 && ( $self->{_logfile_gap} > 1 || !$save_logfile ) )
517 {
518 0 $self->warning( "To save a full .LOG file rerun with -g\n",
519 $msg_line_number );
520 }
521 }
522  
523 660 ▶ if ($save_logfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save_logfile) 1 659 660
524 1 my $is_encoded_data = $self->{_is_encoded_data};
525 1 my $fh = Perl::Tidy::streamhandle( $log_file, 'w', $is_encoded_data );
526 1 ▶ if ( !$fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fh) { } 0 1 1
527 0 Perl::Tidy::Warn(
528 "unable to open log file '$logfile_display_name'\n");
529 }
530 else {
531 1 my $routput_array = $self->{_output_array};
532 1 foreach my $line ( @{$routput_array} ) { $fh->print($line) }
533 1 ▶ if ( $fh->can('close')
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->can("close") and not ref $log_file and $log_file ne "-") 0 1 1
Condition33%2/6
$fh->can("close") and not ref $log_file and $log_file ne "-"
!ll&&!rl&&r
100
$fh->can("close") and not ref $log_file
!ll&&!rl&&r
100
MC/DC0%0/3
$fh->can("close") and not ref $log_file and $log_file ne "-"
$fh->can("close") not ref $log_file $log_file ne "-"
Truth table25%1/4
A and not(B) and C
A= $fh->can("close")B= not ref $log_fileC= $log_file ne "-"
ABCresult
0XX0
10X0
1100
1111
534 && !ref($log_file)
535 && $log_file ne '-' )
536 {
537 0 ▶ $fh->close()
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or Perl::Tidy::Warn("Error closing LOG file '${logfile_display_name}': $Perl::Tidy::Logger::OS_ERROR\n") 0 0 0
538 or Perl::Tidy::Warn(
539 "Error closing LOG file '$logfile_display_name': $OS_ERROR\n"
540 );
541 }
542 }
543 }
544 660 return;
545 } ## end sub finish
546 45 1;
« Tidy/Tokenizer.pm ↑ Summary Tidy/VerticalAligner.pm »