line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26516
|
use 5.010001; |
|
40
|
|
|
|
|
180
|
|
4
|
40
|
|
|
40
|
|
266
|
use strict; |
|
40
|
|
|
|
|
102
|
|
|
40
|
|
|
|
|
827
|
|
5
|
40
|
|
|
40
|
|
251
|
use warnings; |
|
40
|
|
|
|
|
105
|
|
|
40
|
|
|
|
|
1062
|
|
6
|
40
|
|
|
40
|
|
233
|
use Readonly; |
|
40
|
|
|
|
|
125
|
|
|
40
|
|
|
|
|
2084
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
295
|
use Perl::Critic::Utils qw{ :characters :severities }; |
|
40
|
|
|
|
|
117
|
|
|
40
|
|
|
|
|
2064
|
|
9
|
40
|
|
|
40
|
|
12678
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
124
|
|
|
40
|
|
|
|
|
299
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{C-style "for" loop used}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 100 ]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
91
|
|
|
91
|
0
|
1700
|
sub supported_parameters { return () } |
21
|
77
|
|
|
77
|
1
|
360
|
sub default_severity { return $SEVERITY_LOW } |
22
|
86
|
|
|
86
|
1
|
394
|
sub default_themes { return qw( core pbp maintenance ) } |
23
|
32
|
|
|
32
|
1
|
109
|
sub applies_to { return 'PPI::Structure::For' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
3
|
|
|
3
|
1
|
12
|
my ( $self, $elem, undef ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
|
|
|
15
|
if ( _is_cstyle($elem) ) { |
31
|
3
|
|
|
|
|
30
|
return $self->violation( $DESC, $EXPL, $elem ); |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
0
|
return; #ok! |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _is_cstyle { |
37
|
3
|
|
|
3
|
|
9
|
my $elem = shift; |
38
|
3
|
|
|
|
|
23
|
my $nodes_ref = $elem->find('PPI::Token::Structure'); |
39
|
3
|
50
|
|
|
|
1648
|
return if !$nodes_ref; |
40
|
3
|
|
|
|
|
9
|
my @semis = grep { $_ eq $SCOLON } @{$nodes_ref}; |
|
6
|
|
|
|
|
71
|
|
|
3
|
|
|
|
|
10
|
|
41
|
3
|
|
|
|
|
1342
|
return scalar @semis == 2; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops - Write C<for(0..20)> instead of C<for($i=0; $i<=20; $i++)>. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 AFFILIATION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
59
|
|
|
|
|
|
|
distribution. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The 3-part C<for> loop that Perl inherits from C is butt-ugly, and |
65
|
|
|
|
|
|
|
only really necessary if you need irregular counting. The very |
66
|
|
|
|
|
|
|
Perlish C<..> operator is much more elegant and readable. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
for($i=0; $i<=$max; $i++){ #ick! |
69
|
|
|
|
|
|
|
do_something($i); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
for(0..$max){ #very nice |
73
|
|
|
|
|
|
|
do_something($_); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 CONFIGURATION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
91
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
92
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Local Variables: |
97
|
|
|
|
|
|
|
# mode: cperl |
98
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
99
|
|
|
|
|
|
|
# fill-column: 78 |
100
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
101
|
|
|
|
|
|
|
# c-indentation-style: bsd |
102
|
|
|
|
|
|
|
# End: |
103
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |