1PERLCRITIC(1) User Contributed Perl Documentation PERLCRITIC(1)
2
3
4
6 "perlcritic" - Command-line interface to critique Perl source
7
9 perlcritic [-12345 ⎪ -brutal ⎪ -cruel ⎪ -harsh ⎪ -stern ⎪ -gentle]
10 [-severity number ⎪ name] [-profile file ⎪ -noprofile]
11 [-top [ number ]] [-theme expression] [-include pattern]
12 [-exclude pattern] [-singlepolicy pattern] [-only ⎪ -noonly]
13 [-force ⎪ -noforce] [-verbose number ⎪ format] [-nocolor]
14 [-quiet] {FILE ⎪ DIRECTORY ⎪ STDIN}
15
16 perlcritic -doc pattern [...]
17
18 perlcritic {-list ⎪ -profileproto ⎪ -help ⎪ -man ⎪ -Version}
19
21 "perlcritic" is a Perl source code analyzer. It is the executable
22 front-end to the Perl::Critic engine, which attempts to identify awk‐
23 ward, hard to read, error-prone, or unconventional constructs in your
24 code. Most of the rules are based on Damian Conway's book Perl Best
25 Practices. However, "perlcritic" is not limited to enforcing PBP, and
26 it will even support rules that contradict Conway. All rules can eas‐
27 ily be configured or disabled to your liking.
28
29 If you want to integrate "perlcritic" with your build process, the
30 Test::Perl::Critic module provides a nice interface that is suitable
31 for test scripts. For ultimate convenience (at the expense of some
32 flexibility) see the criticism pragma.
33
34 Win32 and ActivePerl users can find PPM distributions of Perl::Critic
35 at <http://theoryx5.uwinnipeg.ca/ppms/>.
36
37 If you'd like to try Perl::Critic without installing anything, there is
38 a web-service available at <http://perlcritic.com>. The web-service
39 does not yet support all the configuration features that are available
40 in the native Perl::Critic API, but it should give you a good idea of
41 what it does. You can also invoke the perlcritic web-service from the
42 command-line by doing an HTTP-post, such as one of these:
43
44 $> POST http://perlcritic.com/perl/critic.pl < MyModule.pm
45 $> lwp-request -m POST http://perlcritic.com/perl/critic.pl < MyModule.pm
46 $> wget -q -O - --post-file=MyModule.pm http://perlcritic.com/perl/critic.pl
47
48 Please note that the perlcritic web-service is still alpha code. The
49 URL and interface to the service are subject to change.
50
52 Before getting into all the gory details, here are some basic usage
53 examples to help get you started.
54
55 #Report only most severe violations (severity = 5)
56 perlcritic YourModule.pm
57
58 #Same as above, but read input from STDIN
59 perlcritic
60
61 #Recursively process all Perl files beneath directory
62 perlcritic /some/directory
63
64 #Report slightly less severe violations too (severity >= 4)
65 perlcritic -4 YourModule.pm
66
67 #Same as above, but using named severity level
68 perlcritic -stern YourModule.pm
69
70 #Report all violations, regardless of severity (severity >= 1)
71 perlcritic -1 YourModule.pm
72
73 #Same as above, but using named severity level
74 perlcritic -brutal YourModule.pm
75
76 #Report only violations of things from "Perl Best Practices"
77 perlcritic -theme pbp YourModule.pm
78
79 #Report top 20 most severe violations (severity >= 1)
80 perlcritic -top YourModule.pm
81
82 #Report additional violations of Policies that match m/variables/ix
83 perlcritic -include variables YourModule.pm
84
86 The arguments are paths to the files you wish to analyze. You may
87 specify multiple files. If an argument is a directory, "perlcritic"
88 will analyze all Perl files below the directory. If no arguments are
89 specified, then input is read from STDIN.
90
92 Option names can be abbreviated to uniqueness and can be stated with
93 singe or double dashes, and option values can be separated from the
94 option name by a space or '=' (as with Getopt::Long). Option names are
95 also case-sensitive.
96
97 "-profile FILE"
98 Directs "perlcritic" to use a profile named by FILE rather than
99 looking for the default .perlcriticrc file in the current
100 directory or your home directory. See "CONFIGURATION" for more
101 information.
102
103 "-noprofile"
104 Directs "perlcritic" not to load any configuration file, thus
105 reverting to the default configuration for all Policies.
106
107 "-severity N"
108 Directs "perlcritic" to only apply Policies with a severity
109 greater than "N". Severity values are integers ranging from 1
110 (least severe) to 5 (most severe). The default is 5. For a
111 given "-profile", decreasing the "-severity" will usually pro‐
112 duce more violations. You can set the default value for this
113 option in your .perlcriticrc file. You can also redefine the
114 "severity" for any Policy in your .perlcriticrc file. See
115 "CONFIGURATION" for more information.
116
117 "-5 ⎪ -4 ⎪ -3 ⎪ -2 ⎪ -1"
118 These are numeric shortcuts for setting the "-severity" option.
119 For example, "-4" is equivalent to "-severity 4". If multiple
120 shortcuts are specified, then the most restrictive one wins.
121 If an explicit "-severity" option is also given, then all
122 shortcut options are silently ignored. NOTE: Be careful not to
123 put one of the number severity shortcut options immediately
124 after the "-top" flag or "perlcritic" will interpret it as the
125 number of violations to report.
126
127 "-severity NAME"
128 If it is difficult for you to remember whether severity "5" is
129 the most or least restrictive level, then you can use one of
130 these named values:
131
132 SEVERITY NAME ...is equivalent to... SEVERITY NUMBER
133 --------------------------------------------------------
134 -severity gentle -severity 5
135 -severity stern -severity 4
136 -severity harsh -severity 3
137 -severity cruel -severity 2
138 -severity brutal -severity 1
139
140 "-gentle ⎪ -stern ⎪ -harsh ⎪ -cruel ⎪ -brutal"
141 These are named shortcuts for setting the "-severity" option.
142 For example, "-cruel" is equivalent to "-severity 4". If mul‐
143 tiple shortcuts are specified, then the most restrictive one
144 wins. If an explicit "-severity" option is also given, then
145 all shortcut options are silently ignored.
146
147 "-theme RULE"
148 Directs "perlcritic" to apply only Policies with themes that
149 satisfy the "RULE". Themes are arbitrary names for groups of
150 related policies. You can combine theme names with boolean
151 operators to create an arbitrarily complex "RULE". For exam‐
152 ple, the following would apply only Policies that have a 'bugs'
153 AND 'pbp' theme:
154
155 $> perlcritic -theme='bugs && pbp' MyModule.pm
156
157 Unless the "-severity" option is explicitly given, setting
158 "-theme" silently causes the "-severity" to be set to 1. You
159 can set the default value for this option in your .perlcriticrc
160 file. See the "POLICY THEMES" section for more information
161 about themes.
162
163 "-include PATTERN"
164 Directs "perlcritic" to apply additional Policies that match
165 the regex "/PATTERN/imx". Use this option to temporarily over‐
166 ride your profile and/or the severity settings at the com‐
167 mand-line. For example:
168
169 perlcritic -include=layout my_file.pl
170
171 This would cause "perlcritic" to apply all the "CodeLayout::*"
172 policies even if they have a severity level that is less than
173 the default level of 5, or have been disabled in your .perl‐
174 criticrc file. You can specify multiple "-include" options and
175 you can use it in conjunction with the "-exclude" option. Note
176 that "-exclude" takes precedence over "-include" when a Policy
177 matches both patterns. You can set the default value for this
178 option in your .perlcriticrc file.
179
180 "-exclude PATTERN"
181 Directs "perlcritic" to not apply any Policy that matches the
182 regex "/PATTERN/imx". Use this option to temporarily override
183 your profile and/or the severity settings at the command-line.
184 For example:
185
186 perlcritic -exclude=strict my_file.pl
187
188 This would cause "perlcritic" to not apply the "RequireUseS‐
189 trict" and "ProhibitNoStrict" Policies even though they have
190 the highest severity level. You can specify multiple
191 "-exclude" options and you can use it in conjunction with the
192 "-include" option. Note that "-exclude" takes precedence over
193 "-include" when a Policy matches both patterns. You can set
194 the default value for this option in your .perlcriticrc file.
195
196 "-singlepolicy PATTERN"
197 Directs "perlcritic" to apply just one Policy module matching
198 the regex "/PATTERN/imx", and exclude all other Policies. This
199 option has precedence over the "-severity", "-theme",
200 "-include", "-exclude", and "-only" options. For example:
201
202 perlcritic -singlepolicy=nowarnings my_file.pl
203
204 This would cause "perlcritic" to apply just the "Prohibit‐
205 NoWarnings" Policy, regardless of the severity level setting.
206 No other Policies would be applied.
207
208 This is equivalent to what one might intend by...
209
210 perlcritic -exclude=. -include=nowarnings my_file.pl
211
212 ...but this won't work because the "-exclude" option overrides
213 the "-include" option.
214
215 The equivalent of this option can be accomplished by creating a
216 custom profile containing only the desired policy and then run‐
217 ning...
218
219 perlcritic -profile=customprofile -only my_file.pl
220
221 "-top [ N ]"
222 Directs "perlcritic" to report only the top "N" Policy viola‐
223 tions in each file, ranked by their severity. If "N" is not
224 specified, it defaults to 20. If the "-severity" option (or
225 one of the shortcuts) is not explicitly given, the "-top"
226 option implies that the minimum severity level is "1" (i.e.
227 "brutal"). Users can redefine the severity for any Policy in
228 their .perlcriticrc file. See "CONFIGURATION" for more infor‐
229 mation. You can set the default value for this option in your
230 .perlcriticrc file. NOTE: Be careful not to put one of the
231 severity shortcut options immediately after the "-top" flag or
232 "perlcritic" will interpret it as the number of violations to
233 report.
234
235 "-force"
236 Directs "perlcritic" to ignore the magical "## no critic"
237 pseudo-pragmas in the source code. See "BENDING THE RULES" for
238 more information. You can set the default value for this
239 option in your .perlcriticrc file.
240
241 "-verbose N ⎪ FORMAT"
242 Sets the verbosity level or format for reporting violations.
243 If given a number ("N"), "perlcritic" reports violations using
244 one of the predefined formats described below. If given a
245 string ("FORMAT"), it is interpreted to be an actual format
246 specification. If the "-verbose" option is not specified, it
247 defaults to either 4 or 5, depending on whether multiple files
248 were given as arguments to "perlcritic". You can set the
249 default value for this option in your .perlcriticrc file.
250
251 Verbosity Format Specification
252 ----------- -------------------------------------------------------------
253 1 "%f:%l:%c:%m\n",
254 2 "%f: (%l:%c) %m\n",
255 3 "%m at %f line %l\n",
256 4 "%m at line %l, column %c. %e. (Severity: %s)\n",
257 5 "%f: %m at line %l, column %c. %e. (Severity: %s)\n",
258 6 "%m at line %l, near '%r'. (Severity: %s)\n",
259 7 "%f: %m at line %l near '%r'. (Severity: %s)\n",
260 8 "[%p] %m at line %l, column %c. (Severity: %s)\n",
261 9 "[%p] %m at line %l, near '%r'. (Severity: %s)\n",
262 10 "%m at line %l, column %c.\n %p (Severity: %s)\n%d\n",
263 11 "%m at line %l, near '%r'.\n %p (Severity: %s)\n%d\n"
264
265 Formats are a combination of literal and escape characters sim‐
266 ilar to the way "sprintf" works. See String::Format for a full
267 explanation of the formatting capabilities. Valid escape char‐
268 acters are:
269
270 Escape Meaning
271 ------- ----------------------------------------------------------------
272 %c Column number where the violation occurred
273 %d Full diagnostic discussion of the violation
274 %e Explanation of violation or page numbers in PBP
275 %F Just the name of the file where the violation occurred.
276 %f Path to the file where the violation occurred.
277 %l Line number where the violation occurred
278 %m Brief description of the violation
279 %P Full name of the Policy module that created the violation
280 %p Name of the Policy without the Perl::Critic::Policy:: prefix
281 %r The string of source code that caused the violation
282 %s The severity level of the violation
283
284 The purpose of these formats is to provide some compatibility
285 with text editors that have an interface for parsing certain
286 kinds of input. See "EDITOR INTEGRATION" for more information
287 about that.
288
289 "-list" Displays a condensed listing of all the Perl::Critic::Policy
290 modules that are found on this machine. For each Policy, the
291 name, default severity and default themes are shown.
292
293 "-profileproto"
294 Displays an expanded listing of all the Perl::Critic::Policy
295 modules that are found on this machine. For each Policy, the
296 name, default severity and default themes are shown, as well as
297 the name of any additional parameters that the Policy supports.
298 The format is suitable as a prototype for your .perlcriticrc
299 file.
300
301 "-only" Directs perlcritic to apply only Policies that are explicitly
302 mentioned in your .perlcriticrc file. This is useful if you
303 want to use just a small subset of Policies without having to
304 disable all the others. You can set the default value for this
305 option in your .perlcriticrc file.
306
307 "-count"
308 "-C" Display only the number of violations for each file. Use this
309 feature to get a quick handle on where a large pile of code
310 might need the most attention.
311
312 "-Safari"
313 Report "Perl Best Practice" citations as section numbers from
314 <http://safari.oreilly.com> instead of page numbers from the
315 actual book. NOTE: This feature is not implemented yet.
316
317 "-nocolor"
318 By default, Severity 5 and 4 are colored red and yellow,
319 respectively. Colorization only happens if STDOUT is a tty and
320 Term::ANSIColor is installed. And it only works on non-windows
321 environments. Set this switch to disable color.
322
323 "-doc PATTERN"
324 Displays the perldoc for all Perl::Critic::Policy modules that
325 match "m/PATTERN/imx". Since Policy modules tend to have
326 rather long names, this just provides a more convenient way to
327 say something like: ""perldoc Perl::Critic::Policy::ValuesAnd‐
328 Expressions::RequireUpperCaseHeredocTerminator"" at the command
329 prompt.
330
331 "-quiet"
332 Suppress the "source OK" message when no violations are found.
333
334 "-help"
335 "-?"
336 "-H" Displays a brief summary of options and exits.
337
338 "-man" Displays the complete "perlcritic" manual and exits.
339
340 "-Version"
341 "-V" Displays the version number of "perlcritic" and exits.
342
344 Most of the settings for Perl::Critic and each of the Policy modules
345 can be controlled by a configuration file. The default configuration
346 file is called .perlcriticrc. "perlcritic" will look for this file in
347 the current directory first, and then in your home directory. Alterna‐
348 tively, you can set the "PERLCRITIC" environment variable to explicitly
349 point to a different file in another location. If none of these files
350 exist, and the "-profile" option is not given on the command-line, then
351 all Policies will be loaded with their default configuration.
352
353 The format of the configuration file is a series of INI-style blocks
354 that contain key-value pairs separated by "=". Comments should start
355 with "#" and can be placed on a separate line or after the name-value
356 pairs if you desire.
357
358 Default settings for perlcritic itself can be set before the first
359 named block. For example, putting any or all of these at the top of
360 your .perlcriticrc file will set the default value for the correspond‐
361 ing command-line argument.
362
363 severity = 3 #Integer or named level
364 only = 1 #Zero or One
365 force = 0 #Zero or One
366 verbose = 4 #Integer or format spec
367 top = 50 #A positive integer
368 theme = (pbp + security) * bugs #A theme expression
369 include = NamingConventions ClassHierarchies #Space-delimited list
370 exclude = Variables Modules::RequirePackage #Space-delimited list
371
372 The remainder of the configuration file is a series of blocks like
373 this:
374
375 [Perl::Critic::Policy::Category::PolicyName]
376 severity = 1
377 set_themes = foo bar
378 add_themes = baz
379 arg1 = value1
380 arg2 = value2
381
382 "Perl::Critic::Policy::Category::PolicyName" is the full name of a mod‐
383 ule that implements the policy. The Policy modules distributed with
384 Perl::Critic have been grouped into categories according to the table
385 of contents in Damian Conway's book Perl Best Practices. For brevity,
386 you can omit the 'Perl::Critic::Policy' part of the module name.
387
388 "severity" is the level of importance you wish to assign to the Policy.
389 All Policy modules are defined with a default severity value ranging
390 from 1 (least severe) to 5 (most severe). However, you may disagree
391 with the default severity and choose to give it a higher or lower
392 severity, based on your own coding philosophy. You can set the "sever‐
393 ity" to an integer from 1 to 5, or use one of the equivalent names:
394
395 SEVERITY NAME ...is equivalent to... SEVERITY NUMBER
396 ----------------------------------------------------
397 gentle 5
398 stern 4
399 harsh 3
400 cruel 2
401 brutal 1
402
403 "set_themes" sets the theme for the Policy and overrides it's default
404 theme. The argument is a string of one or more whitespace-delimited
405 alphanumeric words. Themes are case-insensitive. See "POLICY THEMES"
406 for more information.
407
408 "add_themes" appends to the default themes for this Policy. The argu‐
409 ment is a string of one or more whitespace-delimited words. Themes are
410 case-insensitive. See "POLICY THEMES" for more information.
411
412 The remaining key-value pairs are configuration parameters that will be
413 passed into the constructor of that Policy. The constructors for most
414 Policy modules do not support arguments, and those that do should have
415 reasonable defaults. See the documentation on the appropriate Policy
416 module for more details.
417
418 Instead of redefining the severity for a given Policy, you can com‐
419 pletely disable a Policy by prepending a '-' to the name of the module
420 in your configuration file. In this manner, the Policy will never be
421 loaded, regardless of the "-severity" given on the command line.
422
423 A simple configuration might look like this:
424
425 #--------------------------------------------------------------
426 # I think these are really important, so always load them
427
428 [TestingAndDebugging::RequireUseStrict]
429 severity = 5
430
431 [TestingAndDebugging::RequireUseWarnings]
432 severity = 5
433
434 #--------------------------------------------------------------
435 # I think these are less important, so only load when asked
436
437 [Variables::ProhibitPackageVars]
438 severity = 2
439
440 [ControlStructures::ProhibitPostfixControls]
441 allow = if unless # My custom configuration
442 severity = cruel # Same as "severity = 2"
443
444 #--------------------------------------------------------------
445 # Give these policies a custom theme. I can activate just
446 # these policies by saying "perlcritic -theme 'larry ⎪⎪ curly'"
447
448 [Modules::RequireFilenameMatchesPackage]
449 add_themes = larry
450
451 [TestingAndDebugging::RequireTestLables]
452 add_themes = curly moe
453
454 #--------------------------------------------------------------
455 # I do not agree with these at all, so never load them
456
457 [-NamingConventions::ProhibitMixedCaseVars]
458 [-NamingConventions::ProhibitMixedCaseSubs]
459
460 #--------------------------------------------------------------
461 # For all other Policies, I accept the default severity,
462 # so no additional configuration is required for them.
463
464 For additional configuration examples, see the perlcriticrc file that
465 is included in this examples directory of this distribution.
466
467 Damian Conway's own Perl::Critic configuration is also included in this
468 distribution as examples/perlcriticrc-conway.
469
471 A large number of Policy modules are distributed with Perl::Critic.
472 They are described briefly in the companion document Perl::Critic::Pol‐
473 icySummary and in more detail in the individual modules themselves.
474 Say ""perlcritic -doc PATTERN"" to see the perldoc for all Policy mod‐
475 ules that match the regex "m/PATTERN/imx"
476
478 Each Policy is defined with one or more "themes". Themes can be used
479 to create arbitrary groups of Policies. They are intended to provide
480 an alternative mechanism for selecting your preferred set of Policies.
481 For example, you may wish disable a certain set of Policies when ana‐
482 lyzing test scripts. Conversely, you may wish to enable only a spe‐
483 cific subset of Policies when analyzing modules.
484
485 The Policies that ship with Perl::Critic are have been divided into the
486 following themes. This is just our attempt to provide some basic logi‐
487 cal groupings. You are free to invent new themes that suit your needs.
488
489 THEME DESCRIPTION
490 --------------------------------------------------------------------------
491 core All policies that ship with Perl::Critic
492 pbp Policies that come directly from "Perl Best Practices"
493 bugs Policies that that prevent or reveal bugs
494 maintenance Policies that affect the long-term health of the code
495 cosmetic Policies that only have a superficial effect
496 complexity Policies that specificaly relate to code complexity
497 security Policies that relate to security issues
498 tests Policies that are specific to test scripts
499
500 Say "perlcritic -list" to get a listing of all available policies and
501 the themes that are associated with each one. You can also change the
502 theme for any Policy in your .perlcriticrc file. See the "CONFIGURA‐
503 TION" section for more information about that.
504
505 Using the "-theme" command-line option, you can create an arbitrarily
506 complex rule that determines which Policies to apply. Precedence is
507 the same as regular Perl code, and you can use parens to enforce prece‐
508 dence as well. Supported operators are:
509
510 Operator Altertative Example
511 ----------------------------------------------------------------------------
512 && and 'pbp && core'
513 ⎪⎪ or 'pbp ⎪⎪ (bugs && security)'
514 ! not 'pbp && ! (portability ⎪⎪ complexity)'
515
516 Theme names are case-insensitive. If the "-theme" is set to an empty
517 string, then it evaluates as true all Policies.
518
520 Perl::Critic takes a hard-line approach to your code: either you comply
521 or you don't. In the real world, it is not always practical (or even
522 possible) to fully comply with coding standards. In such cases, it is
523 wise to show that you are knowingly violating the standards and that
524 you have a Damn Good Reason (DGR) for doing so.
525
526 To help with those situations, you can direct Perl::Critic to ignore
527 certain lines or blocks of code by using pseudo-pragmas:
528
529 require 'LegacyLibaray1.pl'; ## no critic
530 require 'LegacyLibrary2.pl'; ## no critic
531
532 for my $element (@list) {
533
534 ## no critic
535
536 $foo = ""; #Violates 'ProhibitEmptyQuotes'
537 $barf = bar() if $foo; #Violates 'ProhibitPostfixControls'
538 #Some more evil code...
539
540 ## use critic
541
542 #Some good code...
543 do_something($_);
544 }
545
546 The "## no critic" comments direct Perl::Critic to ignore the remaining
547 lines of code until the end of the current block, or until a ""## use
548 critic"" comment is found (whichever comes first). If the "## no
549 critic" comment is on the same line as a code statement, then only that
550 line of code is overlooked. To direct perlcritic to ignore the "## no
551 critic" comments, use the "-force" option.
552
553 A bare "## no critic" comment disables all the active Policies. If you
554 wish to disable only specific Policies, add a list of Policy names as
555 arguments just as you would for the "no strict" or "no warnings"
556 pragma. For example, this would disable the "ProhibitEmptyQuotes" and
557 "ProhibitPostfixControls" policies until the end of the block or until
558 the next "## use critic" comment (whichever comes first):
559
560 ## no critic (EmptyQuotes, PostfixControls);
561
562 # Now exempt from ValuesAndExpressions::ProhibitEmptyQuotes
563 $foo = "";
564
565 # Now exempt ControlStructures::ProhibitPostfixControls
566 $barf = bar() if $foo;
567
568 # Still subject to ValuesAndExpression::RequireNumberSeparators
569 $long_int = 10000000000;
570
571 Since the Policy names are matched against the "## no critic" arguments
572 as regular expressions, you can abbreviate the Policy names or disable
573 an entire family of Policies in one shot like this:
574
575 ## no critic (NamingConventions)
576
577 # Now exempt from NamingConventions::ProhibitMixedCaseVars
578 my $camelHumpVar = 'foo';
579
580 # Now exempt from NamingConventions::ProhibitMixedCaseSubs
581 sub camelHumpSub {}
582
583 The argument list must be enclosed in parens and must contain one or
584 more comma-separated barewords (i.e. don't use quotes). The "## no
585 critic" pragmas can be nested, and Policies named by an inner pragma
586 will be disabled along with those already disabled an outer pragma.
587
588 Some Policies like "Subroutines::ProhibitExcessComplexity" apply to an
589 entire block of code. In those cases, "## no critic" must appear on
590 the line where the violation is reported. For example:
591
592 sub complicated_function { ## no critic (ProhibitExcessComplexity)
593 # Your code here...
594 }
595
596 Some Policies like "Documentation::RequirePodSections" apply to the
597 entire document, in which case violations are reported at line 1. But
598 if the file requires a shebang line, it is impossible to put "## no
599 critic" on the first line of the file. This is a known limitation and
600 it will be addressed in a future release. As a workaround, you can
601 disable the affected policies at the command-line or in your .perl‐
602 criticrc file. But beware that this will affect the analysis of all
603 files.
604
605 Use this feature wisely. "## no critic" should be used in the smallest
606 possible scope, or only on individual lines of code. And you should
607 always be as specific as possible about which policies you want to dis‐
608 able (i.e. never use a bare "## no critic"). If Perl::Critic complains
609 about your code, try and find a compliant solution before resorting to
610 this feature.
611
613 Perl-Critic is evolving rapidly. As such, some of the interfaces have
614 changed in ways that are not backward-compatible. If you have been
615 using an older version of Perl-Critic and/or you have been developing
616 custom Policy modules, please read this section carefully.
617
618 VERSION 0.23
619
620 In version 0.23, the syntax for theme rules changed. The mathematical
621 operators ( "*", "+", "-" ) are no longer supported. You must use log‐
622 ical operators instead ( "&&", "!", "⎪⎪" ). However the meanings of
623 these operators is effectively the same. See "POLICY THEMES" for more
624 details.
625
626 VERSION 0.21
627
628 In version 0.21, we introduced the concept of policy "themes". All you
629 existing custom Policies should still be compatible. But to take
630 advantage of the theme feature, you should add a "default_themes"
631 method to your custom Policy modules. See Perl::Critic::DEVELOPER for
632 an up-to-date guide on creating Policy modules.
633
634 VERSION 0.16
635
636 Starting in version 0.16, you can add a list Policy names as arguments
637 to the "## no critic" pseudo-pragma. This feature allows you to dis‐
638 able specific policies. So if you have been in the habit of adding
639 additional words after "no critic", then those words might cause unex‐
640 pected results. If you want to append other stuff to the "## no
641 critic" comment, then terminate the pseudo-pragma with a semi-colon,
642 and then start another comment. For example:
643
644 #This may not work as expected.
645 $email = 'foo@bar.com'; ## no critic for literal '@'
646
647 #This will work.
648 $email = 'foo@bar.com'; ## no critic; #for literal '@'
649
650 #This is even better.
651 $email = 'foo@bar.com'; ## no critic (RequireInterpolation);
652
653 VERSION 0.14
654
655 Starting in version 0.14, the interface to Perl::Critic::Violation
656 changed. This will also break any custom Policy modules that you might
657 have written for earlier modules. See Perl::Critic::DEVELOPER for an
658 up-to-date guide on creating Policy modules.
659
660 The notion of "priority" was also replaced with "severity" in version
661 0.14. Consequently, the default behavior of Perl::Critic is to only
662 load the most "severe" Policy modules, rather than loading all of them.
663 This decision was based on user-feedback suggesting that Perl-Critic
664 should be less "critical" for new users, and should steer them toward
665 gradually increasing the strictness as they adopt better coding prac‐
666 tices.
667
668 VERSION 0.11
669
670 Starting in version 0.11, the internal mechanics of Perl-Critic were
671 rewritten so that only one traversal of the PPI document tree is
672 required. Unfortunately, this will break any custom Policy modules
673 that you might have written for earlier versions. Converting your
674 policies to work with the new version is pretty easy and actually
675 results in cleaner code. See Perl::Critic::DEVELOPER for an up-to-date
676 guide on creating Policy modules.
677
679 For ease-of-use, "perlcritic" can be integrated with your favorite text
680 editor. The output-formatting capabilities of "perlcritic" are specif‐
681 ically intended for use with the "grep" or "compile" modes available in
682 editors like "emacs" and "vim". In these modes, you can run an arbi‐
683 trary command and the editor will parse the output into an interactive
684 buffer that you can click on and jump to the relevant line of code.
685
686 The Perl::Critic team thanks everyone who has helped integrate Perl-
687 Critic with their favorite editor. Your contributions in particular
688 have made Perl-Critic a convenient and user-friendly tool for Perl
689 developers of all stripes. We sincerely appreciate your hard work.
690
691 EMACS
692
693 Joshua ben Jore has authored a minor-mode for emacs that allows you to
694 run perlcritic on the current region or buffer. You can run it on
695 demand, or configure it to run automatically when you save the buffer.
696 The output appears in a hot-linked compiler buffer. The code and
697 installation instructions can be found in the extras directory inside
698 this distribution.
699
700 VIM
701
702 Scott Peshak has published perlchecker.vim, which is available at
703 <http://www.vim.org/scripts/script.php?script_id=1731>.
704
705 gVIM
706
707 Fritz Mehner recently added support for "perlcritic" to his fantastic
708 gVIM plugin. In addition to providing a very Perlish IDE, Fritz's
709 plugin enables one-click access to "perlcritic" and many other very
710 useful utilities. And all is seamlessly integrated into the editor.
711 See <http://lug.fh-swf.de/vim/vim-perl/screenshots-en.html> for com‐
712 plete details.
713
714 EPIC
715
716 EPIC is an open source Perl IDE based on the Eclipse platform. Fea‐
717 tures supported are syntax highlighting, on-the-fly syntax check, con‐
718 tent assist, perldoc support, source formatter, templating support and
719 a Perl debugger. Go to <http://e-p-i-c.sourceforge.net> for more
720 information about EPIC.
721
722 The EPIC team is currently working on integration with Perl::Critic.
723 In the meantime, you can use the criticism pragma and EPIC will high‐
724 light violations whenever it does a syntax check on your code. I
725 haven't tried this myself, but other folks say it works.
726
727 BBEdit
728
729 Josh Clark has produced an excellent Perl-Critic plugin for BBEdit. See
730 <http://beta.bigmedium.com/projects/bbedit-perl-critic/index.shtml> for
731 more information. Apple users rejoice!
732
734 If "perlcritic" has any errors itself, exits with status == 1. If
735 there are no errors, but "perlcritic" finds Policy violations in your
736 source code, exits with status == 2. If there were no errors and no
737 violations were found, exits with status == 0.
738
740 Coding standards are deeply personal and highly subjective. The
741 goal of Perl::Critic is to help you write code that conforms with a
742 set of best practices. Our primary goal is not to dictate what
743 those practices are, but rather, to implement the practices
744 discovered by others. Ultimately, you make the rules --
745 Perl::Critic is merely a tool for encouraging consistency. If there
746 is a policy that you think is important or that we have overlooked,
747 we would be very grateful for contributions, or you can simply load
748 your own private set of policies into Perl::Critic.
749
751 The modular design of Perl::Critic is intended to facilitate the addi‐
752 tion of new Policies. You'll need to have some understanding of PPI,
753 but most Policy modules are pretty straightforward and only require
754 about 20 lines of code. Please see the Perl::Critic::DEVELOPER file
755 included in this distribution for a step-by-step demonstration of how
756 to create new Policy modules.
757
758 If you develop any new Policy modules, feel free to send them to
759 "<thaljef@cpan.org>" and I'll be happy to put them into the
760 Perl::Critic distribution. Or if you would like to work on the
761 Perl::Critic project directly, check out our repository at
762 <http://perlcritic.tigris.org>. To subscribe to our mailing list, send
763 a message to "<dev-subscribe@perlcritic.tigris.org>".
764
765 The Perl::Critic team is also available for hire. If your organization
766 has its own coding standards, we can create custom Policies to enforce
767 your local guidelines. Or if your code base is prone to a particular
768 defect pattern, we can design Policies that will help you catch those
769 costly defects before they go into production. To discuss your needs
770 with the Perl::Critic team, just contact "<thaljef@cpan.org>".
771
773 Scrutinizing Perl code is hard for humans, let alone machines. If you
774 find any bugs, particularly false-positives or false-negatives from a
775 Perl::Critic::Policy, please submit them to
776 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Perl-Critic>. Thanks.
777
779 Adam Kennedy - For creating PPI, the heart and soul of Perl::Critic.
780
781 Damian Conway - For writing Perl Best Practices, finally :)
782
783 Chris Dolan - For contributing the best features and Policy modules.
784
785 Andy Lester - Wise sage and master of all-things-testing.
786
787 Elliot Shank - The self-proclaimed quality freak.
788
789 Giuseppe Maxia - For all the great ideas and positive encouragement.
790
791 and Sharon, my wife - For putting up with my all-night code sessions.
792
794 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
795
797 Copyright (c) 2005-2007 Jeffrey Ryan Thalhammer. All rights reserved.
798
799 This program is free software; you can redistribute it and/or modify it
800 under the same terms as Perl itself. The full text of this license can
801 be found in the LICENSE file included with this module.
802
803
804
805perl v5.8.8 2007-03-20 PERLCRITIC(1)