Tidy/FileWriter.pm

filter: Statementstmt 69.4% 152 / 219 Branchbran 50.0% 31 / 62 Conditioncond 66.6% 16 / 24 MC/DCmcdc 46.6% 7 / 15 Subroutinesub 80.0% 24 / 30 Podpod 0.0% 0 / 19 totaltotal 62.3% 230 / 369 CC 41 SCAR 21.2
CC
41
Cov
65%
check_line_lengths
26.1
write_code_line
14.2
report_line_length_errors
12.4
CRAP 8.3
« Tidy/IOScalar.pm ↑ Summary Tidy/Debugger.pm »
1 package Perl::Tidy::FileWriter;
2  
3 #####################################################################
4 #
5 # The Perl::Tidy::FileWriter class writes the output file created
6 # by the formatter. It receives each output line and performs some
7 # important monitoring services. These include:
8 #
9 # - Verifying that lines do not go out with tokens in the wrong order
10 # - Checking for obvious iteration convergence when all output tokens
11 # match all input tokens
12 # - Keeping track of consecutive blank and non-blank lines
13 # - Looking for line lengths which exceed the maximum requested length
14 # - Reporting results to the log file
15 #
16 #####################################################################
17  
18 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 45 our $VERSION = '20260808';
21 45 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 45 ▶use constant DEVEL_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 45 ▶use constant EMPTY_STRING => q{};
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # Maximum number of little messages; probably need not be changed.
27 45 ▶use constant MAX_NAG_MESSAGES => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # List of hash keys to prevent -duk from listing them.
30 45 my @unique_hash_keys_uu = qw( indent-columns );
31  
32 sub AUTOLOAD {
33  
34 # Catch any undefined sub calls so that we are sure to get
35 # some diagnostic information. This sub should never be called
36 # except for a programming error.
37 0 ▶ our $AUTOLOAD;
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
38 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::FileWriter::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
39 0 my ( $pkg, $fname, $lno ) = caller();
40 0 my $my_package = __PACKAGE__;
41 0 print {*STDERR} <<EOM;
42 ======================================================================
43 Error detected in package '$my_package', version $VERSION
44 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
45 Called from package: '$pkg'
46 Called from File '$fname' at line '$lno'
47 This error is probably due to a recent programming change
48 ======================================================================
49 EOM
50 0 exit 1;
51 } ## end sub AUTOLOAD
52  
53 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
54  
55 # required to avoid call to AUTOLOAD in some versions of perl
56 }
57  
58 BEGIN {
59  
60 # Array index names for variables.
61 # Do not combine with other BEGIN blocks (c101).
62 45 ▶ my $i = 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 use constant {
64 45 _logger_object_ => $i++,
65 _rOpts_ => $i++,
66 _output_line_number_ => $i++,
67 _consecutive_blank_lines_ => $i++,
68 _consecutive_nonblank_lines_ => $i++,
69 _consecutive_new_blank_lines_ => $i++,
70 _first_line_length_error_ => $i++,
71 _max_line_length_error_ => $i++,
72 _last_line_length_error_ => $i++,
73 _first_line_length_error_at_ => $i++,
74 _max_line_length_error_at_ => $i++,
75 _last_line_length_error_at_ => $i++,
76 _line_length_error_count_ => $i++,
77 _max_output_line_length_ => $i++,
78 _max_output_line_length_at_ => $i++,
79 _rK_checklist_ => $i++,
80 _K_arrival_order_matches_ => $i++,
81 _K_sequence_error_msg_ => $i++,
82 _K_last_arrival_ => $i++,
83 _save_logfile_ => $i++,
84 _routput_string_ => $i++,
85 45 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
86 } ## end BEGIN
87  
88 sub Die {
89 0 ▶ my ($msg) = @_;
Subroutine Die: not called CC=1 SCAR=6.9
Pod undocumented
90 0 Perl::Tidy::Die($msg);
91 0 croak "unexpected return from Perl::Tidy::Die";
92 }
93  
94 sub Fault {
95 0 ▶ my ($msg) = @_;
Subroutine Fault: not called CC=1 SCAR=6.9
Pod undocumented
96  
97 # This routine is called for errors that really should not occur
98 # except if there has been a bug introduced by a recent program change.
99 # Please add comments at calls to Fault to explain why the call
100 # should not occur, and where to look to fix it.
101 0 my ( $package0_uu, $filename0_uu, $line0, $subroutine0_uu ) = caller(0);
102 0 my ( $package1_uu, $filename1, $line1, $subroutine1 ) = caller(1);
103 0 my ( $package2_uu, $filename2_uu, $line2_uu, $subroutine2 ) = caller(2);
104 0 my $pkg = __PACKAGE__;
105 0 my $input_stream_name = Perl::Tidy::get_input_stream_name();
106  
107 0 Die(<<EOM);
108 ==============================================================================
109 While operating on input stream with name: '$input_stream_name'
110 A fault was detected at line $line0 of sub '$subroutine1'
111 in file '$filename1'
112 which was called from line $line1 of sub '$subroutine2'
113 Message: '$msg'
114 This is probably an error introduced by a recent programming change.
115 $pkg reports VERSION='$VERSION'.
116 ==============================================================================
117 EOM
118  
119 0 croak "unexpected return from sub Die";
120 } ## end sub Fault
121  
122 sub warning {
123 0 ▶ my ( $self, $msg ) = @_;
Subroutine warning: not called CC=2 SCAR=17.9
Pod undocumented
124  
125 # log a warning message from any caller
126 0 my $logger_object = $self->[_logger_object_];
127 0 ▶ if ($logger_object) { $logger_object->warning($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
128 0 return;
129 } ## end sub warning
130  
131 sub write_logfile_entry {
132 1322 ▶ my ( $self, $msg ) = @_;
Subroutine write_logfile_entry: called CC=2 SCAR=6.9
Pod undocumented
133 1322 my $logger_object = $self->[_logger_object_];
134 1322 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 1318 4 1322
135 1318 $logger_object->write_logfile_entry($msg);
136 }
137 1322 return;
138 } ## end sub write_logfile_entry
139  
140 sub new {
141 661 ▶ my ( $class, $line_sink_object, $rOpts, $logger_object ) = @_;
Subroutine new: called CC=5 SCAR=16.6
Pod undocumented
142  
143 661 my $self = [];
144 661 bless $self, $class;
145 661 $self->[_logger_object_] = $logger_object;
146 661 $self->[_rOpts_] = $rOpts;
147 661 $self->[_output_line_number_] = 1;
148 661 $self->[_consecutive_blank_lines_] = 0;
149 661 $self->[_consecutive_nonblank_lines_] = 0;
150 661 $self->[_consecutive_new_blank_lines_] = 0;
151 661 $self->[_first_line_length_error_] = 0;
152 661 $self->[_max_line_length_error_] = 0;
153 661 $self->[_last_line_length_error_] = 0;
154 661 $self->[_first_line_length_error_at_] = 0;
155 661 $self->[_max_line_length_error_at_] = 0;
156 661 $self->[_last_line_length_error_at_] = 0;
157 661 $self->[_line_length_error_count_] = 0;
158 661 $self->[_max_output_line_length_] = 0;
159 661 $self->[_max_output_line_length_at_] = 0;
160 661 $self->[_rK_checklist_] = [];
161 661 $self->[_K_arrival_order_matches_] = 0;
162 661 $self->[_K_sequence_error_msg_] = EMPTY_STRING;
163 661 $self->[_K_last_arrival_] = -1;
164 661 ▶ $self->[_save_logfile_] =
Condition100%3/3
defined $logger_object && $logger_object->get_save_logfile
!ll&&!rl&&r
26581
MC/DC100%2/2
defined $logger_object && $logger_object->get_save_logfile
defined $logger_object $logger_object->get_save_logfile
Truth table100%3/3
A && B
A= defined $logger_objectB= $logger_object->get_save_logfile
ABresult
0X0
100
111
165 defined($logger_object) && $logger_object->get_save_logfile();
166  
167 # '$line_sink_object' is a SCALAR ref which receives the lines.
168 661 my $ref = ref($line_sink_object);
169 661 ▶ if ( !$ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref) { } 0 661 661
elsif ($ref eq 'SCALAR') { } 661 0 661
170 0 Fault("FileWriter expects line_sink_object to be a ref\n");
171 }
172 elsif ( $ref eq 'SCALAR' ) {
173 661 $self->[_routput_string_] = $line_sink_object;
174 }
175 else {
176 0 my $str = $ref;
177 0 ▶ if ( length($str) > 63 ) { $str = substr( $str, 0, 60 ) . '...' }
Branch: 1 branch
BranchTrueFalseTotal
if (length $str > 63) 0 0 0
178 0 Fault(<<EOM);
179 FileWriter expects 'line_sink_object' to be ref to SCALAR but it is ref to:
180 $str
181 EOM
182 }
183  
184 661 return $self;
185 } ## end sub new
186  
187 sub setup_convergence_test {
188 658 ▶ my ( $self, $rlist ) = @_;
Subroutine setup_convergence_test: called CC=3 SCAR=11.0
Pod undocumented
189  
190 # Setup the convergence test,
191  
192 # Given:
193 # $rlist = a reference to a list of line-ending token indexes 'K' of
194 # the input stream. We will compare these with the line-ending token
195 # indexes of the output stream. If they are identical, then we have
196 # convergence.
197 658 ▶ if ( @{$rlist} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rlist;}) 647 11 658
198  
199 # We are going to destroy the list, so make a copy and put in
200 # reverse order so we can pop values as they arrive
201 647 my @list = @{$rlist};
202 647 ▶ if ( $list[0] < $list[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list[0] < $list[-1]) 570 77 647
203 570 @list = reverse(@list);
204 }
205 647 $self->[_rK_checklist_] = \@list;
206 }
207  
208 # We will zero this flag on any error in arrival order:
209 658 $self->[_K_arrival_order_matches_] = 1;
210 658 $self->[_K_sequence_error_msg_] = EMPTY_STRING;
211 658 $self->[_K_last_arrival_] = -1;
212 658 return;
213 } ## end sub setup_convergence_test
214  
215 sub get_convergence_check {
216 661 ▶ my ($self) = @_;
Subroutine get_convergence_check: called CC=2 SCAR=6.9
Pod undocumented
217  
218 # converged if:
219 # - all expected indexes arrived
220 # - and in correct order
221 661 ▶ return !@{ $self->[_rK_checklist_] }
Condition100%3/3
!@{$self->[15];} && $self->[16]
!ll&&!rl&&r
24455362
MC/DC100%2/2
!@{$self->[15];} && $self->[16]
!@{$self->[15];} $self->[16]
Truth table100%3/3
not(A) && B
A= !@{$self->[15];}B= $self->[16]
ABresult
0X0
100
111
222 && $self->[_K_arrival_order_matches_];
223  
224 } ## end sub get_convergence_check
225  
226 sub get_output_line_number {
227 562 ▶ my $self = shift;
Subroutine get_output_line_number: called CC=1 SCAR=0.0
Pod undocumented
228 562 return $self->[_output_line_number_];
229 }
230  
231 sub decrement_output_line_number {
232 661 ▶ my $self = shift;
Subroutine decrement_output_line_number: called CC=1 SCAR=0.0
Pod undocumented
233 661 $self->[_output_line_number_]--;
234 661 return;
235 }
236  
237 sub get_consecutive_nonblank_lines {
238 1 ▶ my $self = shift;
Subroutine get_consecutive_nonblank_lines: called CC=1 SCAR=0.0
Pod undocumented
239 1 return $self->[_consecutive_nonblank_lines_];
240 }
241  
242 sub get_consecutive_blank_lines {
243 0 ▶ my $self = shift;
Subroutine get_consecutive_blank_lines: not called CC=1 SCAR=6.9
Pod undocumented
244 0 return $self->[_consecutive_blank_lines_];
245 }
246  
247 sub reset_consecutive_blank_lines {
248 175 ▶ my $self = shift;
Subroutine reset_consecutive_blank_lines: called CC=1 SCAR=0.0
Pod undocumented
249 175 $self->[_consecutive_blank_lines_] = 0;
250 175 return;
251 }
252  
253 sub want_blank_line {
254 22 ▶ my $self = shift;
Subroutine want_blank_line: called CC=2 SCAR=6.9
Pod undocumented
255 22 ▶ if ( !$self->[_consecutive_blank_lines_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[3]) 13 9 22
256 13 $self->write_blank_code_line();
257 }
258 22 return;
259 } ## end sub want_blank_line
260  
261 sub require_blank_code_lines {
262 51 ▶ my ( $self, $count ) = @_;
Subroutine require_blank_code_lines: called CC=2 SCAR=6.9
Pod undocumented
263  
264 # Given:
265 # $count = number of blank lines to write
266 # Write out $count blank lines regardless of the value of -mbl
267 # unless -mbl=0. This allows extra blank lines to be written for subs and
268 # packages even with the default -mbl=1
269 51 my $need = $count - $self->[_consecutive_blank_lines_];
270 51 my $rOpts = $self->[_rOpts_];
271 51 my $forced = $rOpts->{'maximum-consecutive-blank-lines'} > 0;
272 51 foreach ( 0 .. $need - 1 ) {
273 32 $self->write_blank_code_line($forced);
274 }
275 51 return;
276 } ## end sub require_blank_code_lines
277  
278 sub write_blank_code_line {
279 1117 ▶ my ( $self, ($forced) ) = @_;
Subroutine write_blank_code_line: called CC=6 SCAR=18.2
Pod undocumented
280  
281 # Write a blank line of code, given:
282 # $forced = optional flag which, if set, forces the blank line
283 # to be written. This allows the -mbl flag to be temporarily
284 # exceeded.
285  
286 1117 my $rOpts = $self->[_rOpts_];
287 return
288 if (!$forced
289 && $self->[_consecutive_blank_lines_] >=
290 1117 ▶ $rOpts->{'maximum-consecutive-blank-lines'} );
Branch: 1 branch
BranchTrueFalseTotal
if not $forced and $self->[3] >= $rOpts->{"maximum-consecutive-blank-lines"} 114 1003 1117
Condition100%3/3
not $forced and $self->[3] >= $rOpts->{"maximum-consecutive-blank-lines"}
!ll&&!rl&&r
56947114
MC/DC100%2/2
not $forced and $self->[3] >= $rOpts->{"maximum-consecutive-blank-lines"}
not $forced $self->[3] >= $rOpts->{"maximum-consecutive-blank-lines"}
Truth table100%3/3
not(A) and B
A= not $forcedB= $self->[3] >= $rOpts->{"maximum-consecutive-blank-lines"}
ABresult
0X0
100
111
291  
292 1003 $self->[_consecutive_nonblank_lines_] = 0;
293  
294 # Balance old blanks against new (forced) blanks instead of writing them.
295 # This fixes case b1073.
296 1003 ▶ if ( !$forced && $self->[_consecutive_new_blank_lines_] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $forced and $self->[5] > 0) 0 1003 1003
Condition66%2/3
not $forced and $self->[5] > 0
!ll&&!rl&&r
569470
MC/DC0%0/2
not $forced and $self->[5] > 0
not $forced $self->[5] > 0
Truth table66%2/3
not(A) and B
A= not $forcedB= $self->[5] > 0
ABresult
0X0
100
111
297 0 $self->[_consecutive_new_blank_lines_]--;
298 0 return;
299 }
300  
301 1003 ${ $self->[_routput_string_] } .= "\n";
302  
303 1003 $self->[_output_line_number_]++;
304 1003 $self->[_consecutive_blank_lines_]++;
305 1003 ▶ $self->[_consecutive_new_blank_lines_]++ if ($forced);
Branch: 1 branch
BranchTrueFalseTotal
if $forced 56 947 1003
306  
307 1003 return;
308 } ## end sub write_blank_code_line
309  
310 45 ▶use constant MAX_PRINTED_CHARS => 80;
Subroutine BEGIN: called CC=1 SCAR=0.0
311  
312 sub write_code_line {
313 8543 ▶ my ( $self, $str, $K ) = @_;
Subroutine write_code_line: called CC=10 SCAR=26.5
Pod undocumented
314  
315 # Write a line of code, given
316 # $str = the line of code
317 # $K = an optional check integer which, if given, must
318 # increase monotonically. This was added to catch cache
319 # sequence errors in the vertical aligner.
320  
321 8543 $self->[_consecutive_blank_lines_] = 0;
322 8543 $self->[_consecutive_new_blank_lines_] = 0;
323 8543 $self->[_consecutive_nonblank_lines_]++;
324 8543 $self->[_output_line_number_]++;
325  
326 8543 ${ $self->[_routput_string_] } .= $str;
327  
328 8543 ▶ if ( $self->[_save_logfile_] ) { $self->check_line_lengths($str) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[19]) 2 8541 8543
329  
330 #----------------------------
331 # Convergence and error check
332 #----------------------------
333 8543 ▶ if ( defined($K) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $K) 7643 900 8543
334  
335 # Convergence check: we are checking if all defined K values arrive in
336 # the order which was defined by the caller. Quit checking if any
337 # unexpected K value arrives.
338 7643 ▶ if ( $self->[_K_arrival_order_matches_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[16]) 4065 3578 7643
339 4065 my $Kt = pop @{ $self->[_rK_checklist_] };
340 4065 ▶ if ( !defined($Kt) || $Kt != $K ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $Kt or $Kt != $K) 296 3769 4065
Condition66%2/3
not defined $Kt or $Kt != $K
l!l&&r!l&&!r
02963769
MC/DC50%1/2
not defined $Kt or $Kt != $K
not defined $Kt $Kt != $K
Truth table66%2/3
not(A) or B
A= not defined $KtB= $Kt != $K
ABresult
1X1
011
000
341 296 $self->[_K_arrival_order_matches_] = 0;
342 }
343 }
344  
345 # Check for out-of-order arrivals of index K. The K values are the
346 # token indexes of the last token of code lines, and they should come
347 # out in increasing order. Otherwise something is seriously wrong.
348 # Most likely a recent programming change to VerticalAligner.pm has
349 # caused lines to go out in the wrong order. This could happen if
350 # either the cache or buffer that it uses are emptied in the wrong
351 # order.
352 7643 ▶ if ( $K < $self->[_K_last_arrival_]
Branch: 1 branch
BranchTrueFalseTotal
if ($K < $self->[18] and not $self->[17]) 0 7643 7643
Condition33%1/3
$K < $self->[18] and not $self->[17]
!ll&&!rl&&r
764300
MC/DC0%0/2
$K < $self->[18] and not $self->[17]
$K < $self->[18] not $self->[17]
Truth table33%1/3
A and not(B)
A= $K < $self->[18]B= not $self->[17]
ABresult
0X0
100
111
353 && !$self->[_K_sequence_error_msg_] )
354 {
355 0 my $K_prev = $self->[_K_last_arrival_];
356  
357 0 chomp $str;
358 0 ▶ if ( length($str) > MAX_PRINTED_CHARS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str > 80) 0 0 0
359 0 $str = substr( $str, 0, MAX_PRINTED_CHARS ) . "...";
360 }
361  
362 0 my $msg = <<EOM;
363 Lines have arrived out of order in sub 'write_code_line'
364 as detected by token index K=$K arriving after index K=$K_prev in the following line:
365 $str
366 This is probably due to a recent programming change and needs to be fixed.
367 EOM
368  
369 # Always die during development, this needs to be fixed
370 0 if (DEVEL_MODE) { Fault($msg) }
371  
372 # Otherwise warn if string is not empty (added for b1378)
373 0 ▶ $self->warning($msg) if ( length($str) );
Branch: 1 branch
BranchTrueFalseTotal
if length $str 0 0 0
374  
375 # Only issue this warning once
376 0 $self->[_K_sequence_error_msg_] = $msg;
377  
378 }
379 7643 $self->[_K_last_arrival_] = $K;
380 }
381 8543 return;
382 } ## end sub write_code_line
383  
384 sub write_line {
385 407 ▶ my ( $self, $str ) = @_;
Subroutine write_line: called CC=3 SCAR=11.4
Pod undocumented
386  
387 # Write a line directly to the output, without any counting of blank or
388 # non-blank lines.
389  
390 # Given:
391 # $str = line of text to write
392  
393 407 ${ $self->[_routput_string_] } .= $str;
394  
395 407 ▶ if ( chomp $str ) { $self->[_output_line_number_]++; }
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $str) 407 0 407
396 407 ▶ if ( $self->[_save_logfile_] ) { $self->check_line_lengths($str) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[19]) 0 407 407
397  
398 407 return;
399 } ## end sub write_line
400  
401 sub check_line_lengths {
402 2 ▶ my ( $self, $str ) = @_;
Subroutine check_line_lengths: called CC=9 SCAR=32.6
Pod undocumented
403  
404 # Collect info on line lengths for logfile
405 # Given:
406 # $str = line of text being written
407  
408 # This calculation of excess line length ignores any internal tabs
409 2 my $rOpts = $self->[_rOpts_];
410 2 chomp $str;
411 2 my $len_str = length($str);
412 2 my $exceed = $len_str - $rOpts->{'maximum-line-length'};
413 2 ▶ if ( $str && substr( $str, 0, 1 ) eq "\t" && $str =~ /^\t+/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str and substr($str, 0, 1) eq "\t" and $str =~ /^\t+/g) 0 2 2
Condition33%2/6
$str and substr($str, 0, 1) eq "\t" and $str =~ /^\t+/g
!ll&&!rl&&r
200
$str and substr($str, 0, 1) eq "\t"
!ll&&!rl&&r
020
MC/DC0%0/3
$str and substr($str, 0, 1) eq "\t" and $str =~ /^\t+/g
$str substr($str, 0, 1) eq "\t" $str =~ /^\t+/g
Truth table25%1/4
A and B and C
A= $strB= substr($str, 0, 1) eq "\t"C= $str =~ /^\t+/g
ABCresult
0XX0
10X0
1100
1111
414 0 $exceed += pos($str) * $rOpts->{'indent-columns'};
415 }
416  
417 # Note that we just incremented output line number to future value
418 # so we must subtract 1 for current line number
419 2 ▶ if ( $len_str > $self->[_max_output_line_length_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_str > $self->[13]) 1 1 2
420 1 $self->[_max_output_line_length_] = $len_str;
421 1 $self->[_max_output_line_length_at_] =
422 $self->[_output_line_number_] - 1;
423 }
424  
425 2 ▶ if ( $exceed > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exceed > 0) 0 2 2
426 0 my $output_line_number = $self->[_output_line_number_];
427 0 $self->[_last_line_length_error_] = $exceed;
428 0 $self->[_last_line_length_error_at_] = $output_line_number - 1;
429 0 ▶ if ( $self->[_line_length_error_count_] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12] == 0) 0 0 0
430 0 $self->[_first_line_length_error_] = $exceed;
431 0 $self->[_first_line_length_error_at_] = $output_line_number - 1;
432 }
433  
434 0 ▶ if ( $self->[_last_line_length_error_] >
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[8] > $self->[7]) 0 0 0
435 $self->[_max_line_length_error_] )
436 {
437 0 $self->[_max_line_length_error_] = $exceed;
438 0 $self->[_max_line_length_error_at_] = $output_line_number - 1;
439 }
440  
441 0 ▶ if ( $self->[_line_length_error_count_] < MAX_NAG_MESSAGES ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12] < 6) 0 0 0
442 0 $self->write_logfile_entry(
443 "Line length exceeded by $exceed characters\n");
444 }
445 0 $self->[_line_length_error_count_]++;
446 }
447 2 return;
448 } ## end sub check_line_lengths
449  
450 sub report_line_length_errors {
451 661 ▶ my $self = shift;
Subroutine report_line_length_errors: called CC=5 SCAR=25.2
Pod undocumented
452  
453 # Write summary info about line lengths to the log file
454  
455 661 my $rOpts = $self->[_rOpts_];
456 661 my $line_length_error_count = $self->[_line_length_error_count_];
457 661 ▶ if ( $line_length_error_count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_length_error_count == 0) { } 661 0 661
458 661 $self->write_logfile_entry(
459 "No lines exceeded $rOpts->{'maximum-line-length'} characters\n");
460 661 my $max_output_line_length = $self->[_max_output_line_length_];
461 661 my $max_output_line_length_at = $self->[_max_output_line_length_at_];
462 661 $self->write_logfile_entry(
463 " Maximum output line length was $max_output_line_length at line $max_output_line_length_at\n"
464 );
465  
466 }
467 else {
468  
469 0 ▶ my $word = ( $line_length_error_count > 1 ) ? "s" : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$line_length_error_count > 1 ? : 0 0 0
470 0 $self->write_logfile_entry(
471 "$line_length_error_count output line$word exceeded $rOpts->{'maximum-line-length'} characters:\n"
472 );
473  
474 0 ▶ $word = ( $line_length_error_count > 1 ) ? "First" : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$line_length_error_count > 1 ? : 0 0 0
475 0 my $first_line_length_error = $self->[_first_line_length_error_];
476 0 my $first_line_length_error_at = $self->[_first_line_length_error_at_];
477 0 $self->write_logfile_entry(
478 " $word at line $first_line_length_error_at by $first_line_length_error characters\n"
479 );
480  
481 0 ▶ if ( $line_length_error_count > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_length_error_count > 1) 0 0 0
482 0 my $max_line_length_error = $self->[_max_line_length_error_];
483 0 my $max_line_length_error_at = $self->[_max_line_length_error_at_];
484 0 my $last_line_length_error = $self->[_last_line_length_error_];
485 0 my $last_line_length_error_at =
486 $self->[_last_line_length_error_at_];
487 0 $self->write_logfile_entry(
488 " Maximum at line $max_line_length_error_at by $max_line_length_error characters\n"
489 );
490 0 $self->write_logfile_entry(
491 " Last at line $last_line_length_error_at by $last_line_length_error characters\n"
492 );
493 }
494 }
495 661 return;
496 } ## end sub report_line_length_errors
497 45 1;
« Tidy/IOScalar.pm ↑ Summary Tidy/Debugger.pm »