NAME
App::Test::Generator::Model::Method - Evidence-based model of a single method under test
VERSION
Version 0.40
DESCRIPTION
Accumulates weighted evidence about a single method's return behaviour, gathered independently by several analysers (App::Test::Generator::Analyzer::Return and friends), then resolves that evidence into a best-guess return type, test classification, and confidence level. This lets multiple independent heuristics contribute to one final judgement instead of the first heuristic to run winning outright.
new
Construct a new Method model.
my $method = App::Test::Generator::Model::Method->new(
name => 'get_name',
source => 'sub get_name { return $_[0]->{name}; }',
);
Arguments
nameThe method's name. Required.
sourceThe method's raw Perl source text. Required.
Returns
A blessed hashref with evidence initialised to an empty arrayref and return_type, classification, and confidence initialised to undef. Croaks with "name required" or "source required" if either argument is missing.
API specification
input
{
name => { type => SCALAR },
source => { type => SCALAR },
}
output
{ type => OBJECT, isa => 'App::Test::Generator::Model::Method' }
name
Return the method's name.
my $name = $method->name;
Arguments
None beyond $self.
Returns
The name string supplied to new. Read-only — there is no setter; name ignores any extra arguments passed to it.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => SCALAR }
source
Return the method's raw source text.
my $source = $method->source;
Arguments
None beyond $self.
Returns
The source string supplied to new. Read-only — there is no setter; source ignores any extra arguments passed to it.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => SCALAR }
return_type
Read/write accessor for the resolved return type.
$method->return_type('object');
my $type = $method->return_type;
Arguments
$valOptional. If supplied (including
undef), stores it as the new return type.
Returns
The current return type string, or undef if not yet resolved (or explicitly set back to undef).
Side effects
Overwrites the stored return type when called with an argument.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
val => { type => SCALAR, optional => 1 },
}
output
{ type => SCALAR, optional => 1 }
classification
Read/write accessor for the resolved test classification.
$method->classification('getter');
my $class = $method->classification;
Arguments
$valOptional. If supplied (including
undef), stores it as the new classification.
Returns
The current classification string, or undef if not yet resolved.
Side effects
Overwrites the stored classification when called with an argument.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
val => { type => SCALAR, optional => 1 },
}
output
{ type => SCALAR, optional => 1 }
confidence
Read/write accessor for the resolved confidence hashref.
$method->confidence({ score => 45, level => 'medium' });
my $conf = $method->confidence;
Arguments
$valOptional. If supplied (including
undef), stores it as the new confidence value.
Returns
The current confidence hashref (with score and level keys), or undef if not yet resolved.
Side effects
Overwrites the stored confidence value when called with an argument.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
val => { type => HASHREF, optional => 1 },
}
output
{ type => HASHREF, optional => 1 }
add_evidence
Record one piece of weighted evidence about the method's behaviour.
$method->add_evidence(
category => 'return',
signal => 'returns_property',
value => 'name',
weight => 20,
);
Arguments
categoryOne of
return,input, oreffect. Required. Croaks"Invalid evidence category '...'"for any other value, including a missing category.signalA recognised signal name (see "Notes"). Required. Croaks
"Invalid evidence signal '...'"for any other value, including a missing signal.valueOptional. An arbitrary value associated with the signal (e.g. the property name for
returns_property).weightOptional. A numeric weight. Defaults to 1.
Returns
Nothing (undef).
Side effects
Appends an evidence hashref (with keys category, signal, value, weight) to the object's internal evidence list.
Notes
Recognised signals are returns_property, returns_constant, returns_self, legacy_type, context_aware, error_pattern (intended for category return); input_validated, input_typed, input_optional (category input); and has_side_effect, no_side_effect (category effect). Signal validity is checked against the full set regardless of category — passing a return-only signal with category => 'input' does not croak.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
category => { type => SCALAR },
signal => { type => SCALAR },
value => { type => SCALAR, optional => 1 },
weight => { type => SCALAR, optional => 1 },
}
output
{ type => UNDEF }
evidence
Return all recorded evidence entries.
my @evidence = $method->evidence;
for my $entry (@evidence) {
print "$entry->{category}/$entry->{signal}: $entry->{weight}\n";
}
Arguments
None beyond $self.
Returns
A list of evidence hashrefs (each with keys category, signal, value, weight), in the order they were added via add_evidence. Empty list if no evidence has been recorded. Called in scalar context, returns the count of evidence entries.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => ARRAYREF, items => { type => HASHREF } }
evidence_ref
Return all recorded evidence entries as an arrayref.
my $ref = $method->evidence_ref;
print "count: ", scalar(@$ref), "\n";
Arguments
None beyond $self.
Returns
An arrayref of the same evidence hashrefs returned by evidence. This is the live internal arrayref, not a copy — modifying it modifies the object's evidence list.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => ARRAYREF, items => { type => HASHREF } }
resolve_return_type
Derive a return type from the accumulated return-category evidence and store it.
$method->add_evidence(category => 'return', signal => 'returns_self', weight => 20);
my $type = $method->resolve_return_type; # 'object'
Arguments
None beyond $self.
Returns
One of object, property, or constant, chosen by summing the weight of all return-category evidence into three buckets (returns_self -> object; returns_property, context_aware, error_pattern -> property; returns_constant -> constant; legacy_type -> object or property depending on its value) and picking the highest-scoring bucket. Ties are broken alphabetically among the tied bucket names (constant < object < property). With no return-category evidence at all, all three buckets score 0 and constant wins the alphabetical tie-break.
Side effects
Sets return_type to the resolved value.
Notes
Evidence outside the return category is ignored. Evidence with an unrecognised signal name is also ignored (this can only happen if a caller other than add_evidence populated the evidence list directly, since add_evidence itself rejects unrecognised signals).
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => SCALAR }
resolve_confidence
Derive a confidence level from the total weight of all accumulated evidence (every category, not just return) and store it.
$method->add_evidence(category => 'return', signal => 'returns_self', weight => 50);
my $conf = $method->resolve_confidence; # { score => 50, level => 'high' }
Arguments
None beyond $self.
Returns
A hashref with keys score (the sum of every evidence entry's weight) and level, which is low if score is below $MEDIUM_CONFIDENCE_THRESHOLD (20), medium if at least 20 but below $HIGH_CONFIDENCE_THRESHOLD (40), or high if 40 or above. With no evidence at all, score is 0 and level is low.
Side effects
Sets confidence to the resolved hashref.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{
type => HASHREF,
keys => {
score => { type => SCALAR },
level => { type => SCALAR },
},
}
resolve_classification
Derive a test classification from the resolved return type and store it.
$method->add_evidence(category => 'return', signal => 'returns_self', weight => 20);
my $class = $method->resolve_classification; # 'chainable'
Arguments
None beyond $self.
Returns
chainable if return_type is object, getter if property, constant if constant, or unknown for any other value.
Side effects
Calls resolve_return_type first (and so also sets return_type) if return_type has not already been resolved. Sets classification to the resolved value.
API specification
input
{ self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' } }
output
{ type => SCALAR }
absorb_legacy_output
Convert a legacy schema output hashref (the pre-evidence-model output descriptor format) into one or more return-category evidence entries.
$method->absorb_legacy_output({
type => 'object',
_returns_self => 1,
});
Arguments
$outputA hashref of legacy output hints, or
undef.
Returns
Nothing (undef).
Side effects
For each recognised key present and true in $output, calls add_evidence once:
type->legacy_typeevidence,valueset to$output->{type}, weight 20._returns_self->returns_selfevidence, weight 25._context_aware->context_awareevidence, weight 15._error_return->error_patternevidence,valueset to$output->{_error_return}, weight 15.
Notes
$output being undef or any non-hashref value is silently ignored — no evidence is added and no exception is raised. A hashref with none of the four recognised keys set to a true value also adds no evidence.
API specification
input
{
self => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
output => { type => HASHREF, optional => 1 },
}
output
{ type => UNDEF }
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 107:
Non-ASCII character seen before =encoding in '—'. Assuming UTF-8