line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
27375
|
use 5.010001; |
|
40
|
|
|
|
|
185
|
|
4
|
40
|
|
|
40
|
|
267
|
use strict; |
|
40
|
|
|
|
|
104
|
|
|
40
|
|
|
|
|
885
|
|
5
|
40
|
|
|
40
|
|
245
|
use warnings; |
|
40
|
|
|
|
|
167
|
|
|
40
|
|
|
|
|
1166
|
|
6
|
40
|
|
|
40
|
|
267
|
use Readonly; |
|
40
|
|
|
|
|
138
|
|
|
40
|
|
|
|
|
2250
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
316
|
use Perl::Critic::Utils qw{ :severities :classification is_in_void_context }; |
|
40
|
|
|
|
|
137
|
|
|
40
|
|
|
|
|
2211
|
|
9
|
40
|
|
|
40
|
|
14927
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
142
|
|
|
40
|
|
|
|
|
277
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{"grep" used in void context}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Use a "for" loop instead}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
94
|
|
|
94
|
0
|
2025
|
sub supported_parameters { return () } |
21
|
83
|
|
|
83
|
1
|
393
|
sub default_severity { return $SEVERITY_MEDIUM } |
22
|
74
|
|
|
74
|
1
|
315
|
sub default_themes { return qw( core maintenance ) } |
23
|
35
|
|
|
35
|
1
|
113
|
sub applies_to { return 'PPI::Token::Word' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
383
|
|
|
383
|
1
|
741
|
my ( $self, $elem, undef ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
383
|
100
|
|
|
|
758
|
return if $elem->content() ne 'grep'; |
31
|
27
|
100
|
|
|
|
150
|
return if not is_function_call($elem); |
32
|
22
|
100
|
|
|
|
58
|
return if not is_in_void_context($elem); |
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
|
|
75
|
return $self->violation( $DESC, $EXPL, $elem ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep - Don't use C<grep> in void contexts. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 AFFILIATION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
54
|
|
|
|
|
|
|
distribution. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
C<map> and C<grep> are intended to be pure functions, not mutators. |
60
|
|
|
|
|
|
|
If you want to iterate with side-effects, then you should use a proper |
61
|
|
|
|
|
|
|
C<for> or C<foreach> loop. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
grep{ print frobulate($_) } @list; #not ok |
64
|
|
|
|
|
|
|
print map{ frobulate($_) } @list; #ok |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
grep{ $_ = lc $_ } @list; #not ok |
67
|
|
|
|
|
|
|
for( @list ){ $_ = lc $_ }; #ok |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
map{ push @frobbed, frobulate($_) } @list; #not ok |
70
|
|
|
|
|
|
|
@frobbed = map { frobulate($_) } @list; #ok |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 CONFIGURATION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
88
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
89
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Local Variables: |
94
|
|
|
|
|
|
|
# mode: cperl |
95
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
96
|
|
|
|
|
|
|
# fill-column: 78 |
97
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
98
|
|
|
|
|
|
|
# c-indentation-style: bsd |
99
|
|
|
|
|
|
|
# End: |
100
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |