1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockMap.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap;
15 use Perl::Critic::Utils qw{ :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Expression form of "map"};
23 Readonly::Scalar my $EXPL => [ 169 ];
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_HIGH }
29 sub default_themes { return qw( core bugs pbp ) }
30 sub applies_to { return 'PPI::Token::Word' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, undef ) = @_;
37 return if $elem ne 'map';
38 return if ! is_function_call($elem);
40 my $arg = first_arg($elem);
42 return if $arg->isa('PPI::Structure::Block');
44 return $self->violation( $DESC, $EXPL, $elem );
51 #-----------------------------------------------------------------------------
57 Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap - Write C<map { $_ =~ /$pattern/ } @list> instead of C<map /$pattern/, @list>.
61 This Policy is part of the core L<Perl::Critic> distribution.
66 The expression forms of C<grep> and C<map> are awkward and hard to read.
67 Use the block forms instead.
69 @matches = grep /pattern/, @list; #not ok
70 @matches = grep { /pattern/ } @list; #ok
72 @mapped = map transform($_), @list; #not ok
73 @mapped = map { transform($_) } @list; #ok
79 This Policy is not configurable except for the standard options.
84 L<Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval>
86 L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep>
90 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
94 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
96 This program is free software; you can redistribute it and/or modify
97 it under the same terms as Perl itself. The full text of this license
98 can be found in the LICENSE file included with this module.
104 # cperl-indent-level: 4
106 # indent-tabs-mode: nil
107 # c-indentation-style: bsd
109 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :