VERSION
Version 0.34
DESCRIPTION
Analyses the source body of a method and produces a side effect report describing whether the method mutates $self, mutates global state, performs IO, or calls external commands. Used by App::Test::Generator to classify methods by purity and guide test generation strategy.
new
Construct a new SideEffect analyser.
my $analyser = App::Test::Generator::Analyzer::SideEffect->new;
Arguments
None.
Returns
A blessed hashref.
API specification
input
{}
output
{
type => OBJECT,
isa => 'App::Test::Generator::Analyzer::SideEffect',
}
analyze
Analyse the source body of a method and return a side effect report hashref.
my $analyser = App::Test::Generator::Analyzer::SideEffect->new;
my $report = $analyser->analyze($method);
if ($report->{purity_level} eq 'pure') {
print "Method is side-effect free\n";
}
Arguments
$methodA hashref with a
bodykey containing the raw source text of the method to analyse.
Returns
A hashref with the following keys:
mutates_self— 1 if the method assigns to$self->{field}.mutates_globals— 1 if the method modifies global variables.performs_io— 1 if the method performs IO operations.calls_external— 1 if the method calls external commands.mutation_fields— arrayref of$selffield names assigned to (deduplicated).purity_level— one ofpure,self_mutating, orimpure.
Notes
Detection is based on regex pattern matching against the raw source text and will not catch dynamically constructed calls or aliased operations. The global variable pattern covers common Perl specials but is not exhaustive.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Analyzer::SideEffect' },
method => { type => HASHREF },
}
output
{
type => HASHREF,
keys => {
mutates_self => { type => SCALAR },
mutates_globals => { type => SCALAR },
performs_io => { type => SCALAR },
calls_external => { type => SCALAR },
mutation_fields => { type => ARRAYREF },
purity_level => { type => SCALAR },
},
}
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 110:
Non-ASCII character seen before =encoding in '—'. Assuming UTF-8