line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26302
|
use 5.010001; |
|
40
|
|
|
|
|
199
|
|
4
|
40
|
|
|
40
|
|
277
|
use strict; |
|
40
|
|
|
|
|
118
|
|
|
40
|
|
|
|
|
894
|
|
5
|
40
|
|
|
40
|
|
239
|
use warnings; |
|
40
|
|
|
|
|
139
|
|
|
40
|
|
|
|
|
991
|
|
6
|
40
|
|
|
40
|
|
292
|
use Readonly; |
|
40
|
|
|
|
|
115
|
|
|
40
|
|
|
|
|
2225
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
340
|
use Perl::Critic::Utils qw{ :severities :classification :ppi }; |
|
40
|
|
|
|
|
157
|
|
|
40
|
|
|
|
|
2108
|
|
9
|
40
|
|
|
40
|
|
15325
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
163
|
|
|
40
|
|
|
|
|
251
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.150'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Expression form of "map"}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 169 ]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
89
|
|
|
89
|
0
|
1622
|
sub supported_parameters { return () } |
21
|
74
|
|
|
74
|
1
|
305
|
sub default_severity { return $SEVERITY_HIGH } |
22
|
92
|
|
|
92
|
1
|
351
|
sub default_themes { return qw( core bugs pbp ) } |
23
|
32
|
|
|
32
|
1
|
87
|
sub applies_to { return 'PPI::Token::Word' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
346
|
|
|
346
|
1
|
583
|
my ( $self, $elem, undef ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
346
|
50
|
|
|
|
614
|
return if $elem ne 'map'; |
31
|
0
|
0
|
|
|
|
|
return if ! is_function_call($elem); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $arg = first_arg($elem); |
34
|
0
|
0
|
|
|
|
|
return if !$arg; |
35
|
0
|
0
|
|
|
|
|
return if $arg->isa('PPI::Structure::Block'); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $self->violation( $DESC, $EXPL, $elem ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=pod |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap - Write C<map { /$pattern/ } @list> instead of C<map /$pattern/, @list>. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 AFFILIATION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
55
|
|
|
|
|
|
|
distribution. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The expression forms of C<grep> and C<map> are awkward and hard to |
60
|
|
|
|
|
|
|
read. Use the block forms instead. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
@matches = grep /pattern/, @list; #not ok |
63
|
|
|
|
|
|
|
@matches = grep { /pattern/ } @list; #ok |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
@mapped = map transform($_), @list; #not ok |
66
|
|
|
|
|
|
|
@mapped = map { transform($_) } @list; #ok |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 CONFIGURATION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SEE ALSO |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L<Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval|Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep|Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright (c) 2005-2013 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 : |