Perl::Critic::PolicySummary - Description of the bundled Policy modules
The following Policy modules are distributed with Perl::Critic. The Policy modules have been categorized according to the table of contents in Damian Conway's book Perl Best Practices. Since most coding standards take the form "do this..." or "don't do that...", I have adopted the convention of naming each module RequireSomething or ProhibitSomething. Each Policy is listed here with it's default severity. If you don't agree with the default severity, you can change it in your .perlcriticrc file. See the documentation of each module for it's specific details.
RequireSomething
ProhibitSomething
Use 4-argument substr instead of writing substr($foo, 2, 6) = $bar [Severity 3]
substr
substr($foo, 2, 6) = $bar
Forbid $b before $a in sort blocks [Severity 1]
Use Time::HiRes instead of something like select(undef, undef, undef, .05) [Severity 5]
select(undef, undef, undef, .05)
Write eval { my $foo; bar($foo) } instead of eval "my $foo; bar($foo);" [Severity 5]
eval { my $foo; bar($foo) }
eval "my $foo; bar($foo);"
Write split /-/, $string instead of split '-', $string [Severity 3]
split /-/, $string
split '-', $string
Write eval { $foo->can($name) } instead of UNIVERSAL::can($foo, $name) [Severity 3]
eval { $foo->can($name) }
UNIVERSAL::can($foo, $name)
Write eval { $foo->isa($pkg) } instead of UNIVERSAL::isa($foo, $pkg) [Severity 3]
eval { $foo->isa($pkg) }
UNIVERSAL::isa($foo, $pkg)
Don't use grep in void contexts. [Severity 3]
grep
Don't use map in void contexts. [Severity 3]
map
Write grep { $_ =~ /$pattern/ } @list instead of grep /$pattern/, @list [Severity 4]
grep { $_ =~ /$pattern/ } @list
grep /$pattern/, @list
Write map { $_ =~ /$pattern/ } @list instead of map /$pattern/, @list [Severity 4]
map { $_ =~ /$pattern/ } @list
map /$pattern/, @list
Use glob q{*} instead of <*> [Severity 5]
glob q{*}
Sort blocks should have a single statement [Severity 3]
AUTOLOAD methods should be avoided [Severity 3]
Employ use base instead of @ISA [Severity 3]
use base
@ISA
Write bless {}, $class; instead of just bless {}; [Severity 5]
bless {}, $class;
bless {};
Use spaces instead of tabs. [Severity 3]
Write open $handle, $path instead of open($handle, $path) [Severity 1]
open $handle, $path
open($handle, $path)
Write qw(foo bar baz) instead of ('foo', 'bar', 'baz') [Severity 2]
qw(foo bar baz)
('foo', 'bar', 'baz')
Use the same newline through the source [Severity 4]
Must run code through perltidy. [Severity 1]
Put a comma at the end of every multi-line list declaration, including the last one. [Severity 1]
Write for(0..20) instead of for($i=0; $i<=20; $i++) [Severity 2]
for(0..20)
for($i=0; $i<=20; $i++)
Don't write long "if-elsif-elsif-elsif-elsif...else" chains. [Severity 3]
Don't write deeply nested loops and conditionals. [Severity 2]
Don't modify $_ in list functions [Severity 5]
$_
Write if($condition){ do_something() } instead of do_something() if $condition [Severity 2]
if($condition){ do_something() }
do_something() if $condition
Write if(! $condition) instead of unless($condition) [Severity 2]
if(! $condition)
unless($condition)
Don't write code after an unconditional die, exit, or next. [Severity 4]
die, exit, or next
Write while(! $condition) instead of until($condition) [Severity 2]
while(! $condition)
until($condition)
All POD should be after __END__ [Severity 1]
__END__
Organize your POD into the customary sections. [Severity 2]
Use functions from Carp instead of warn or die. [Severity 3]
warn
die
Discourage stuff like @files = `ls $directory` [Severity 3]
@files = `ls $directory`
Write open my $fh, q{<}, $filename; instead of open FH, q{<}, $filename; [Severity 5]
open my $fh, q{<}, $filename;
open FH, q{<}, $filename;
Use prompt() instead of -t [Severity 5]
Never write select($fh) [Severity 4]
select($fh)
Write while( $line = <> ){...} instead of for(<>){...} [Severity 4]
while( $line = <> ){...}
for(<>){...}
Write open $fh, q{<}, $filename; instead of open $fh, "<$filename"; [Severity 5]
open $fh, q{<}, $filename;
open $fh, "<$filename";
Write print {$FH} $foo, $bar; instead of print $FH $foo, $bar; [Severity 1]
print {$FH} $foo, $bar;
print $FH $foo, $bar;
Do not use format. [Severity 3]
format
Do not use tie. [Severity 2]
tie
Put source-control keywords in every file. [Severity 2]
Export symbols via @EXPORT_OK or %EXPORT_TAGS instead of @EXPORT. [Severity 3]
@EXPORT_OK
%EXPORT_TAGS
@EXPORT
Ban modules that aren't blessed by your shop. [Severity 5]
Put packages (especially subclasses) in separate files. [Severity 4]
Write require Module instead of require 'Module.pm' [Severity 5]
require Module
require 'Module.pm'
End each module with an explicitly 1; instead of some funky expression. [Severity 4]
1;
Always make the package explicit. [Severity 4]
package
Package declaration must match filename [Severity 5]
Give every module a $VERSION number. [Severity 2]
$VERSION
Don't use vague variable or subroutine names like 'last' or 'record'. [Severity 3]
Write sub my_function{} instead of sub MyFunction{} [Severity 1]
sub my_function{}
sub MyFunction{}
Write $my_variable = 42 instead of $MyVariable = 42 [Severity 1]
$my_variable = 42
$MyVariable = 42
Write @{ $array_ref } instead of @$array_ref [Severity 2]
@{ $array_ref }
@$array_ref
Capture variable used outside conditional [Severity 3]
Always use the /x modifier with regular expressions. [Severity 2]
/x
Always use the /m modifier with regular expressions. [Severity 3]
/m
Don't call functions with a leading ampersand sigil. [Severity 2]
Don't declare your own open function. [Severity 4]
open
Minimize complexity by factoring code into smaller subroutines. [Severity 3]
Return failure with bare return instead of return undef [Severity 5]
return
return undef
Don't write sub my_function (@@) {} [Severity 5]
sub my_function (@@) {}
Prevent access to private subs in other packages [Severity 3]
End every path through a subroutine with an explicit return statement. [Severity 4]
Prohibit various flavors of no strict [Severity 5]
no strict
Prohibit various flavors of no warnings [Severity 4]
no warnings
Don't turn off strict for large blocks of code [Severity 4]
Tests should all have labels [Severity 3]
Always use strict [Severity 5]
use strict
Always use warnings [Severity 4]
use warnings
Don't use constant $FOO => 15 [Severity 4]
use constant $FOO => 15
Write q{} instead of '' [Severity 2]
q{}
''
Write "\N{DELETE}" instead of "\x7F", etc. [Severity 2]
"\N{DELETE}"
"\x7F"
Always use single quotes for literal strings. [Severity 1]
Write oct(755) instead of 0755 [Severity 5]
oct(755)
0755
Use Readonly to give meaningful names for numeric literals. [Severity 2]
Don't mix numeric operators with string operands, or vice-versa. [Severity 3]
Write !$foo && $bar || $baz instead of not $foo && $bar or $baz [Severity 4]
!$foo && $bar || $baz
not $foo && $bar or $baz
Use q{} or qq{} instead of quotes for awkward-looking strings. [Severity 2]
qq{}
Don't use strings like v1.4 or 1.4.5 when including other modules. [Severity 3]
v1.4
1.4.5
Warns that you might have used single quotes when you really wanted double-quotes. [Severity 1]
Write 141_234_397.0145 instead of 141234397.0145 [Severity 2]
141_234_397.0145
141234397.0145
Write print <<'THE_END' or print <<"THE_END" [Severity 3]
print <<'THE_END'
print <<"THE_END"
Write <<'THE_END'; instead of <<'theEnd'; [Severity 1]
<<'THE_END';
<<'theEnd';
Do not write my $foo = $bar if $baz; [Severity 5]
my $foo = $bar if $baz;
Use my instead of local, except when you have to. [Severity 2]
my
local
Avoid $`, $&, $' and their English equivalents. [Severity 4]
$`
$&
$'
Eliminate globals declared with our or use vars [Severity 3]
our
use vars
Write $EVAL_ERROR instead of $@ [Severity 2]
$EVAL_ERROR
$@
Prevent access to private vars in other packages [Severity 3]
Write local $foo = $bar; instead of just local $foo; [Severity 3]
local $foo = $bar;
local $foo;
Write for my $element (@list) {...} instead of for $element (@list) {...}
for my $element (@list) {...}
for $element (@list) {...}
Negative array index should be used [Severity 4]
Jeffrey Ryan Thalhammer <thaljef@cpan.org>
Copyright (c) 2005-2006 Jeffrey Ryan Thalhammer. 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.
To install Perl::Critic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic
CPAN shell
perl -MCPAN -e shell install Perl::Critic
For more information on module installation, please visit the detailed CPAN module installation guide.