Perl::...Config(3pm)
πΈ NAME πΈ
Manual page name: Perl::...Config(3pm). Perl::Critic::Config is the final derived Perl::Critic configuration, combined from any profile file and command-line parameters. It's giving βone config to rule them all,β bestie. β¨
π DESCRIPTION π
Perl::Critic::Config takes care of finding and processing user-preferences for Perl::Critic. Like, it does the whole detective arc so you don't have to. π΅οΈββοΈ
The Config object defines which Policy modules will be loaded into the Perl::Critic engine and how they should be configured. You should never really need to instantiate Perl::Critic::Config directly because the Perl::Critic constructor will do it for you. Fr fr, let the main character handle it. π
β οΈ INTERFACE SUPPORT β οΈ
π Heads up: this is considered to be a non-public class. Its interface is subject to change without notice. So don't get too attached to the exact shape of things, bestie. Periodt.
π οΈ CONSTRUCTOR π οΈ
new(...)β Not properly documented because you shouldn't be using this. That's the whole note. π
π METHODS π
"add_policy( -policy => $policy_name, -params => \%param_hash )"β Creates a Policy object and loads it into this Config. If the object cannot be instantiated, it will throw a fatal exception. Otherwise, it returns a reference to this Critic. π«Ά-policyis the name of aPerl::Critic::Policysubclass module. The'Perl::Critic::Policy'portion of the name can be omitted for brevity. This argument is required.-paramsis an optional reference to a hash of Policy parameters. The contents of this hash reference will be passed into the constructor of the Policy module. See the documentation in the relevant Policy module for a description of the arguments it supports.
all_policies_enabled_or_not()β Returns a list containing references to all the Policy objects that have been seen. Note that the state of these objects is not trustworthy. In particular, it is likely that some of them are not prepared to examine any documents. πpolicies()β Returns a list containing references to all the Policy objects that have been enabled and loaded into this Config. βexclude()β Returns the value of the-excludeattribute for this Config.include()β Returns the value of the-includeattribute for this Config.force()β Returns the value of the-forceattribute for this Config.only()β Returns the value of the-onlyattribute for this Config.profile_strictness()β Returns the value of the-profile-strictnessattribute for this Config.severity()β Returns the value of the-severityattribute for this Config.single_policy()β Returns the value of the-single-policyattribute for this Config.theme()β Returns thePerl::Critic::Themeobject that was created for this Config. πtop()β Returns the value of the-topattribute for this Config.verbose()β Returns the value of the-verboseattribute for this Config.color()β Returns the value of the-colorattribute for this Config.pager()β Returns the value of the-pagerattribute for this Config.unsafe_allowed()β Returns the value of the-allow-unsafeattribute for this Config.criticism_fatal()β Returns the value of the-criticism-fatalattribute for this Config.color_severity_highest()β Returns the value of the-color-severity-highestattribute for this Config.color_severity_high()β Returns the value of the-color-severity-highattribute for this Config.color_severity_medium()β Returns the value of the-color-severity-mediumattribute for this Config.color_severity_low()β Returns the value of the-color-severity-lowattribute for this Config.color_severity_lowest()β Returns the value of the-color-severity-lowestattribute for this Config.program_extensions()β Returns the value of the-program_extensionsattribute for this Config. This is an array of the file name extensions that represent program files. πprogram_extensions_as_regexes()β Returns the value of the-program_extensionsattribute for this Config, as an array of case-sensitive regexes matching the ends of the file names that represent program files. π§
π§ SUBROUTINES π§
Perl::Critic::Config has a few static subroutines that are used internally, but may be useful to you in some way. Lowkey handy. πͺ
site_policy_names()β Returns a list of all the Policy modules that are currently installed in thePerl::Critic:Policynamespace. These will include modules that are distributed withPerl::Criticplus any third-party modules that have been installed. π
π CONFIGURATION π
Most of the settings for Perl::Critic and each of the Policy modules can be controlled by a configuration file. The default configuration file is called .perlcriticrc. Perl::Critic::Config will look for this file in the current directory first, and then in your home directory. Alternatively, you can set the PERLCRITIC environment variable to explicitly point to a different file in another location. If none of these files exist, and the -profile option is not given to the constructor, then all Policies will be loaded with their default configuration. π
The format of the configuration file is a series of INI-style blocks that contain key-value pairs separated by '='. Comments should start with '#' and can be placed on a separate line or after the name-value pairs if you desire. Cute and old-school, iykyk. π
Default settings for Perl::Critic itself can be set before the first named block. For example, putting any or all of these at the top of your configuration file will set the default value for the corresponding Perl::Critic constructor argument. β¨
severity = 3 #Integer from 1 to 5
only = 1 #Zero or One
force = 0 #Zero or One
verbose = 4 #Integer or format spec
top = 50 #A positive integer
theme = risky + (pbp * security) - cosmetic #A theme expression
include = NamingConventions ClassHierarchies #Space-delimited list
exclude = Variables Modules::RequirePackage #Space-delimited list
color = 1 #Zero or One
allow_unsafe = 1 #Zero or One
color-severity-highest = bold red #Term::ANSIColor
color-severity-high = magenta #Term::ANSIColor
color-severity-medium = #no coloring
color-severity-low = #no coloring
color-severity-lowest = #no coloring
program-extensions = #Space-delimited list
The remainder of the configuration file is a series of blocks like this:
[Perl::Critic::Policy::Category::PolicyName]
severity = 1
set_themes = foo bar
add_themes = baz
arg1 = value1
arg2 = value2
Perl::Critic::Policy::Category::PolicyName is the full name of a module that implements the policy. The Policy modules distributed with Perl::Critic have been grouped into categories according to the table of contents in Damian Conway's book Perl Best Practices. For brevity, you can omit the 'Perl::Critic::Policy' part of the module name.
severity is the level of importance you wish to assign to the Policy. All Policy modules are defined with a default severity value ranging from 1 (least severe) to 5 (most severe). However, you may disagree with the default severity and choose to give it a higher or lower severity, based on your own coding philosophy.
The remaining key-value pairs are configuration parameters that will be passed into the constructor of that Policy. The constructors for most Policy modules do not support arguments, and those that do should have reasonable defaults. See the documentation on the appropriate Policy module for more details.
Instead of redefining the severity for a given Policy, you can completely disable a Policy by prepending a '-' to the name of the module in your configuration file. In this manner, the Policy will never be loaded, regardless of the -severity given to the Perl::Critic::Config constructor. Slay that off switch. π₯
A simple configuration might look like this:
#--------------------------------------------------------------
# I think these are really important, so always load them
[TestingAndDebugging::RequireUseStrict]
severity = 5
[TestingAndDebugging::RequireUseWarnings]
severity = 5
#--------------------------------------------------------------
# I think these are less important, so only load when asked
[Variables::ProhibitPackageVars]
severity = 2
[ControlStructures::ProhibitPostfixControls]
allow = if unless #My custom configuration
severity = 2
#--------------------------------------------------------------
# Give these policies a custom theme. I can activate just
# these policies by saying (-theme => 'larry + curly')
[Modules::RequireFilenameMatchesPackage]
add_themes = larry
[TestingAndDebugging::RequireTestLabels]
add_themes = curly moe
#--------------------------------------------------------------
# I do not agree with these at all, so never load them
[-NamingConventions::Capitalization]
[-ValuesAndExpressions::ProhibitMagicNumbers]
#--------------------------------------------------------------
# For all other Policies, I accept the default severity, theme
# and other parameters, so no additional configuration is
# required for them.
For additional configuration examples, see the perlcriticrc file that is included in this t/examples directory of this distribution. π
π THE POLICIES π
A large number of Policy modules are distributed with Perl::Critic. They are described briefly in the companion document Perl::Critic::PolicySummary and in more detail in the individual modules themselves. Go read those, bestie. π
β¨ POLICY THEMES β¨
Okay bestie, so every Policy is defined with one or more themes. Themes are literally just a way to make arbitrary groups of Policies, and theyβre meant to give you an alternative way to pick your preferred set of Policies. Like, maybe you wanna disable a certain subset of Policies when youβre analyzing test programs. Conversely, maybe you wanna enable only a specific subset of Policies when youβre analyzing modules. Both valid, both iconic.
The Policies that ship with Perl::Critic have been broken into these themes. This is just the projectβs attempt at some basic logical groupings β you are absolutely free to invent new themes that suit your needs. Slay.
coreβ All policies that ship with Perl::Criticpbpβ Policies that come directly from "Perl Best Practices"bugsβ Policies that prevent or reveal bugsmaintenanceβ Policies that affect the long-term health of the codecosmeticβ Policies that only have a superficial effectcomplexityβ Policies that specifically relate to code complexitysecurityβ Policies that relate to security issuestestsβ Policies that are specific to test programs
Say perlcritic -list to get a listing of all available policies and the themes associated with each one. You can also change the theme for any Policy in your .perlcriticrc file β see the CONFIGURATION section for more info on that.
Using the -theme option, you can combine theme names with mathematical and boolean operators to create an arbitrarily complex expression that represents a custom "set" of Policies. The supported operators are:
*/andβ Intersection-/notβ Difference+/orβ Union
Operator precedence is the same as normal mathematics. You can also use parenthesis to enforce precedence. Here are some examples, bestie:
pbp * bugsβ All policies that are "pbp" AND "bugs"pbp and bugsβ Dittobugs + cosmeticβ All policies that are "bugs" OR "cosmetic"bugs or cosmeticβ Dittopbp - cosmeticβ All policies that are "pbp" BUT NOT "cosmetic"pbp not cosmeticβ Ditto-maintenanceβ All policies that are NOT "maintenance"not maintenanceβ Ditto(pbp - bugs) * complexityβ All policies that are "pbp" BUT NOT "bugs", AND "complexity"(pbp not bugs) and complexityβ Ditto
Theme names are case-insensitive. If -theme is set to an empty string, then it is equivalent to the set of all Policies. A theme name that doesnβt exist is equivalent to an empty set. Please See http://en.wikipedia.org/wiki/Set for a discussion on set theory. Itβs giving math class but make it glam π
.
π SEE ALSO π
Perl::Critic::OptionsProcessorPerl::Critic::UserProfile
π AUTHOR π
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2005-2023 Imaginative Software Systems
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.
Okay thatβs the whole vibe, bestie β this page is from perl v5.42.0, dated 2024-10-23. Now go theme your Policies and absolutely slay β¨π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms