NAME
App::Test::Generator::Mutation::BooleanNegation - Negate boolean return expressions to expose missing assertion coverage
VERSION
Version 0.33
applies_to
Return true if this mutation strategy applies to the given PPI node. Used by the mutation framework to pre-filter nodes before calling mutate.
my $applies = $mutation->applies_to($node);
Arguments
$nodeA PPI::Element node to test.
Returns
True if the node is a PPI::Statement::Return, false otherwise.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Mutation::BooleanNegation' },
node => { type => OBJECT, isa => 'PPI::Element' },
}
output
{ type => SCALAR }
mutate
Walk a PPI document and generate one mutant for each return statement whose expression can be negated. For example, return $ok becomes return !($ok).
my $mutation = App::Test::Generator::Mutation::BooleanNegation->new;
my $doc = PPI::Document->new(\$source);
my @mutants = $mutation->mutate($doc);
for my $m (@mutants) {
print $m->id, ': ', $m->description, "\n";
}
Arguments
$selfAn instance of
App::Test::Generator::Mutation::BooleanNegation.$docA PPI::Document object representing the parsed source to mutate. The document is not modified by this method.
Returns
A list of App::Test::Generator::Mutant objects, one per qualifying return statement found in the document. Returns an empty list if no return statements with expressions are found.
Each mutant carries a transform closure that when called with a fresh PPI::Document copy will wrap the targeted return expression in !( ), negating its boolean value.
Notes
Mutant IDs include both line and column number to ensure uniqueness when multiple return statements appear on different lines of the same source file.
Only return statements that have an expression child (i.e. not bare return; statements) are mutated.
API specification
input
{
self => {
type => OBJECT,
isa => 'App::Test::Generator::Mutation::BooleanNegation',
},
doc => {
type => OBJECT,
isa => 'PPI::Document',
},
}
output
{
type => ARRAYREF,
elements => {
type => OBJECT,
isa => 'App::Test::Generator::Mutant',
},
}
AUTHOR
Nigel Horne, <njh at nigelhorne.com>
LICENCE AND COPYRIGHT
Copyright 2026 Nigel Horne.
Usage is subject to licence terms.
The licence terms of this software are as follows:
Personal single user, single computer use: GPL2
All other users (including Commercial, Charity, Educational, Government) must apply in writing for a licence for use from Nigel Horne at the above e-mail.