| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!perl |
|
2
|
|
|
|
|
|
|
# PODNAME: Perl::Critic::Policy::BuiltinFunctions::ProhibitForeach |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Prohibit foreach keyword |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
965661
|
use strict; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
145
|
|
|
7
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
424
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::ProhibitForeach; |
|
10
|
|
|
|
|
|
|
$Perl::Critic::Policy::BuiltinFunctions::ProhibitForeach::VERSION = '0.01'; |
|
11
|
3
|
|
|
3
|
|
2073
|
use Perl::Critic::Utils qw(:severities :classification :ppi); |
|
|
3
|
|
|
|
|
393365
|
|
|
|
3
|
|
|
|
|
164
|
|
|
12
|
3
|
|
|
3
|
|
3278
|
use parent 'Perl::Critic::Policy'; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
193649
|
use constant DESC => '"foreach" used'; |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
295
|
|
|
15
|
3
|
|
|
3
|
|
21
|
use constant EXPL => 'This codebase uses "for" rather than "foreach"'; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
605
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
1
|
17011
|
sub applies_to { return 'PPI::Token::Word' } |
|
18
|
1
|
|
|
1
|
1
|
21
|
sub default_severity { return $SEVERITY_LOW } |
|
19
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return () } |
|
20
|
1
|
|
|
1
|
0
|
2465961
|
sub supported_parameters { return () } |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub violates { |
|
23
|
3
|
|
|
3
|
1
|
503
|
my ($self, $elem) = @_; |
|
24
|
3
|
100
|
|
|
|
13
|
return () unless $elem eq 'foreach'; |
|
25
|
1
|
|
|
|
|
36
|
return $self->violation(DESC, EXPL, $elem); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__END__ |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=pod |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=encoding UTF-8 |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::ProhibitForeach - Prohibit foreach keyword |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 VERSION |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
version 0.01 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This policy prohibits the use of the C<foreach> keyword in favour of the C<for> keyword. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Apply this policy in your code base for the sake of consistency. There can only be one! |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
foreach my $foo (1..10) { # not ok |
|
52
|
|
|
|
|
|
|
for my $foo (1..10) { # ok |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
You may also experience additional benefits including screen space savings, reduced storage, saved bandwidth, |
|
55
|
|
|
|
|
|
|
reduced carbon emissions, less greenhouse gases, increased muscle mass, improved blood pressure, etc. you |
|
56
|
|
|
|
|
|
|
may even get a promotion and gain greater charisma. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This policy is not configurable except for the standard options. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
L<Perl::Critic> |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Dean Hamstead <dean@fragfest.com.au> |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This software is Copyright (c) 2025 by Dean Hamstead. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This is free software, licensed under: |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The MIT (X11) License |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |