lib/App/GHGen/Detector.pm

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