.\" -*- 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::Document 3pm" .TH Perl::Critic::Document 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::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 PPI document tree via the \f(CWPPI::Document::find()\fR method. To save some time, this class pre-caches a lot of the common \f(CWfind()\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 CPAN 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 PPI methods. If \f(CW$wanted\fR is a simple PPI 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 "split_ppi_node_by_namespace" 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 LICENSE file included with this module.