.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Perl::Critic::Violation 3pm" .TH Perl::Critic::Violation 3pm 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Perl::Critic::Violation \- A violation of a Policy found in some source code. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use PPI; \& use Perl::Critic::Violation; \& \& my $elem = $doc\->child(0); # $doc is a PPI::Document object \& my $desc = \*(AqOffending code\*(Aq; # 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); .Ve .SH DESCRIPTION .IX Header "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 \f(CW\*(C`violations\*(C'\fR method of all Perl::Critic::Policy subclasses must return a list of these Perl::Critic::Violation objects. .SH "INTERFACE SUPPORT" .IX Header "INTERFACE SUPPORT" This is considered to be a public class. Any changes to its interface will go through a deprecation cycle. .SH CONSTRUCTOR .IX Header "CONSTRUCTOR" .ie n .IP """new( $description, $explanation, $element, $severity )""" 4 .el .IP "\f(CWnew( $description, $explanation, $element, $severity )\fR" 4 .IX Item "new( $description, $explanation, $element, $severity )" Returns a reference to a new \f(CW\*(C`Perl::Critic::Violation\*(C'\fR object. 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). .SH METHODS .IX Header "METHODS" .ie n .IP description() 4 .el .IP \f(CWdescription()\fR 4 .IX Item "description()" Returns a brief description of the specific violation. In other words, this value may change on a per violation basis. .ie n .IP explanation() 4 .el .IP \f(CWexplanation()\fR 4 .IX Item "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. .ie n .IP location() 4 .el .IP \f(CWlocation()\fR 4 .IX Item "location()" Don't use this method. Use the \f(CWline_number()\fR, \&\f(CWlogical_line_number()\fR, \f(CWcolumn_number()\fR, \&\f(CWvisual_column_number()\fR, and \f(CWlogical_filename()\fR methods instead. .Sp 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 in PPI::Element. .ie n .IP line_number() 4 .el .IP \f(CWline_number()\fR 4 .IX Item "line_number()" Returns the physical line number that the violation was found on. .ie n .IP logical_line_number() 4 .el .IP \f(CWlogical_line_number()\fR 4 .IX Item "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 \f(CW\*(C`#line\*(C'\fR directives in the code. .ie n .IP column_number() 4 .el .IP \f(CWcolumn_number()\fR 4 .IX Item "column_number()" Returns the physical column that the violation was found at. This means that hard tab characters count as a single character. .ie n .IP visual_column_number() 4 .el .IP \f(CWvisual_column_number()\fR 4 .IX Item "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 [ \f(CW$width\fR ]" in PPI::Document. .ie n .IP filename() 4 .el .IP \f(CWfilename()\fR 4 .IX Item "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. .ie n .IP logical_filename() 4 .el .IP \f(CWlogical_filename()\fR 4 .IX Item "logical_filename()" Returns the logical path to the file where the Violation occurred. This can differ from \f(CWfilename()\fR when there was a \f(CW\*(C`#line\*(C'\fR directive in the code. .ie n .IP severity() 4 .el .IP \f(CWseverity()\fR 4 .IX Item "severity()" Returns the severity of this Violation as an integer ranging from 1 to 5, where 5 is the "most" severe. .ie n .IP "sort_by_severity( @violation_objects )" 4 .el .IP "\f(CWsort_by_severity( @violation_objects )\fR" 4 .IX Item "sort_by_severity( @violation_objects )" If you need to sort Violations by severity, use this handy routine: .Sp .Vb 1 \& @sorted = Perl::Critic::Violation::sort_by_severity(@violations); .Ve .ie n .IP "sort_by_location( @violation_objects )" 4 .el .IP "\f(CWsort_by_location( @violation_objects )\fR" 4 .IX Item "sort_by_location( @violation_objects )" If you need to sort Violations by location, use this handy routine: .Sp .Vb 1 \& @sorted = Perl::Critic::Violation::sort_by_location(@violations); .Ve .ie n .IP diagnostics() 4 .el .IP \f(CWdiagnostics()\fR 4 .IX Item "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 \&\f(CW\*(C`DESCRIPTION\*(C'\fR section of the Policy module's POD. .ie n .IP policy() 4 .el .IP \f(CWpolicy()\fR 4 .IX Item "policy()" Returns the name of the Perl::Critic::Policy that created this Violation. .ie n .IP source() 4 .el .IP \f(CWsource()\fR 4 .IX Item "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. .ie n .IP element_class() 4 .el .IP \f(CWelement_class()\fR 4 .IX Item "element_class()" Returns the PPI::Element subclass of the code that caused this exception. .ie n .IP "set_format( $format )" 4 .el .IP "\f(CWset_format( $format )\fR" 4 .IX Item "set_format( $format )" Class method. Sets the format for all Violation objects when they are evaluated in string context. The default is \f(CW\*(Aq%d at line %l, column %c. %e\*(Aq\fR. See "OVERLOADS" for formatting options. .ie n .IP get_format() 4 .el .IP \f(CWget_format()\fR 4 .IX Item "get_format()" Class method. Returns the current format for all Violation objects when they are evaluated in string context. .ie n .IP to_string() 4 .el .IP \f(CWto_string()\fR 4 .IX Item "to_string()" Returns a string representation of this violation. The content of the string depends on the current value of the \f(CW$format\fR package variable. See "OVERLOADS" for the details. .SH OVERLOADS .IX Header "OVERLOADS" Perl::Critic::Violation overloads the \f(CW""\fR operator to produce neat little messages when evaluated in string context. .PP Formats are a combination of literal and escape characters similar to the way \f(CW\*(C`sprintf\*(C'\fR works. If you want to know the specific formatting capabilities, look at String::Format. Valid escape characters are: .PP .Vb 10 \& Escape Meaning \& \-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& %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 the Perl::Critic::Policy:: prefix \& %r The string of source code that caused the violation \& %C The class of the PPI::Element that caused the violation \& %s The severity level of the violation .Ve .PP Explanation of the \f(CW%F\fR, \f(CW%f\fR, \f(CW%G\fR, \f(CW%G\fR, \f(CW%l\fR, and \f(CW%L\fR formats: Using \f(CW\*(C`#line\*(C'\fR 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(CW%F\fR, \f(CW%f\fR, and \&\f(CW%l\fR will match the values of \f(CW%G\fR, \f(CW%g\fR, and \f(CW%L\fR, respectively. In the presence of a \f(CW\*(C`#line\*(C'\fR directive, the values of \f(CW%F\fR, \f(CW%f\fR, and \f(CW%l\fR will change to take that directive into account. The values of \f(CW%G\fR, \f(CW%g\fR, and \&\f(CW%L\fR are unaffected by those directives. .PP Here are some examples: .PP .Vb 2 \& Perl::Critic::Violation::set_format("%m at line %l, column %c.\en"); \& # looks like "Mixed case variable name at line 6, column 23." \& \& Perl::Critic::Violation::set_format("%m near \*(Aq%r\*(Aq\en"); \& # looks like "Mixed case variable name near \*(Aqmy $theGreatAnswer = 42;\*(Aq" \& \& Perl::Critic::Violation::set_format("%l:%c:%p\en"); \& # looks like "6:23:NamingConventions::Capitalization" \& \& Perl::Critic::Violation::set_format("%m at line %l. %e. \en%d\en"); \& # looks like "Mixed case variable name at line 6. See page 44 of PBP. \& Conway\*(Aqs 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." .Ve .SH AUTHOR .IX Header "AUTHOR" Jeffrey Ryan Thalhammer .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (c) 2005\-2011 Imaginative Software Systems. All rights reserved. .PP 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.