| 1 | package App::GHGen::Detector; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 8 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 11 | detect_project_type | ||||||||||||||||||||||||||||
| 12 | get_project_indicators | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 8 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | App::GHGen::Detector - Detect project type from repository contents | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | use App::GHGen::Detector qw(detect_project_type); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | my $type = detect_project_type(); | ||||||||||||||||||||||||||||
| 26 | # Returns: 'perl', 'node', 'python', etc. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 detect_project_type() | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Detect the project type by examining indicator files in the current directory. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head3 Purpose | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Score the current working directory against ten known project types | ||||||||||||||||||||||||||||
| 37 | (perl, node, python, rust, go, ruby, php, java, cpp, docker) and return | ||||||||||||||||||||||||||||
| 38 | the highest-scoring type. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head3 Arguments | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | None. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head3 Returns | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | In scalar context: the type string (e.g. C<'perl'>) of the best match, or | ||||||||||||||||||||||||||||
| 47 | C<undef> when no type scores above zero. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | In list context: a list of C<{ type => Str, score => Int, indicators => [] }> | ||||||||||||||||||||||||||||
| 50 | hash references sorted by descending score. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head3 Side Effects | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Reads the filesystem; results depend on the current working directory. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head3 Usage Example | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | use App::GHGen::Detector qw(detect_project_type); | ||||||||||||||||||||||||||||
| 59 | my $type = detect_project_type(); | ||||||||||||||||||||||||||||
| 60 | say $type // 'unknown'; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head4 Input | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # No parameters. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head4 Output (scalar context) | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | { type => 'scalar' } # may be undef | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head4 Output (list context) | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | { type => 'array', element => { type => 'hashref' } } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | detect_project_type : → ℤ* ∪ { ⊥ } | seq Detection | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Detection ≔ { type: ProjectType, score: ℕ, indicators: seq ℤ* } | ||||||||||||||||||||||||||||
| 81 | detections ≔ [ { type: t, score: score(t) } ∣ t ∈ Types, score(t) > 0 ] | ||||||||||||||||||||||||||||
| 82 | ranked ≔ sort desc-score detections | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | scalar context: ranked = ∅ → ⊥ | ranked ≠ ∅ → ranked[0].type | ||||||||||||||||||||||||||||
| 85 | list context: ranked | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 18 | ▶ | sub detect_project_type() { | ||||||||||||||||||||||||||
|
Subroutine
detect_project_type: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 18 | my @detections; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # Check for each project type | ||||||||||||||||||||||||||||
| 93 | 18 | for my $type (qw(perl node python rust go ruby php java cpp docker)) { | |||||||||||||||||||||||||||
| 94 | 180 | my $detector = "_detect_$type"; | |||||||||||||||||||||||||||
| 95 | 180 | my $score = __PACKAGE__->can($detector)->(); | |||||||||||||||||||||||||||
| 96 | 180 | ▶ | push @detections, { type => $type, score => $score, indicators => [] } if $score > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Sort by score (highest first) | ||||||||||||||||||||||||||||
| 100 | 18 | @detections = sort { $b->{score} <=> $a->{score} } @detections; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # `return;` returns () in list context and undef in scalar context — correct for both. | ||||||||||||||||||||||||||||
| 103 | # `return undef` would return (undef) in list context, i.e. a one-element list. | ||||||||||||||||||||||||||||
| 104 | 18 | ▶ | return unless @detections; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 13 | ▶ | return wantarray ? @detections : $detections[0]->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head2 get_project_indicators($type) | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Return the indicator file patterns associated with a given project type. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head3 Purpose | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Provide a human-readable or programmatic list of the files and patterns that | ||||||||||||||||||||||||||||
| 115 | the detector uses to score each project type. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head3 Arguments | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =over 4 | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item C<$type> (Str, optional) | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | A project type string such as C<'perl'>, C<'node'>, C<'python'>, etc. | ||||||||||||||||||||||||||||
| 124 | When omitted or C<undef>, the full indicator table is returned. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =back | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head3 Returns | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | When C<$type> is given and known: an array reference of strings (file names / | ||||||||||||||||||||||||||||
| 131 | glob patterns). | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | When C<$type> is C<undef> or omitted: a hash reference mapping every known | ||||||||||||||||||||||||||||
| 134 | type to its indicator list. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | When C<$type> is given but unknown: C<undef>. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head3 Side Effects | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | None. Pure lookup function. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head3 Usage Example | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | my $indicators = get_project_indicators('perl'); | ||||||||||||||||||||||||||||
| 145 | say for @$indicators; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | my $all = get_project_indicators(); | ||||||||||||||||||||||||||||
| 148 | for my $type (sort keys %$all) { | ||||||||||||||||||||||||||||
| 149 | say "$type: " . join(', ', @{$all->{$type}}); | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head4 Input | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | { type => { type => 'scalar', optional => 1 } } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head4 Output | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | known type → { type => 'arrayref' } | ||||||||||||||||||||||||||||
| 161 | all types → { type => 'hashref' } | ||||||||||||||||||||||||||||
| 162 | unknown type → undef | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | get_project_indicators : ℤ* ∪ { ⊥ } → seq ℤ* ∪ (ℤ* → seq ℤ*) ∪ { ⊥ } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | t given ∧ t ∈ KnownTypes → indicators[t] (ArrayRef) | ||||||||||||||||||||||||||||
| 169 | t given ∧ t ∉ KnownTypes → ⊥ (undef) | ||||||||||||||||||||||||||||
| 170 | t absent → indicators (HashRef of all types) | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 12 | ▶ | sub get_project_indicators($type = undef) { | ||||||||||||||||||||||||||
|
Subroutine
get_project_indicators: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 12 | my %indicators = ( | |||||||||||||||||||||||||||
| 176 | perl => [ | ||||||||||||||||||||||||||||
| 177 | 'cpanfile', 'dist.ini', 'Makefile.PL', 'Build.PL', | ||||||||||||||||||||||||||||
| 178 | 'lib/*.pm', 't/*.t', 'META.json', 'META.yml' | ||||||||||||||||||||||||||||
| 179 | ], | ||||||||||||||||||||||||||||
| 180 | node => [ | ||||||||||||||||||||||||||||
| 181 | 'package.json', 'package-lock.json', 'yarn.lock', | ||||||||||||||||||||||||||||
| 182 | 'node_modules/', 'tsconfig.json', '.npmrc' | ||||||||||||||||||||||||||||
| 183 | ], | ||||||||||||||||||||||||||||
| 184 | python => [ | ||||||||||||||||||||||||||||
| 185 | 'requirements.txt', 'setup.py', 'pyproject.toml', | ||||||||||||||||||||||||||||
| 186 | 'Pipfile', 'poetry.lock', 'setup.cfg', 'tox.ini' | ||||||||||||||||||||||||||||
| 187 | ], | ||||||||||||||||||||||||||||
| 188 | rust => [ | ||||||||||||||||||||||||||||
| 189 | 'Cargo.toml', 'Cargo.lock', 'src/main.rs', | ||||||||||||||||||||||||||||
| 190 | 'src/lib.rs', 'rust-toolchain.toml' | ||||||||||||||||||||||||||||
| 191 | ], | ||||||||||||||||||||||||||||
| 192 | go => [ | ||||||||||||||||||||||||||||
| 193 | 'go.mod', 'go.sum', 'main.go', '*.go' | ||||||||||||||||||||||||||||
| 194 | ], | ||||||||||||||||||||||||||||
| 195 | ruby => [ | ||||||||||||||||||||||||||||
| 196 | 'Gemfile', 'Gemfile.lock', 'Rakefile', | ||||||||||||||||||||||||||||
| 197 | '.ruby-version', 'config.ru' | ||||||||||||||||||||||||||||
| 198 | ], | ||||||||||||||||||||||||||||
| 199 | php => [ | ||||||||||||||||||||||||||||
| 200 | 'composer.json', 'composer.lock', 'phpunit.xml', | ||||||||||||||||||||||||||||
| 201 | 'phpunit.xml.dist', 'src/', 'tests/' | ||||||||||||||||||||||||||||
| 202 | ], | ||||||||||||||||||||||||||||
| 203 | java => [ | ||||||||||||||||||||||||||||
| 204 | 'pom.xml', 'build.gradle', 'build.gradle.kts', | ||||||||||||||||||||||||||||
| 205 | 'gradlew', 'mvnw', 'src/main/java/' | ||||||||||||||||||||||||||||
| 206 | ], | ||||||||||||||||||||||||||||
| 207 | cpp => [ | ||||||||||||||||||||||||||||
| 208 | 'CMakeLists.txt', 'Makefile', 'configure.ac', | ||||||||||||||||||||||||||||
| 209 | '*.cpp', '*.hpp', '*.cc', '*.h' | ||||||||||||||||||||||||||||
| 210 | ], | ||||||||||||||||||||||||||||
| 211 | c => [ | ||||||||||||||||||||||||||||
| 212 | 'CMakeLists.txt', 'Makefile', 'configure.ac', | ||||||||||||||||||||||||||||
| 213 | '*.c', '*.h', | ||||||||||||||||||||||||||||
| 214 | ], | ||||||||||||||||||||||||||||
| 215 | docker => [ | ||||||||||||||||||||||||||||
| 216 | 'Dockerfile', 'docker-compose.yml', 'docker-compose.yaml', | ||||||||||||||||||||||||||||
| 217 | '.dockerignore' | ||||||||||||||||||||||||||||
| 218 | ], | ||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 12 | ▶ | return $type ? $indicators{$type} : \%indicators; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # Detection functions - return a score (0 = not detected, higher = more confident) | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 24 | ▶ | sub _detect_perl() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_perl: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||
| 227 | 24 | my $score = 0; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Strong indicators | ||||||||||||||||||||||||||||
| 230 | 24 | ▶ | $score += 10 if path('cpanfile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 24 | ▶ | $score += 10 if path('dist.ini')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 24 | ▶ | $score += 8 if path('Makefile.PL')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 24 | ▶ | $score += 8 if path('Build.PL')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # Medium indicators | ||||||||||||||||||||||||||||
| 236 | 24 | ▶ | $score += 5 if path('META.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 24 | ▶ | $score += 5 if path('META.yml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # Weak indicators | ||||||||||||||||||||||||||||
| 240 | 24 | ▶ | $score += 3 if path('lib')->exists && path('lib')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
path("lib")->exists and path("lib")->is_dir
MC/DC50%1/2
path("lib")->exists and path("lib")->is_dir
path("lib")->exists
path("lib")->is_dir
Truth table66%2/3
A and B
A= path("lib")->existsB= path("lib")->is_dir
| |||||||||||||||||||||||||||||
| 241 | 24 | ▶ | $score += 2 if path('t')->exists && path('t')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
path("t")->exists and path("t")->is_dir
MC/DC50%1/2
path("t")->exists and path("t")->is_dir
path("t")->exists
path("t")->is_dir
Truth table66%2/3
A and B
A= path("t")->existsB= path("t")->is_dir
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Check for .pm files in lib/ | ||||||||||||||||||||||||||||
| 244 | 24 | ▶ | if (path('lib')->exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 11 | my @pm_files = path('lib')->children(qr/\.pm$/); | |||||||||||||||||||||||||||
| 246 | 11 | ▶ | $score += 2 if @pm_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | # Check for .t files in t/ | ||||||||||||||||||||||||||||
| 250 | 24 | ▶ | if (path('t')->exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 10 | my @t_files = path('t')->children(qr/\.t$/); | |||||||||||||||||||||||||||
| 252 | 10 | ▶ | $score += 1 if @t_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 24 | return $score; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 21 | ▶ | sub _detect_node() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_node: called CC=11 SCAR=26.9
| |||||||||||||||||||||||||||||
| 259 | 21 | my $score = 0; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # Strong indicators | ||||||||||||||||||||||||||||
| 262 | 21 | ▶ | $score += 15 if path('package.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 21 | ▶ | $score += 8 if path('package-lock.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 21 | ▶ | $score += 8 if path('yarn.lock')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 21 | ▶ | $score += 7 if path('pnpm-lock.yaml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | # Medium indicators | ||||||||||||||||||||||||||||
| 268 | 21 | ▶ | $score += 5 if path('node_modules')->exists && path('node_modules')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("node_modules")->exists and path("node_modules")->is_dir
MC/DC0%0/2
path("node_modules")->exists and path("node_modules")->is_dir
path("node_modules")->exists
path("node_modules")->is_dir
Truth table33%1/3
A and B
A= path("node_modules")->existsB= path("node_modules")->is_dir
| |||||||||||||||||||||||||||||
| 269 | 21 | ▶ | $score += 4 if path('tsconfig.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 21 | ▶ | $score += 3 if path('.npmrc')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | # Weak indicators | ||||||||||||||||||||||||||||
| 273 | 21 | ▶ | $score += 2 if path('src')->exists && path('src')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("src")->exists and path("src")->is_dir
MC/DC0%0/2
path("src")->exists and path("src")->is_dir
path("src")->exists
path("src")->is_dir
Truth table33%1/3
A and B
A= path("src")->existsB= path("src")->is_dir
| |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 21 | return $score; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 22 | ▶ | sub _detect_python() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_python: called CC=12 SCAR=26.1
| |||||||||||||||||||||||||||||
| 279 | 22 | my $score = 0; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # Strong indicators | ||||||||||||||||||||||||||||
| 282 | 22 | ▶ | $score += 12 if path('requirements.txt')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 22 | ▶ | $score += 12 if path('setup.py')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 22 | ▶ | $score += 12 if path('pyproject.toml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 22 | ▶ | $score += 10 if path('Pipfile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 22 | ▶ | $score += 8 if path('poetry.lock')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # Medium indicators | ||||||||||||||||||||||||||||
| 289 | 22 | ▶ | $score += 5 if path('setup.cfg')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 22 | ▶ | $score += 4 if path('tox.ini')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 22 | ▶ | $score += 3 if path('.python-version')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # Weak indicators | ||||||||||||||||||||||||||||
| 294 | 22 | ▶ | $score += 2 if path('venv')->exists || path('.venv')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("venv")->exists or path(".venv")->exists
MC/DC0%0/2
path("venv")->exists or path(".venv")->exists
path("venv")->exists
path(".venv")->exists
Truth table33%1/3
A or B
A= path("venv")->existsB= path(".venv")->exists
| |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # Check for .py files | ||||||||||||||||||||||||||||
| 297 | 22 | my @py_files = path('.')->children(qr/\.py$/); | |||||||||||||||||||||||||||
| 298 | 22 | ▶ | $score += 2 if @py_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 22 | return $score; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 19 | ▶ | sub _detect_rust() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_rust: called CC=9 SCAR=25.1
| |||||||||||||||||||||||||||||
| 304 | 19 | my $score = 0; | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | # Strong indicators | ||||||||||||||||||||||||||||
| 307 | 19 | ▶ | $score += 15 if path('Cargo.toml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 19 | ▶ | $score += 10 if path('Cargo.lock')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # Medium indicators | ||||||||||||||||||||||||||||
| 311 | 19 | ▶ | $score += 5 if path('src/main.rs')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 19 | ▶ | $score += 5 if path('src/lib.rs')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 19 | ▶ | $score += 3 if path('rust-toolchain.toml')->exists || path('rust-toolchain')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("rust-toolchain.toml")->exists or path("rust-toolchain")->exists
MC/DC0%0/2
path("rust-toolchain.toml")->exists or path("rust-toolchain")->exists
path("rust-toolchain.toml")->exists
path("rust-toolchain")->exists
Truth table33%1/3
A or B
A= path("rust-toolchain.toml")->existsB= path("rust-toolchain")->exists
| |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # Weak indicators | ||||||||||||||||||||||||||||
| 316 | 19 | ▶ | $score += 2 if path('target')->exists && path('target')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("target")->exists and path("target")->is_dir
MC/DC0%0/2
path("target")->exists and path("target")->is_dir
path("target")->exists
path("target")->is_dir
Truth table33%1/3
A and B
A= path("target")->existsB= path("target")->is_dir
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 19 | return $score; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 22 | ▶ | sub _detect_go() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_go: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 322 | 22 | my $score = 0; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | # Strong indicators | ||||||||||||||||||||||||||||
| 325 | 22 | ▶ | $score += 15 if path('go.mod')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 22 | ▶ | $score += 10 if path('go.sum')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # Medium indicators | ||||||||||||||||||||||||||||
| 329 | 22 | ▶ | $score += 5 if path('main.go')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # Check for .go files | ||||||||||||||||||||||||||||
| 332 | 22 | my @go_files = path('.')->children(qr/\.go$/); | |||||||||||||||||||||||||||
| 333 | 22 | ▶ | $score += 3 if @go_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 22 | ▶ | $score += 1 if @go_files > 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 22 | return $score; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 21 | ▶ | sub _detect_ruby() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_ruby: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||
| 340 | 21 | my $score = 0; | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | # Strong indicators | ||||||||||||||||||||||||||||
| 343 | 21 | ▶ | $score += 15 if path('Gemfile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 21 | ▶ | $score += 10 if path('Gemfile.lock')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # Medium indicators | ||||||||||||||||||||||||||||
| 347 | 21 | ▶ | $score += 5 if path('Rakefile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 21 | ▶ | $score += 4 if path('.ruby-version')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 21 | ▶ | $score += 3 if path('config.ru')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | # Check for .rb files | ||||||||||||||||||||||||||||
| 352 | 21 | my @rb_files = path('.')->children(qr/\.rb$/); | |||||||||||||||||||||||||||
| 353 | 21 | ▶ | $score += 2 if @rb_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 21 | return $score; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 20 | ▶ | sub _detect_docker() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_docker: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 359 | 20 | my $score = 0; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # Strong indicators | ||||||||||||||||||||||||||||
| 362 | 20 | ▶ | $score += 12 if path('Dockerfile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 20 | ▶ | $score += 8 if path('docker-compose.yml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 20 | ▶ | $score += 8 if path('docker-compose.yaml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | # Medium indicators | ||||||||||||||||||||||||||||
| 367 | 20 | ▶ | $score += 3 if path('.dockerignore')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 20 | return $score; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 21 | ▶ | sub _detect_php() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_php: called CC=11 SCAR=26.6
| |||||||||||||||||||||||||||||
| 373 | 21 | my $score = 0; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | # Strong indicators | ||||||||||||||||||||||||||||
| 376 | 21 | ▶ | $score += 15 if path('composer.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 21 | ▶ | $score += 10 if path('composer.lock')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | # Medium indicators | ||||||||||||||||||||||||||||
| 380 | 21 | ▶ | $score += 5 if path('phpunit.xml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 21 | ▶ | $score += 5 if path('phpunit.xml.dist')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 21 | ▶ | $score += 3 if path('.php-version')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | # Weak indicators | ||||||||||||||||||||||||||||
| 385 | 21 | ▶ | $score += 2 if path('src')->exists && path('src')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("src")->exists and path("src")->is_dir
MC/DC0%0/2
path("src")->exists and path("src")->is_dir
path("src")->exists
path("src")->is_dir
Truth table33%1/3
A and B
A= path("src")->existsB= path("src")->is_dir
| |||||||||||||||||||||||||||||
| 386 | 21 | ▶ | $score += 2 if path('tests')->exists && path('tests')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("tests")->exists and path("tests")->is_dir
MC/DC0%0/2
path("tests")->exists and path("tests")->is_dir
path("tests")->exists
path("tests")->is_dir
Truth table33%1/3
A and B
A= path("tests")->existsB= path("tests")->is_dir
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | # Check for .php files | ||||||||||||||||||||||||||||
| 389 | 21 | my @php_files = path('.')->children(qr/\.php$/); | |||||||||||||||||||||||||||
| 390 | 21 | ▶ | $score += 2 if @php_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 21 | return $score; | |||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 22 | ▶ | sub _detect_java() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_java: called CC=11 SCAR=25.0
| |||||||||||||||||||||||||||||
| 396 | 22 | my $score = 0; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | # Strong indicators | ||||||||||||||||||||||||||||
| 399 | 22 | ▶ | $score += 15 if path('pom.xml')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 22 | ▶ | $score += 15 if path('build.gradle')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 22 | ▶ | $score += 15 if path('build.gradle.kts')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | # Medium indicators | ||||||||||||||||||||||||||||
| 404 | 22 | ▶ | $score += 5 if path('gradlew')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 22 | ▶ | $score += 5 if path('mvnw')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 22 | ▶ | $score += 4 if path('settings.gradle')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 22 | ▶ | $score += 4 if path('settings.gradle.kts')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # Weak indicators | ||||||||||||||||||||||||||||
| 410 | 22 | ▶ | $score += 3 if path('src/main/java')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 22 | ▶ | $score += 2 if path('src/test/java')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | # Check for .java files | ||||||||||||||||||||||||||||
| 414 | 22 | my @java_files = path('.')->children(qr/\.java$/); | |||||||||||||||||||||||||||
| 415 | 22 | ▶ | $score += 2 if @java_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 22 | return $score; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 21 | ▶ | sub _detect_cpp() { | ||||||||||||||||||||||||||
|
Subroutine
_detect_cpp: called CC=11 SCAR=25.4
| |||||||||||||||||||||||||||||
| 421 | 21 | my $score = 0; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | # Strong indicators | ||||||||||||||||||||||||||||
| 424 | 21 | ▶ | $score += 12 if path('CMakeLists.txt')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 21 | ▶ | $score += 8 if path('Makefile')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 21 | ▶ | $score += 6 if path('configure.ac')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 21 | ▶ | $score += 6 if path('configure')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | # Medium indicators | ||||||||||||||||||||||||||||
| 430 | 21 | ▶ | $score += 4 if path('meson.build')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 21 | ▶ | $score += 3 if path('.clang-format')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | # Check for C++ files | ||||||||||||||||||||||||||||
| 434 | 21 | my @cpp_files = path('.')->children(qr/\.(?:cpp|cc|cxx|hpp|hxx|h)$/); | |||||||||||||||||||||||||||
| 435 | 21 | ▶ | $score += 3 if @cpp_files > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 21 | ▶ | $score += 2 if @cpp_files > 5; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | # Check for include directory | ||||||||||||||||||||||||||||
| 439 | 21 | ▶ | $score += 2 if path('include')->exists && path('include')->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
path("include")->exists and path("include")->is_dir
MC/DC0%0/2
path("include")->exists and path("include")->is_dir
path("include")->exists
path("include")->is_dir
Truth table33%1/3
A and B
A= path("include")->existsB= path("include")->is_dir
| |||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 21 | return $score; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | Nigel Horne E<lt>njh@nigelhorne.comE<gt> | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | L<https://github.com/nigelhorne> | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 453 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 8 | 1; | |||||||||||||||||||||||||||