Tidy/IndentationItem.pm

filter: Statementstmt 90.7% 108 / 119 Branchbran 57.6% 15 / 26 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 88.2% 30 / 34 Podpod 0.0% 0 / 28 totaltotal 74.5% 158 / 212 CC 15 SCAR 6.5
CC
15
Cov
85%
AUTOLOAD
6.0
permanently_decrease_available_spaces
4.0
set_marked
2.0
CRAP 1.9
« Tidy/VerticalAligner/Alignment.pm ↑ Summary
1 package Perl::Tidy::IndentationItem;
2  
3 #####################################################################
4 #
5 # The Perl::Tidy::IndentationItem class supplies items which contain
6 # how much whitespace should be used at the start of a line
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  
13 45 our $VERSION = '20260826';
14  
15 45 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Array index names
18 # Do not combine with other BEGIN blocks (c101).
19 45 my $i = 0;
20 45 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 45 _spaces_ => $i++,
22 _level_ => $i++,
23 _ci_level_ => $i++,
24 _available_spaces_ => $i++,
25 _closed_ => $i++,
26 _comma_count_ => $i++,
27 _lp_item_index_ => $i++,
28 _have_child_ => $i++,
29 _recoverable_spaces_ => $i++,
30 _align_seqno_ => $i++,
31 _marked_ => $i++,
32 _K_begin_line_ => $i++,
33 _arrow_count_ => $i++,
34 _standard_spaces_ => $i++,
35 _K_extra_space_ => $i++,
36 45 };
37 } ## end BEGIN
38  
39 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
40  
41 # Catch any undefined sub calls so that we are sure to get
42 # some diagnostic information. This sub should never be called
43 # except for a programming error.
44 0 our $AUTOLOAD;
45 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::IndentationItem::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
46 0 my ( $pkg, $fname, $lno ) = caller();
47 0 my $my_package = __PACKAGE__;
48 0 print {*STDERR} <<EOM;
49 ======================================================================
50 Error detected in package '$my_package', version $VERSION
51 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
52 Called from package: '$pkg'
53 Called from File '$fname' at line '$lno'
54 This error is probably due to a recent programming change
55 ======================================================================
56 EOM
57 0 exit 1;
58 } ## end sub AUTOLOAD
59  
60 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
61  
62 # required to avoid call to AUTOLOAD in some versions of perl
63 }
64  
65 623 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
66  
67 # Create an 'indentation_item' which describes one level of leading
68 # whitespace when the '-lp' indentation is used.
69 623 my ( $class, %input_hash ) = @_;
70  
71 # DEFINITIONS:
72 # spaces => # total leading white spaces
73 # level => # the indentation 'level'
74 # ci_level => # the 'continuation level'
75 # available_spaces => # how many left spaces available
76 # # for this level
77 # closed => # index where we saw closing '}'
78 # comma_count => # how many commas at this level?
79 # lp_item_index => # index in output batch list
80 # have_child => # any dependents?
81 # recoverable_spaces => # how many spaces to the right
82 # # we would like to move to get
83 # # alignment (negative if left)
84 # align_seqno => # if we are aligning with an opening structure,
85 # # this is its seqno
86 # marked => # if visited by corrector logic
87 # K_begin_line => # first token index K of this level
88 # arrow_count => # how many =>'s
89  
90 623 my $self = [];
91 623 bless $self, $class;
92  
93 623 $self->[_spaces_] = $input_hash{spaces};
94 623 $self->[_level_] = $input_hash{level};
95 623 $self->[_ci_level_] = $input_hash{ci_level};
96 623 $self->[_available_spaces_] = $input_hash{available_spaces};
97 623 $self->[_closed_] = -1;
98 623 $self->[_comma_count_] = 0;
99 623 $self->[_lp_item_index_] = $input_hash{lp_item_index};
100 623 $self->[_have_child_] = 0;
101 623 $self->[_recoverable_spaces_] = 0;
102 623 $self->[_align_seqno_] = $input_hash{align_seqno};
103 623 $self->[_marked_] = 0;
104 623 $self->[_K_begin_line_] = $input_hash{K_begin_line};
105 623 $self->[_arrow_count_] = 0;
106 623 $self->[_standard_spaces_] = $input_hash{standard_spaces};
107 623 $self->[_K_extra_space_] = $input_hash{K_extra_space};
108  
109 623 return $self;
110 } ## end sub new
111  
112 279 ▶sub permanently_decrease_available_spaces {
Subroutine permanently_decrease_available_spaces: called CC=4 SCAR=13.9
Pod undocumented
113  
114 # make a permanent reduction in the available indentation spaces
115 # at one indentation item. NOTE: if there are child nodes, their
116 # total SPACES must be reduced by the caller.
117  
118 279 my ( $self, $spaces_needed ) = @_;
119 279 my $available_spaces = $self->get_available_spaces();
120 279 ▶ my $deleted_spaces =
Branch: 1 branch
BranchTrueFalseTotal
$available_spaces > $spaces_needed ? : 241 38 279
121 ( $available_spaces > $spaces_needed )
122 ? $spaces_needed
123 : $available_spaces;
124  
125 # Fixed for c085; a zero value must remain unchanged unless the closed
126 # flag has been set.
127 279 my $closed = $self->get_closed();
128 279 ▶ $self->decrease_available_spaces($deleted_spaces)
Branch: 1 branch
BranchTrueFalseTotal
if $available_spaces != 0 or $closed >= 0 277 2 279
Condition100%3/3
$available_spaces != 0 or $closed >= 0
l!l&&r!l&&!r
1721052
MC/DC100%2/2
$available_spaces != 0 or $closed >= 0
$available_spaces != 0 $closed >= 0
Truth table100%3/3
A or B
A= $available_spaces != 0B= $closed >= 0
ABresult
1X1
011
000
129 if ( $available_spaces != 0 || $closed >= 0 );
130 279 $self->decrease_SPACES($deleted_spaces);
131 279 $self->set_recoverable_spaces(0);
132  
133 279 return $deleted_spaces;
134 } ## end sub permanently_decrease_available_spaces
135  
136 72 ▶sub tentatively_decrease_available_spaces {
Subroutine tentatively_decrease_available_spaces: called CC=2 SCAR=6.9
Pod undocumented
137  
138 # We are asked to tentatively delete $spaces_needed of indentation
139 # for an indentation item. We may want to undo this later. NOTE: if
140 # there are child nodes, their total SPACES must be reduced by the
141 # caller.
142 72 my ( $self, $spaces_needed ) = @_;
143 72 my $available_spaces = $self->get_available_spaces();
144 72 ▶ my $deleted_spaces =
Branch: 1 branch
BranchTrueFalseTotal
$available_spaces > $spaces_needed ? : 5 67 72
145 ( $available_spaces > $spaces_needed )
146 ? $spaces_needed
147 : $available_spaces;
148 72 $self->decrease_available_spaces($deleted_spaces);
149 72 $self->decrease_SPACES($deleted_spaces);
150 72 $self->increase_recoverable_spaces($deleted_spaces);
151 72 return $deleted_spaces;
152 } ## end sub tentatively_decrease_available_spaces
153  
154 # time-critical sub
155 6829 ▶sub get_spaces {
Subroutine get_spaces: called CC=1 SCAR=0.0
Pod undocumented
156 6829 return $_[0]->[_spaces_];
157 }
158  
159 57 ▶sub get_standard_spaces {
Subroutine get_standard_spaces: called CC=1 SCAR=0.0
Pod undocumented
160 57 my $self = shift;
161 57 return $self->[_standard_spaces_];
162 }
163  
164 # time-critical sub
165 3261 ▶sub get_marked {
Subroutine get_marked: called CC=1 SCAR=0.0
Pod undocumented
166 3261 return $_[0]->[_marked_];
167 }
168  
169 623 ▶sub set_marked {
Subroutine set_marked: called CC=2 SCAR=7.0
Pod undocumented
170 623 my ( $self, $value ) = @_;
171 623 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 623 0 623
172 623 $self->[_marked_] = $value;
173 }
174 623 return $self->[_marked_];
175 } ## end sub set_marked
176  
177 1029 ▶sub get_available_spaces {
Subroutine get_available_spaces: called CC=1 SCAR=0.0
Pod undocumented
178 1029 my $self = shift;
179 1029 return $self->[_available_spaces_];
180 }
181  
182 881 ▶sub decrease_SPACES {
Subroutine decrease_SPACES: called CC=2 SCAR=7.0
Pod undocumented
183 881 my ( $self, $value ) = @_;
184 881 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 881 0 881
185 881 $self->[_spaces_] -= $value;
186 }
187 881 return $self->[_spaces_];
188 } ## end sub decrease_SPACES
189  
190 351 ▶sub decrease_available_spaces {
Subroutine decrease_available_spaces: called CC=2 SCAR=7.0
Pod undocumented
191 351 my ( $self, $value ) = @_;
192  
193 351 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 351 0 351
194 351 $self->[_available_spaces_] -= $value;
195 }
196 351 return $self->[_available_spaces_];
197 } ## end sub decrease_available_spaces
198  
199 623 ▶sub get_align_seqno {
Subroutine get_align_seqno: called CC=1 SCAR=0.0
Pod undocumented
200 623 my $self = shift;
201 623 return $self->[_align_seqno_];
202 }
203  
204 303 ▶sub get_recoverable_spaces {
Subroutine get_recoverable_spaces: called CC=1 SCAR=0.0
Pod undocumented
205 303 my $self = shift;
206 303 return $self->[_recoverable_spaces_];
207 }
208  
209 444 ▶sub set_recoverable_spaces {
Subroutine set_recoverable_spaces: called CC=2 SCAR=7.0
Pod undocumented
210 444 my ( $self, $value ) = @_;
211 444 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 444 0 444
212 444 $self->[_recoverable_spaces_] = $value;
213 }
214 444 return $self->[_recoverable_spaces_];
215 } ## end sub set_recoverable_spaces
216  
217 72 ▶sub increase_recoverable_spaces {
Subroutine increase_recoverable_spaces: called CC=2 SCAR=7.0
Pod undocumented
218 72 my ( $self, $value ) = @_;
219 72 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 72 0 72
220 72 $self->[_recoverable_spaces_] += $value;
221 }
222 72 return $self->[_recoverable_spaces_];
223 } ## end sub increase_recoverable_spaces
224  
225 0 ▶sub get_ci_level {
Subroutine get_ci_level: not called CC=1 SCAR=6.9
Pod undocumented
226 0 my $self = shift;
227 0 return $self->[_ci_level_];
228 }
229  
230 0 ▶sub get_level {
Subroutine get_level: not called CC=1 SCAR=6.9
Pod undocumented
231 0 my $self = shift;
232 0 return $self->[_level_];
233 }
234  
235 1333 ▶sub get_spaces_level_ci {
Subroutine get_spaces_level_ci: called CC=1 SCAR=0.0
Pod undocumented
236 1333 my $self = shift;
237 1333 return [ $self->[_spaces_], $self->[_level_], $self->[_ci_level_] ];
238 }
239  
240 56 ▶sub get_lp_item_index {
Subroutine get_lp_item_index: called CC=1 SCAR=0.0
Pod undocumented
241 56 my $self = shift;
242 56 return $self->[_lp_item_index_];
243 }
244  
245 736 ▶sub get_K_begin_line {
Subroutine get_K_begin_line: called CC=1 SCAR=0.0
Pod undocumented
246 736 my $self = shift;
247 736 return $self->[_K_begin_line_];
248 }
249  
250 30 ▶sub get_K_extra_space {
Subroutine get_K_extra_space: called CC=1 SCAR=0.0
Pod undocumented
251 30 my $self = shift;
252 30 return $self->[_K_extra_space_];
253 }
254  
255 506 ▶sub set_have_child {
Subroutine set_have_child: called CC=2 SCAR=7.0
Pod undocumented
256 506 my ( $self, $value ) = @_;
257 506 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 506 0 506
258 506 $self->[_have_child_] = $value;
259 }
260 506 return $self->[_have_child_];
261 } ## end sub set_have_child
262  
263 70 ▶sub get_have_child {
Subroutine get_have_child: called CC=1 SCAR=0.0
Pod undocumented
264 70 my $self = shift;
265 70 return $self->[_have_child_];
266 }
267  
268 623 ▶sub set_arrow_count {
Subroutine set_arrow_count: called CC=2 SCAR=7.0
Pod undocumented
269 623 my ( $self, $value ) = @_;
270 623 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 623 0 623
271 623 $self->[_arrow_count_] = $value;
272 }
273 623 return $self->[_arrow_count_];
274 } ## end sub set_arrow_count
275  
276 69 ▶sub get_arrow_count {
Subroutine get_arrow_count: called CC=1 SCAR=0.0
Pod undocumented
277 69 my $self = shift;
278 69 return $self->[_arrow_count_];
279 }
280  
281 623 ▶sub set_comma_count {
Subroutine set_comma_count: called CC=2 SCAR=7.0
Pod undocumented
282 623 my ( $self, $value ) = @_;
283 623 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 623 0 623
284 623 $self->[_comma_count_] = $value;
285 }
286 623 return $self->[_comma_count_];
287 } ## end sub set_comma_count
288  
289 69 ▶sub get_comma_count {
Subroutine get_comma_count: called CC=1 SCAR=0.0
Pod undocumented
290 69 my $self = shift;
291 69 return $self->[_comma_count_];
292 }
293  
294 623 ▶sub set_closed {
Subroutine set_closed: called CC=2 SCAR=7.0
Pod undocumented
295 623 my ( $self, $value ) = @_;
296 623 ▶ if ( defined($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 623 0 623
297 623 $self->[_closed_] = $value;
298 }
299 623 return $self->[_closed_];
300 } ## end sub set_closed
301  
302 1153 ▶sub get_closed {
Subroutine get_closed: called CC=1 SCAR=0.0
Pod undocumented
303 1153 my $self = shift;
304 1153 return $self->[_closed_];
305 }
306 45 1;
« Tidy/VerticalAligner/Alignment.pm ↑ Summary