Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / BuiltinFunctions / RequireBlockGrep.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep;
9
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
12 # examples.
13
14 use 5.006001;
15 use strict;
16 use warnings;
17 use Readonly;
18
19 use Perl::Critic::Utils qw{ :severities :classification :ppi };
20 use base 'Perl::Critic::Policy';
21
22 our $VERSION = '1.088';
23
24 #-----------------------------------------------------------------------------
25
26 Readonly::Scalar my $DESC => q{Expression form of "grep"};
27 Readonly::Scalar my $EXPL => [ 169 ];
28
29 #-----------------------------------------------------------------------------
30
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'  }
35
36 #-----------------------------------------------------------------------------
37
38 sub violates {
39     my ( $self, $elem, undef ) = @_;
40
41     return if $elem ne 'grep';
42     return if ! is_function_call($elem);
43
44     my $arg = first_arg($elem);
45     return if !$arg;
46     return if $arg->isa('PPI::Structure::Block');
47
48     return $self->violation( $DESC, $EXPL, $elem );
49 }
50
51 1;
52
53 __END__
54
55 #-----------------------------------------------------------------------------
56
57 =pod
58
59 =head1 NAME
60
61 Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep - Write C<grep { $_ =~ /$pattern/ } @list> instead of C<grep /$pattern/, @list>.
62
63 =head1 AFFILIATION
64
65 This Policy is part of the core L<Perl::Critic> distribution.
66
67
68 =head1 DESCRIPTION
69
70 The expression forms of C<grep> and C<map> are awkward and hard to read.
71 Use the block forms instead.
72
73   @matches = grep  /pattern/,    @list;        #not ok
74   @matches = grep { /pattern/ }  @list;        #ok
75
76   @mapped = map  transform($_),    @list;      #not ok
77   @mapped = map { transform($_) }  @list;      #ok
78
79
80
81 =head1 CONFIGURATION
82
83 This Policy is not configurable except for the standard options.
84
85
86 =head1 SEE ALSO
87
88 L<Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval>
89
90 L<Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap>
91
92 =head1 AUTHOR
93
94 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
95
96 =head1 COPYRIGHT
97
98 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
99
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.
103
104 =cut
105
106 # Local Variables:
107 #   mode: cperl
108 #   cperl-indent-level: 4
109 #   fill-column: 78
110 #   indent-tabs-mode: nil
111 #   c-indentation-style: bsd
112 # End:
113 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :