.\" 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::Document 3pm" .TH Perl::Critic::Document 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::Document \- Caching wrapper around a PPI::Document. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 5 \& use PPI::Document; \& use Perl::Critic::Document; \& my $doc = PPI::Document\->new(\*(AqFoo.pm\*(Aq); \& $doc = Perl::Critic::Document\->new(\-source => $doc); \& ## Then use the instance just like a PPI::Document .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Perl::Critic does a lot of iterations over the \s-1PPI\s0 document tree via the \f(CW\*(C`PPI::Document::find()\*(C'\fR method. To save some time, this class pre-caches a lot of the common \f(CW\*(C`find()\*(C'\fR calls in a single traversal. Then, on subsequent requests we return the cached data. .PP This is implemented as a facade, where method calls are handed to the stored \f(CW\*(C`PPI::Document\*(C'\fR instance. .SH "CAVEATS" .IX Header "CAVEATS" This facade does not implement the overloaded operators from PPI::Document (that is, the \f(CW\*(C`use overload ...\*(C'\fR work). Therefore, users of this facade must not rely on that syntactic sugar. So, for example, instead of \f(CW\*(C`my $source = "$doc";\*(C'\fR you should write \f(CW\*(C`my $source = $doc\->content();\*(C'\fR .PP Perhaps there is a \s-1CPAN\s0 module out there which implements a facade better than we do here? .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(\-source => $source_code, \*(Aq\-filename\-override\*(Aq => $filename, \*(Aq\-program\-extensions\*(Aq => [program_extensions])""" 4 .el .IP "\f(CWnew(\-source => $source_code, \*(Aq\-filename\-override\*(Aq => $filename, \*(Aq\-program\-extensions\*(Aq => [program_extensions])\fR" 4 .IX Item "new(-source => $source_code, -filename-override => $filename, -program-extensions => [program_extensions])" Create a new instance referencing a PPI::Document instance. The \&\f(CW$source_code\fR can be the name of a file, a reference to a scalar containing actual source code, or a PPI::Document or PPI::Document::File. .Sp In the event that \f(CW$source_code\fR is a reference to a scalar containing actual source code or a PPI::Document, the resulting Perl::Critic::Document will not have a filename. This may cause Perl::Critic::Document to incorrectly classify the source code as a module or script. To avoid this problem, you can optionally set the \f(CW\*(C`\-filename\-override\*(C'\fR to force the Perl::Critic::Document to have a particular \&\f(CW$filename\fR. Do not use this option if \f(CW$source_code\fR is already the name of a file, or is a reference to a PPI::Document::File. .Sp The '\-program\-extensions' argument is optional, and is a reference to a list of strings and/or regular expressions. The strings will be made into regular expressions matching the end of a file name, and any document whose file name matches one of the regular expressions will be considered a program. .Sp If \-program\-extensions is not specified, or if it does not determine the document type, the document will be considered to be a program if the source has a shebang line or its file name (if any) matches \f(CW\*(C`m/ [.] PL \ez /smx\*(C'\fR. .SH "METHODS" .IX Header "METHODS" .ie n .IP """ppi_document()""" 4 .el .IP "\f(CWppi_document()\fR" 4 .IX Item "ppi_document()" Accessor for the wrapped PPI::Document instance. Note that altering this instance in any way can cause unpredictable failures in Perl::Critic's subsequent analysis because some caches may fall out of date. .ie n .IP """find($wanted)""" 4 .el .IP "\f(CWfind($wanted)\fR" 4 .IX Item "find($wanted)" .PD 0 .ie n .IP """find_first($wanted)""" 4 .el .IP "\f(CWfind_first($wanted)\fR" 4 .IX Item "find_first($wanted)" .ie n .IP """find_any($wanted)""" 4 .el .IP "\f(CWfind_any($wanted)\fR" 4 .IX Item "find_any($wanted)" .PD Caching wrappers around the \s-1PPI\s0 methods. If \f(CW$wanted\fR is a simple \s-1PPI\s0 class name, then the cache is employed. Otherwise we forward the call to the corresponding method of the \f(CW\*(C`PPI::Document\*(C'\fR instance. .ie n .IP """namespaces()""" 4 .el .IP "\f(CWnamespaces()\fR" 4 .IX Item "namespaces()" Returns a list of the namespaces (package names) in the document. .ie n .IP """subdocuments_for_namespace($namespace)""" 4 .el .IP "\f(CWsubdocuments_for_namespace($namespace)\fR" 4 .IX Item "subdocuments_for_namespace($namespace)" Returns a list of sub-documents containing the elements in the given namespace. For example, given that the current document is for the source .Sp .Vb 4 \& foo(); \& package Foo; \& package Bar; \& package Foo; .Ve .Sp this method will return two Perl::Critic::Documents for a parameter of \f(CW"Foo"\fR. For more, see \&\*(L"split_ppi_node_by_namespace\*(R" in PPIx::Utilities::Node. .ie n .IP """ppix_regexp_from_element($element)""" 4 .el .IP "\f(CWppix_regexp_from_element($element)\fR" 4 .IX Item "ppix_regexp_from_element($element)" Caching wrapper around \f(CW\*(C`PPIx::Regexp\->new($element)\*(C'\fR. If \&\f(CW$element\fR is a \f(CW\*(C`PPI::Element\*(C'\fR the cache is employed, otherwise it just returns the results of \f(CW\*(C`PPIx::Regexp\->new()\*(C'\fR. In either case, it returns \f(CW\*(C`undef\*(C'\fR unless the argument is something that PPIx::Regexp actually understands. .ie n .IP """element_is_in_lexical_scope_after_statement_containing( $inner, $outer )""" 4 .el .IP "\f(CWelement_is_in_lexical_scope_after_statement_containing( $inner, $outer )\fR" 4 .IX Item "element_is_in_lexical_scope_after_statement_containing( $inner, $outer )" Is the \f(CW$inner\fR element in lexical scope after the statement containing the \f(CW$outer\fR element? .Sp In the case where \f(CW$outer\fR is itself a scope-defining element, returns true if \f(CW$outer\fR contains \f(CW$inner\fR. In any other case, \f(CW$inner\fR must be after the last element of the statement containing \f(CW$outer\fR, and the innermost scope for \f(CW$outer\fR also contains \f(CW$inner\fR. .Sp This is not the same as asking whether \f(CW$inner\fR is visible from \&\f(CW$outer\fR. .ie n .IP """filename()""" 4 .el .IP "\f(CWfilename()\fR" 4 .IX Item "filename()" Returns the filename for the source code if applicable (PPI::Document::File) or \f(CW\*(C`undef\*(C'\fR otherwise (PPI::Document). .ie n .IP """isa( $classname )""" 4 .el .IP "\f(CWisa( $classname )\fR" 4 .IX Item "isa( $classname )" To be compatible with other modules that expect to get a PPI::Document, the Perl::Critic::Document class masquerades as the PPI::Document class. .ie n .IP """highest_explicit_perl_version()""" 4 .el .IP "\f(CWhighest_explicit_perl_version()\fR" 4 .IX Item "highest_explicit_perl_version()" Returns a version object for the highest Perl version requirement declared in the document via a \f(CW\*(C`use\*(C'\fR or \f(CW\*(C`require\*(C'\fR statement. Returns nothing if there is no version statement. .ie n .IP """uses_module($module_or_pragma_name)""" 4 .el .IP "\f(CWuses_module($module_or_pragma_name)\fR" 4 .IX Item "uses_module($module_or_pragma_name)" Answers whether there is a \f(CW\*(C`use\*(C'\fR, \f(CW\*(C`require\*(C'\fR, or \f(CW\*(C`no\*(C'\fR of the given name in this document. Note that there is no differentiation of modules vs. pragmata here. .ie n .IP """process_annotations()""" 4 .el .IP "\f(CWprocess_annotations()\fR" 4 .IX Item "process_annotations()" Causes this Document to scan itself and mark which lines & policies are disabled by the \f(CW"## no critic"\fR annotations. .ie n .IP """line_is_disabled_for_policy($line, $policy_object)""" 4 .el .IP "\f(CWline_is_disabled_for_policy($line, $policy_object)\fR" 4 .IX Item "line_is_disabled_for_policy($line, $policy_object)" Returns true if the given \f(CW$policy_object\fR or \f(CW$policy_name\fR has been disabled for at \f(CW$line\fR in this Document. Otherwise, returns false. .ie n .IP """add_annotation( $annotation )""" 4 .el .IP "\f(CWadd_annotation( $annotation )\fR" 4 .IX Item "add_annotation( $annotation )" Adds an \f(CW$annotation\fR object to this Document. .ie n .IP """annotations()""" 4 .el .IP "\f(CWannotations()\fR" 4 .IX Item "annotations()" Returns a list containing all the Perl::Critic::Annotations that were found in this Document. .ie n .IP """add_suppressed_violation($violation)""" 4 .el .IP "\f(CWadd_suppressed_violation($violation)\fR" 4 .IX Item "add_suppressed_violation($violation)" Informs this Document that a \f(CW$violation\fR was found but not reported because it fell on a line that had been suppressed by a \f(CW"## no critic"\fR annotation. Returns \f(CW$self\fR. .ie n .IP """suppressed_violations()""" 4 .el .IP "\f(CWsuppressed_violations()\fR" 4 .IX Item "suppressed_violations()" Returns a list of references to all the Perl::Critic::Violations that were found in this Document but were suppressed. .ie n .IP """is_program()""" 4 .el .IP "\f(CWis_program()\fR" 4 .IX Item "is_program()" Returns whether this document is considered to be a program. .ie n .IP """is_module()""" 4 .el .IP "\f(CWis_module()\fR" 4 .IX Item "is_module()" Returns whether this document is considered to be a Perl module. .SH "AUTHOR" .IX Header "AUTHOR" Chris Dolan .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2006\-2011 Chris Dolan. .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.