NAME
Pod::Coverage::More::Analyzer - Infer arguments, return values and termination of subs from their compiled op trees
VERSION
version 0.003
SYNOPSIS
use Pod::Coverage::More::Analyzer;
my $analyzer = Pod::Coverage::More::Analyzer->new();
my $subs = $analyzer->analyze_package('Pod::Coverage::More::Analyzer');
my @params = map { $_->{name} } @{ $subs->{analyze_sub}{params} };
DESCRIPTION
Reads the op tree that perl compiled for each sub of a package, by way of B. This sees the same program that perl runs, so it also covers subs that have no source of their own, such as closures assigned to globs, constants and accessors that were built with a string eval.
The op tree changes between perl versions. new returns an object of the subclass for the running perl, and each subclass adds handlers for the ops of its version set. This class handles the ops that all supported versions share. B::Deparse is the reference for how each op of each perl version is meant to be read.
The analysis is best effort. It reports what the op tree shows, and it marks what it cannot resolve with the type unknown.
SUPPORTED PERLS
5.36 and later releases. Development perls (odd minor versions, such as 5.43.x) are not supported: their ops can change from one development release to the next.
- 5.36 - Pod::Coverage::More::Analyzer::Perl5_36
- 5.38 to 5.42 - Pod::Coverage::More::Analyzer::Perl5_38
- 5.44 and later - Pod::Coverage::More::Analyzer::Perl5_44
Each version set inherits from the one before it, and adds or replaces the handlers for the ops that changed.
METHODS
analyze_package(package)
The records of the subs that package defines, as analyze_sub returns them. The package must be loaded already. Subs that it imported from another package are left out.
When a class builder or a signature module declares a sub, as Pod::Coverage::More::Declared reads it, its record also has declared: that declaration, with wrapped in place of its body, and each parameter that a declared one matches has declared, the declared Type::Tiny constraint. The record of a sub that only wraps the code that does the work describes that code.
Returns HashRef, from the name of each sub to its record.
my $records = $analyzer->analyze_package('Pod::Coverage::More');
analyze_sub(code, name, package)
The record of what the op tree of code shows, as RECORDS describes it.
- code - CodeRef - the sub
- name - Str - the name of the sub
- package - Str - the package that the sub belongs to
Returns HashRef, the record.
my $record = $analyzer->analyze_sub( \&Pod::Coverage::More::coverage, 'coverage', 'Pod::Coverage::More' );
backend_for(version)
The subclass that handles the perl version.
Returns Str, the name of the subclass.
Dies when no subclass handles the version.
my $backend = Pod::Coverage::More::Analyzer::backend_for($]);
classify(op)
The evidence that op, an op that produces a value, gives about that value. It is one HASHREF per alternative, because an expression such as COND ? A : B has more than one.
The type of each is one of undef, empty, number, string, boolean, hashref, arrayref, coderef, ref, object, variable, call, method, list, context or unknown.
Returns HashRef, the evidence, as a list of HASHREFs.
my @evidence = $self->classify($op);
finish_sub(record)
Called once the op tree of a sub was walked, before the parameters are sorted. Subclasses override it to add what only the whole tree shows. The default does nothing.
Returns nothing.
$walker->finish_sub( \%record );
new
An analyzer of the subclass that handles the running perl.
Returns Object, the analyzer, an instance of that subclass.
Dies when the running perl is older than the oldest supported version set.
my $analyzer = Pod::Coverage::More::Analyzer->new;
op_classifiers
The methods that classify calls for some ops, ahead of its own rules. Subclasses add the value-producing ops of their version set here, as they add walk handlers in op_handlers. The default has none.
Returns HashRef, from the name of each op to the name of its method.
my $classifiers = $analyzer->op_classifiers;
op_handlers
The methods that the walk calls for each op, with the op and the ARRAYREF of its ancestors, nearest last. Subclasses add the ops of their version set to what this returns.
Returns HashRef, from the name of each op to the name of its method.
my $handlers = $analyzer->op_handlers;
op_kids(op)
The kids of op, in order, for the handlers of subclasses.
Returns the kids, as a list of B::OP objects.
my @kids = $self->op_kids($op);
RECORDS
The record of a sub, which analyze_sub returns, is a HASHREF with what the op tree of the sub shows:
- name, package - STRING - the name and the package, as given
- kind - STRING -
perl,xsorconstant - value - SCALAR - the value of a constant
- file, line - STRING, INTEGER - where the body starts
- generated - BOOLEAN - true when the sub has no source file of its own, was installed under a different name, or was compiled in a file other than the one that PACKAGE was loaded from, as an accessor that a class builder installs
- method - BOOLEAN - true for a
methodof the core class feature, whose parameter 0 is the implicit$self - signature - BOOLEAN - true when the sub has a signature, even an empty one
- reads_args - BOOLEAN - true when the body reads
@_in any way: a shift of it, an element, or the whole array - params - ARRAYREF - one HASHREF per parameter, in order:
name(undef when it has none),index,source(shift,list,element,signature,invocant, orcheckedfor a parameter that a call such as$check->(@_)returns),slurpy,optional,default,keys,inferred, the Type::Tiny constraint that the uses of the parameter in the body amount to, or undef, anddeclared, a constraint that the code declares for it, withdeclared_by, what declared it: a guard such asassert_Int($x)of a Type::Library or a type check that Method::Signatures compiled, a checker of Type::Params, or the declaration of a class builder or a signature module - usage - HASHREF - per lexical variable, how the body uses it:
hashref,arrayref,coderef,numeric,string,methodsandkeys - returns - ARRAYREF - one HASHREF per value the sub can return, with
type,lineandimplicit,constraint, the Type::Tiny constraint that the value satisfies when the evidence says,weak, true when the value is the result of an operator, which overloading can change, plus details per type - dies - ARRAYREF - one HASHREF per explicit termination, with
via,lineandcaught
SEE ALSO
Please see those modules/websites for more information related to this module.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/teodesian/Pod-Coverage-More/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHORS
Current Maintainers:
George S. Baugh <teodesian@cpan.org>
COPYRIGHT AND LICENSE
Copyright (c) 2014-2026 George S. Baugh
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.