NAME
App::GHGen::Detector - Detect project type from repository contents
SYNOPSIS
use App::GHGen::Detector qw(detect_project_type);
my $type = detect_project_type();
# Returns: 'perl', 'node', 'python', etc.
FUNCTIONS
detect_project_type()
Detect the project type by examining indicator files in the current directory.
Purpose
Score the current working directory against ten known project types (perl, node, python, rust, go, ruby, php, java, cpp, docker) and return the highest-scoring type.
Arguments
None.
Returns
In scalar context: the type string (e.g. 'perl') of the best match, or undef when no type scores above zero.
In list context: a list of { type = Str, score => Int, indicators => [] }> hash references sorted by descending score.
Side Effects
Reads the filesystem; results depend on the current working directory.
Usage Example
use App::GHGen::Detector qw(detect_project_type);
my $type = detect_project_type();
say $type // 'unknown';
API SPECIFICATION
Input
# No parameters.
Output (scalar context)
{ type => 'scalar' } # may be undef
Output (list context)
{ type => 'array', element => { type => 'hashref' } }
FORMAL SPECIFICATION
detect_project_type : → ℤ* ∪ { ⊥ } | seq Detection
Detection ≔ { type: ProjectType, score: ℕ, indicators: seq ℤ* }
detections ≔ [ { type: t, score: score(t) } ∣ t ∈ Types, score(t) > 0 ]
ranked ≔ sort desc-score detections
scalar context: ranked = ∅ → ⊥ | ranked ≠ ∅ → ranked[0].type
list context: ranked
get_project_indicators($type)
Return the indicator file patterns associated with a given project type.
Purpose
Provide a human-readable or programmatic list of the files and patterns that the detector uses to score each project type.
Arguments
$type(Str, optional)-
A project type string such as
'perl','node','python', etc. When omitted orundef, the full indicator table is returned.
Returns
When $type is given and known: an array reference of strings (file names / glob patterns).
When $type is undef or omitted: a hash reference mapping every known type to its indicator list.
When $type is given but unknown: undef.
Side Effects
None. Pure lookup function.
Usage Example
my $indicators = get_project_indicators('perl');
say for @$indicators;
my $all = get_project_indicators();
for my $type (sort keys %$all) {
say "$type: " . join(', ', @{$all->{$type}});
}
API SPECIFICATION
Input
{ type => { type => 'scalar', optional => 1 } }
Output
known type → { type => 'arrayref' }
all types → { type => 'hashref' }
unknown type → undef
FORMAL SPECIFICATION
get_project_indicators : ℤ* ∪ { ⊥ } → seq ℤ* ∪ (ℤ* → seq ℤ*) ∪ { ⊥ }
t given ∧ t ∈ KnownTypes → indicators[t] (ArrayRef)
t given ∧ t ¬in; KnownTypes → ⊥ (undef)
t absent → indicators (HashRef of all types)
AUTHOR
Nigel Horne <njh@nigelhorne.com>
LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 78:
Non-ASCII character seen before =encoding in '→'. Assuming UTF-8