| Perl::Critic::Document(3pm) | User Contributed Perl Documentation | Perl::Critic::Document(3pm) |
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(-source => $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.
This is implemented as a facade, where method calls are handed to the stored "PPI::Document" instance.
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();"
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.
In the event that $source_code 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 "-filename-override" to force the Perl::Critic::Document to have a particular $filename. Do not use this option if $source_code is already the name of a file, or is a reference to a PPI::Document::File.
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.
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 "m/ [.] PL \z /smx".
foo();
package Foo;
package Bar;
package Foo;
this method will return two Perl::Critic::Documents for a parameter of "Foo". For more, see "split_ppi_node_by_namespace" in PPIx::Utils::Traversal.
In the case where $outer is itself a scope-defining element, returns true if $outer contains $inner. In any other case, $inner must be after the last element of the statement containing $outer, and the innermost scope for $outer also contains $inner.
This is not the same as asking whether $inner is visible from $outer.
Chris Dolan <cdolan@cpan.org>
Copyright (c) 2006-2023 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.
| 2023-10-27 | perl v5.36.0 |