Perl::Critic::Document - Caching wrapper around a PPI::Document.
use PPI::Document; use Perl::Critic::Document; my $doc = PPI::Document->new('Foo.pm'); $doc = Perl::Critic::Document->new($doc); ## Then use the instance just like a PPI::Document
Perl::Critic does a lot of iterations over the PPI document tree via the PPI::Document::find() method. To save some time, this class pre-caches a lot of the common find() calls in a single traversal. Then, on subsequent requests we return the cached data.
PPI::Document::find()
find()
This is implemented as a facade, where method calls are handed to the stored PPI::Document instance.
PPI::Document
This facade does not implement the overloaded operators from PPI::Document (that is, the use overload ... work). Therefore, users of this facade must not rely on that syntactic sugar. So, for example, instead of my $source = "$doc"; you should write my $source = $doc-content();>
use overload ...
my $source = "$doc";
my $source = $doc-
Perhaps there is a CPAN module out there which implements a facade better than we do here?
This is considered to be a public class. Any changes to its interface will go through a deprecation cycle.
new($source_code)
Create a new instance referencing a PPI::Document instance. The $source_code can be the name of a file, a reference to a scalar containing actual source code, or a PPI::Document or PPI::Document::File.
$source_code
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.
find($wanted)
find_first($wanted)
find_any($wanted)
If $wanted is a simple PPI class name, then the cache is employed. Otherwise we forward the call to the corresponding method of the PPI::Document instance.
$wanted
filename()
Returns the filename for the source code if applicable (PPI::Document::File) or undef otherwise (PPI::Document).
undef
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.
highest_explicit_perl_version()
Returns a version object for the highest Perl version requirement declared in the document via a use or require statement. Returns nothing if there is no version statement.
use
require
process_annotations()
Causes this Document to scan itself and mark which lines & policies are disabled by the "## no critic" annotations.
"## no critic"
line_is_disabled_for_policy($line, $policy_object)
Returns true if the given $policy_object or $policy_name has been disabled for at $line in this Document. Otherwise, returns false.
$policy_object
$policy_name
$line
add_annotation( $annotation )
Adds an $annotation object to this Document.
$annotation
annotations()
Returns a list containing all the Perl::Critic::Annotation that were found in this Document.
add_suppressed_violation($violation)
Informs this Document that a $violation was found but not reported because it fell on a line that had been suppressed by a "## no critic" annotation. Returns $self.
$violation
$self
suppressed_violations()
Returns a list of references to all the Perl::Critic::Violations that were found in this Document but were suppressed.
Chris Dolan <cdolan@cpan.org>
Copyright (c) 2006-2009 Chris Dolan.
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.
To install Perl::Critic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic
CPAN shell
perl -MCPAN -e shell install Perl::Critic
For more information on module installation, please visit the detailed CPAN module installation guide.