.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Perl::Critic::Violation 3pm" .TH Perl::Critic::Violation 3pm "2020-05-17" "perl v5.30.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 \s-1PPI\s0. 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 \&\s-1PBP\s0 (as an \s-1ARRAY\s0 ref), a reference to the \s-1PPI\s0 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 \s-1PBP.\s0 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(CW\*(C`line_number()\*(C'\fR, \&\f(CW\*(C`logical_line_number()\*(C'\fR, \f(CW\*(C`column_number()\*(C'\fR, \&\f(CW\*(C`visual_column_number()\*(C'\fR, and \f(CW\*(C`logical_filename()\*(C'\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 \&\*(L"tab_width [ \f(CW$width\fR ]\*(R" 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(CW\*(C`filename()\*(C'\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 \*(L"most\*(R" 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 \s-1POD.\s0 .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 \*(L"\s-1OVERLOADS\*(R"\s0 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 \*(L"\s-1OVERLOADS\*(R"\s0 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 \*(L"Plain Old Comments (Not!)\*(R" 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 \s-1LICENSE\s0 file included with this module.