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 / ProhibitVoidMap.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitVoidMap.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::ProhibitVoidMap;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities :classification is_in_void_context };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{"map" used in void context};
23 Readonly::Scalar my $EXPL => q{Use a "for" loop instead};
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters { return ()                     }
28 sub default_severity     { return $SEVERITY_MEDIUM       }
29 sub default_themes       { return qw( core maintenance ) }
30 sub applies_to           { return 'PPI::Token::Word'     }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36
37     return if $elem ne 'map';
38     return if not is_function_call($elem);
39     return if not is_in_void_context($elem);
40
41     return $self->violation( $DESC, $EXPL, $elem );
42 }
43
44
45 1;
46
47 __END__
48
49 #-----------------------------------------------------------------------------
50
51 =pod
52
53 =head1 NAME
54
55 Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap - Don't use C<map> in void contexts.
56
57 =head1 AFFILIATION
58
59 This Policy is part of the core L<Perl::Critic> distribution.
60
61
62 =head1 DESCRIPTION
63
64 C<map> and C<grep> are intended to be pure functions, not mutators.
65 If you want to iterate with side-effects, then you should use a proper
66 C<for> or C<foreach> loop.
67
68   grep{ print frobulate($_) } @list;           #not ok
69   print map{ frobulate($_) } @list;            #ok
70
71   grep{ $_ = lc $_ } @list;                    #not ok
72   for( @list ){ $_ = lc $_  };                 #ok
73
74   map{ push @frobbed, frobulate($_) } @list;   #not ok
75   @frobbed = map { frobulate($_) } @list;      #ok
76
77
78 =head1 CONFIGURATION
79
80 This Policy is not configurable except for the standard options.
81
82
83 =head1 AUTHOR
84
85 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
86
87 =head1 COPYRIGHT
88
89 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
90
91 This program is free software; you can redistribute it and/or modify
92 it under the same terms as Perl itself.  The full text of this license
93 can be found in the LICENSE file included with this module.
94
95 =cut
96
97 # Local Variables:
98 #   mode: cperl
99 #   cperl-indent-level: 4
100 #   fill-column: 78
101 #   indent-tabs-mode: nil
102 #   c-indentation-style: bsd
103 # End:
104 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :