VERSION

Version 0.34

DESCRIPTION

Analyses the source body of a method and produces a complexity report including cyclomatic score, branching points, early returns, exception paths, and nesting depth. Used by App::Test::Generator to guide test planning — higher complexity methods are prioritised for more thorough test generation.

new

Construct a new Complexity analyser.

my $analyser = App::Test::Generator::Analyzer::Complexity->new;

Arguments

None.

Returns

A blessed hashref.

API specification

input

{}

output

{
    type => OBJECT,
    isa  => 'App::Test::Generator::Analyzer::Complexity',
}

analyze

Analyse the source of a method and return a complexity report hashref.

my $analyser = App::Test::Generator::Analyzer::Complexity->new;
my $report   = $analyser->analyze($method);

printf "Cyclomatic score: %d\n", $report->{cyclomatic_score};
printf "Complexity level: %s\n", $report->{complexity_level};

Arguments

Returns

A hashref with the following keys:

  • cyclomatic_score — integer starting at 1, incremented for each branching point, logical operator, early return, and exception path.

  • branching_points — count of branching keywords found.

  • early_returns — number of return statements beyond the first (each additional return adds a path).

  • exception_paths — count of exception-related keywords found.

  • nesting_depth — maximum brace nesting depth observed.

  • complexity_level — one of low, moderate, or high based on the cyclomatic score.

Notes

Nesting depth is computed by naive brace counting and will be inaccurate if the source contains braces inside strings or regexes. This is a known limitation and is acceptable for dashboard display purposes.

API specification

input

{
    self   => { type => OBJECT, isa => 'App::Test::Generator::Analyzer::Complexity' },
    method => { type => OBJECT, isa => 'App::Test::Generator::Model::Method' },
}

output

{
    type => HASHREF,
    keys => {
        cyclomatic_score  => { type => SCALAR },
        branching_points  => { type => SCALAR },
        early_returns     => { type => SCALAR },
        exception_paths   => { type => SCALAR },
        nesting_depth     => { type => SCALAR },
        complexity_level  => { type => SCALAR },
    },
}

1 POD Error

The following errors were encountered while parsing the POD:

Around line 52:

Non-ASCII character seen before =encoding in '—'. Assuming UTF-8