blib/lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockMap.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 76.7% 43 / 56 CC 5 SCAR 18.9
CC
5
Cov
70%
violates
17.8
BEGIN
1.0
BEGIN
1.0
CRAP 6.6
« blib/lib/Perl/Critic/Policy/Modules/RequireVersionVar.pm ↑ Summary blib/lib/Perl/Critic/PolicyParameter/Behavior/Integer.pm »
1 package Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities :classification :ppi };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Expression form of "map"};
16 40 Readonly::Scalar my $EXPL => [ 169 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 92 ▶sub default_themes { return qw( core bugs pbp ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 33 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 349 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: called CC=5 SCAR=28.8
Pod documented
29  
30 349 ▶ return if $elem ne 'map';
Branch: 1 branch
BranchTrueFalseTotal
if $elem ne "map" 349 0 349
31 0 ▶ return if ! is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 0 0
32  
33 0 my $arg = first_arg($elem);
34 0 ▶ return if !$arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 0 0 0
35 0 ▶ return if $arg->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
if $arg->isa("PPI::Structure::Block") 0 0 0
36  
37 0 return $self->violation( $DESC, $EXPL, $elem );
38 }
39  
40 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 :
« blib/lib/Perl/Critic/Policy/Modules/RequireVersionVar.pm ↑ Summary blib/lib/Perl/Critic/PolicyParameter/Behavior/Integer.pm »