Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

perl::critic::policy::controlstructures::prohibitmutatinglistfun(3) [centos man page]

Perl::Critic::Policy::ControlStructures::ProhibitMutatinUsertContributed)Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions(3)

NAME
Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions - Don't modify "$_" in list functions. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
"map", "grep" and other list operators are intended to transform arrays into other arrays by applying code to the array elements one by one. For speed, the elements are referenced via a $_ alias rather than copying them. As a consequence, if the code block of the "map" or "grep" modify $_ in any way, then it is actually modifying the source array. This IS technically allowed, but those side effects can be quite surprising, especially when the array being passed is @_ or perhaps "values(%ENV)"! Instead authors should restrict in-place array modification to "for(@array) { ... }" constructs instead, or use "List::MoreUtils::apply()". CONFIGURATION
By default, this policy applies to the following list functions: map grep List::Util qw(first) List::MoreUtils qw(any all none notall true false firstidx first_index lastidx last_index insert_after insert_after_string) This list can be overridden the .perlcriticrc file like this: [ControlStructures::ProhibitMutatingListFunctions] list_funcs = map grep List::Util::first Or, one can just append to the list like so: [ControlStructures::ProhibitMutatingListFunctions] add_list_funcs = Foo::Bar::listmunge LIMITATIONS
This policy deliberately does not apply to "for (@array) { ... }" or "List::MoreUtils::apply()". Currently, the policy only detects explicit external module usage like this: my @out = List::MoreUtils::any {s/^foo//} @in; and not like this: use List::MoreUtils qw(any); my @out = any {s/^foo//} @in; This policy looks only for modifications of $_. Other naughtiness could include modifying $a and $b in "sort" and the like. That's beyond the scope of this policy. SEE ALSO
There is discussion of this policy at <http://perlmonks.org/index.pl?node_id=743445>. AUTHOR
Chris Dolan <cdolan@cpan.org> Michael Wolf <MichaelRWolf@att.net> COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2014-Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions(3)

Check Out this Related Man Page

Perl::Critic::Policy::ControlStructures::ProhibitUnreachUserCContributed Perl DPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode(3)

NAME
Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode - Don't write code after an unconditional "die, exit, or next". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
This policy prohibits code following a statement which unconditionally alters the program flow. This includes calls to "exit", "die", "return", "next", "last" and "goto". Due to common usage, "croak" and "confess" from Carp are also included. Code is reachable if any of the following conditions are true: o Flow-altering statement has a conditional attached to it o Statement is on the right side of an operator "&&", "||", "//", "and", "or", or "err". o Code is prefixed with a label (can potentially be reached via "goto") o Code is a subroutine EXAMPLES
# not ok exit; print "123 "; # ok exit if !$xyz; print "123 "; # not ok for ( 1 .. 10 ) { next; print 1; } # ok for ( 1 .. 10 ) { next if $_ == 5; print 1; } # not ok sub foo { my $bar = shift; return; print 1; } # ok sub foo { my $bar = shift; return if $bar->baz(); print 1; } # not ok die; print "123 "; # ok die; LABEL: print "123 "; # not ok croak; do_something(); # ok croak; sub do_something {} CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls AUTHOR
Peter Guzis <pguzis@cpan.org> COPYRIGHT
Copyright (c) 2006-2011 Peter Guzis. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode(3)
Man Page