1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockGrep.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep;
10 # DEVELOPER NOTE: this module is used as an example in DEVELOPER.pod.
11 # If you make changes in here, please reflect those changes in the
19 use Perl::Critic::Utils qw{ :severities :classification :ppi };
20 use base 'Perl::Critic::Policy';
22 our $VERSION = '1.088';
24 #-----------------------------------------------------------------------------
26 Readonly::Scalar my $DESC => q{Expression form of "grep"};
27 Readonly::Scalar my $EXPL => [ 169 ];
29 #-----------------------------------------------------------------------------
31 sub supported_parameters { return () }
32 sub default_severity { return $SEVERITY_HIGH }
33 sub default_themes { return qw( core bugs pbp ) }
34 sub applies_to { return 'PPI::Token::Word' }
36 #-----------------------------------------------------------------------------
39 my ( $self, $elem, undef ) = @_;
41 return if $elem ne 'grep';
42 return if ! is_function_call($elem);
44 my $arg = first_arg($elem);
46 return if $arg->isa('PPI::Structure::Block');
48 return $self->violation( $DESC, $EXPL, $elem );
55 #-----------------------------------------------------------------------------
61 Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep - Write C<grep { $_ =~ /$pattern/ } @list> instead of C<grep /$pattern/, @list>.
65 This Policy is part of the core L<Perl::Critic> distribution.
70 The expression forms of C<grep> and C<map> are awkward and hard to read.
71 Use the block forms instead.
73 @matches = grep /pattern/, @list; #not ok
74 @matches = grep { /pattern/ } @list; #ok
76 @mapped = map transform($_), @list; #not ok
77 @mapped = map { transform($_) } @list; #ok
83 This Policy is not configurable except for the standard options.
88 L<Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval>
90 L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap>
94 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
98 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
100 This program is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself. The full text of this license
102 can be found in the LICENSE file included with this module.
108 # cperl-indent-level: 4
110 # indent-tabs-mode: nil
111 # c-indentation-style: bsd
113 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :