Perl::...olation(3pm)
π NAME π
okay so this is the Perl::...olation(3pm) manual page (User Contributed Perl Documentation), and it's literally all about Perl::Critic::Violation β a violation of a Policy found in some source code. periodt. β¨
β¨ SYNOPSIS β¨
Bestie, here's the setup, no cap:
use PPI;
use Perl::Critic::Violation;
my $elem = $doc->child(0); # $doc is a PPI::Document object
my $desc = 'Offending code'; # Describe the violation
my $expl = [1,45,67]; # Page numbers from PBP
my $sev = 5; # Severity level of this violation
my $vio = Perl::Critic::Violation->new($desc, $expl, $node, $sev);
πΈ DESCRIPTION πΈ
Perl::Critic::Violation is the generic representation of an individual Policy violation. Its primary purpose is to provide an abstraction layer so that clients of Perl::Critic don't have to know anything about PPI. The "violations" method of all Perl::Critic::Policy subclasses must return a list of these Perl::Critic::Violation objects. slay. π«Ά
π INTERFACE SUPPORT π
This is considered to be a public class. Any changes to its interface will go through a deprecation cycle. So like, respect the API, bestie. π
π CONSTRUCTOR π
new( $description, $explanation, $element, $severity )β Returns a reference to a newPerl::Critic::Violationobject. The arguments are a description of the violation (as string), an explanation for the policy (as string) or a series of page numbers in PBP (as an ARRAY ref), a reference to the PPI element that caused the violation, and the severity of the violation (as an integer). π¦
π METHODS π
description()β Returns a brief description of the specific violation. In other words, this value may change on a per violation basis. πexplanation()β Returns an explanation of the policy as a string or as reference to an array of page numbers in PBP. This value will generally not change based upon the specific code violating the policy. πΈlocation()β Don't use this method. Use theline_number(),logical_line_number(),column_number(),visual_column_number(), andlogical_filename()methods instead. Returns a five-element array reference containing the line and real & virtual column and logical numbers and logical file name where this Violation occurred, as inPPI::Element. πline_number()β Returns the physical line number that the violation was found on. βlogical_line_number()β Returns the logical line number that the violation was found on. This can differ from the physical line number when there were"#line"directives in the code. π¦column_number()β Returns the physical column that the violation was found at. This means that hard tab characters count as a single character. πvisual_column_number()β Returns the column that the violation was found at, as it would appear if hard tab characters were expanded, based upon the value of"tab_width [ $width ]"inPPI::Document. β¨filename()β Returns the path to the file where this Violation occurred. In some cases, the path may be undefined because the source code was not read directly from a file. πlogical_filename()β Returns the logical path to the file where the Violation occurred. This can differ fromfilename()when there was a"#line"directive in the code. πseverity()β Returns the severity of this Violation as an integer ranging from 1 to 5, where 5 is the "most" severe. π₯sort_by_severity( @violation_objects )β If you need to sort Violations by severity, use this handy routine:@sorted = Perl::Critic::Violation::sort_by_severity(@violations);πsort_by_location( @violation_objects )β If you need to sort Violations by location, use this handy routine:@sorted = Perl::Critic::Violation::sort_by_location(@violations);π«diagnostics()β Returns a formatted string containing a full discussion of the motivation for and details of the Policy module that created this Violation. This information is automatically extracted from the"DESCRIPTION"section of the Policy module's POD. πpolicy()β Returns the name of thePerl::Critic::Policythat created this Violation. π§source()β Returns the string of source code that caused this exception. If the code spans multiple lines (e.g. multi-line statements, subroutines or other blocks), then only the line containing the violation will be returned. πelement_class()β Returns thePPI::Elementsubclass of the code that caused this exception. πset_format( $format )β Class method. Sets the format for all Violation objects when they are evaluated in string context. The default is'%d at line %l, column %c. %e'. See"OVERLOADS"for formatting options. πget_format()β Class method. Returns the current format for all Violation objects when they are evaluated in string context. πto_string()β Returns a string representation of this violation. The content of the string depends on the current value of the$formatpackage variable. See"OVERLOADS"for the details. π
π₯ OVERLOADS π₯
Perl::Critic::Violation overloads the "" operator to produce neat little messages when evaluated in string context. So like, when you stringify a violation, it serves looks. π
Formats are a combination of literal and escape characters similar to the way sprintf works. If you want to know the specific formatting capabilities, look at String::Format. Valid escape characters are:
%cβ Column number where the violation occurred%dβ Full diagnostic discussion of the violation (DESCRIPTION in POD)%eβ Explanation of violation or page numbers in PBP%Fβ Just the name of the logical file where the violation occurred.%fβ Path to the logical file where the violation occurred.%Gβ Just the name of the physical file where the violation occurred.%gβ Path to the physical file where the violation occurred.%lβ Logical line number where the violation occurred%Lβ Physical line number where the violation occurred%mβ Brief description of the violation%Pβ Full name of the Policy module that created the violation%pβ Name of the Policy without thePerl::Critic::Policy::prefix%rβ The string of source code that caused the violation%Cβ The class of thePPI::Elementthat caused the violation%sβ The severity level of the violation
Explanation of the %F, %f, %G, %G, %l, and %L formats: Using #line directives, you can affect what perl thinks the current line number and file name are; see "Plain Old Comments (Not!)" in perlsyn for the details. Under normal circumstances, the values of %F, %f, and %l will match the values of %G, %g, and %L, respectively. In the presence of a #line directive, the values of %F, %f, and %l will change to take that directive into account. The values of %G, %g, and %L are unaffected by those directives. iykyk. π
Here are some examples:
Perl::Critic::Violation::set_format("%m at line %l, column %c.\n");
# looks like "Mixed case variable name at line 6, column 23."
Perl::Critic::Violation::set_format("%m near '%r'\n");
# looks like "Mixed case variable name near 'my $theGreatAnswer = 42;'"
Perl::Critic::Violation::set_format("%l:%c:%p\n");
# looks like "6:23:NamingConventions::Capitalization"
Perl::Critic::Violation::set_format("%m at line %l. %e. \n%d\n");
# looks like "Mixed case variable name at line 6. See page 44 of PBP.
Conway's recommended naming convention is to use lower-case words
separated by underscores. Well-recognized acronyms can be in ALL
CAPS, but must be separated by underscores from other parts of the
name."
π AUTHOR π
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> π«Ά
π COPYRIGHT π
Copyright (c) 2005-2023 Imaginative Software Systems. 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. π
that's the whole page, bestie β from perl v5.42.0, dated 2024-10-23, on the Perl::...olation(3pm) manual page. πβ¨
π¦ 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