bin/ghgen

filter: Statementstmt 27.0% 71 / 263 Branchbran 9.7% 9 / 92 Conditioncond 1.8% 1 / 53 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 78.2% 18 / 23 Podpod n/a totaltotal 21.5% 99 / 460 CC 72 SCAR 60.9
CC
72
Cov
20%
cmd_analyze
805.2
cmd_generate
552.0
auto_detect_with_prompt
156.0
CRAP 439.7
↑ Summary lib/App/GHGen/PerlCustomizer.pm »
1 #!/usr/bin/env perl
2  
3 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use FindBin qw($RealBin);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use lib "$RealBin/../lib"; # prefer local lib/ over any installed version
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Getopt::Long qw(:config no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use App::GHGen::Generator qw(generate_workflow list_workflow_types);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use App::GHGen::Analyzer qw(analyze_workflow find_workflows);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use App::GHGen::Detector qw(detect_project_type get_project_indicators);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use App::GHGen::Interactive qw(customize_workflow);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use App::GHGen::PerlCustomizer qw(generate_custom_perl_workflow);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use App::GHGen::Fixer qw(fix_workflow can_auto_fix);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use App::GHGen::CostEstimator qw(estimate_current_usage estimate_savings);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 our $VERSION = '0.05';
26  
27 1 my %opts = (
28 help => 0,
29 version => 0,
30 list => 0,
31 timeout => undef,
32 );
33  
34 GetOptions(
35 'help|h' => \$opts{help},
36 'version|v' => \$opts{version},
37 'type|t=s' => \$opts{type},
38 'output|o=s' => \$opts{output},
39 'list|l' => \$opts{list},
40 'interactive|i' => \$opts{interactive},
41 'auto|a' => \$opts{auto},
42 'customize|c' => \$opts{customize},
43 'fix|f' => \$opts{fix},
44 'estimate|e' => \$opts{estimate},
45 'timeout=i' => \$opts{timeout},
46 1 ▶) or pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", \$opts{"help"}, "version|v", \$opts{"version"}, "type|t=s", \$opts{"type"}, "output|o=s", \$opts{"output"}, "list|l", \$opts{"list"}, "interactive|i", \$opts{"interactive"}, "auto|a", \$opts{"auto"}, "customize|c", \$opts{"customize"}, "fix|f", \$opts{"fix"}, "estimate|e", \$opts{"estimate"}, "timeout=i", \$opts{"timeout"}) or pod2usage(2) 1 0 1
47  
48 1 ▶pod2usage(1) if $opts{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"help"} 0 1 1
49  
50 1 ▶if ($opts{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"version"}) 0 1 1
51 0 say "ghgen version $VERSION";
52 0 exit 0;
53 }
54  
55 1 ▶my $command = shift @ARGV // '';
Condition50%1/2
shift @ARGV // ""
l!l
10
MC/DC0%0/1
shift @ARGV // ""
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
56  
57 1 ▶if ($command eq 'generate') {
Branch: 2 branches
BranchTrueFalseTotal
if ($command eq 'generate') { } 0 1 1
elsif ($command eq 'analyze') { } 1 0 1
58 0 cmd_generate();
59 } elsif ($command eq 'analyze') {
60 1 cmd_analyze();
61 } else {
62 0 pod2usage(-message => "Unknown command: $command", -exitval => 1);
63 }
64  
65 0 ▶sub cmd_generate() {
Subroutine cmd_generate: not called CC=23 SCAR=63.1
66 0 ▶ if ($opts{list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"list"}) 0 0 0
67 0 list_types();
68 0 return;
69 }
70  
71 0 my $type = $opts{type};
72 0 my $config;
73  
74 # Auto-detect if requested
75 0 ▶ if ($opts{auto} || (!$type && !$opts{interactive} && !$opts{customize})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}) 0 0 0
Condition0%0/9
$opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}
l!l&&r!l&&!r
000
$type || $opts{'interactive'} || $opts{'customize'}
l!l&&r!l&&!r
000
$type or $opts{"interactive"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$opts{"auto"} or not $type || $opts{"interactive"} || $opts{"customize"}
$opts{"auto"} $type $opts{"interactive"} $opts{'customize'}
Truth table0%0/5
A or not(B or C || D)
A= $opts{"auto"}B= $typeC= $opts{"interactive"}D= $opts{'customize'}
ABCDresult
1XXX1
00001
01XX0
001X0
00010
76 0 $type = auto_detect_with_prompt();
77 0 ▶ return unless $type; # User cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
78 }
79  
80 # Interactive mode
81 0 ▶ if ($opts{interactive} && !$type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"interactive"} and not $type) 0 0 0
Condition0%0/3
$opts{"interactive"} and not $type
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"interactive"} and not $type
$opts{"interactive"} not $type
Truth table0%0/3
A and not(B)
A= $opts{"interactive"}B= not $type
ABresult
0X0
100
111
82 0 $type = interactive_select_type();
83 }
84  
85 0 ▶ unless ($type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 0 0 0
86 0 die colored(['red'], "Error: ") .
87 'Please specify --type, use --auto, or use --interactive';
88 }
89  
90 # Customization mode
91 0 ▶ if ($opts{customize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"customize"}) 0 0 0
92 0 $config = customize_workflow($type);
93 }
94  
95 # Generate workflow with optional customization
96 0 my $yaml;
97 0 ▶ if ($config && $type eq 'perl') {
Branch: 2 branches
BranchTrueFalseTotal
if ($config and $type eq 'perl') { } 0 0 0
elsif ($type eq 'perl') { } 0 0 0
Condition0%0/3
$config and $type eq "perl"
!ll&&!rl&&r
000
MC/DC0%0/2
$config and $type eq "perl"
$config $type eq "perl"
Truth table0%0/3
A and B
A= $configB= $type eq "perl"
ABresult
0X0
100
111
98 # Use customized Perl workflow
99 0 ▶ my @perl_versions = @{$config->{perl_versions} // ['5.40', '5.38', '5.36']};
Condition0%0/2
$config->{"perl_versions"} // ["5.40", "5.38", "5.36"]
l!l
00
MC/DC0%0/1
$config->{"perl_versions"} // ["5.40", "5.38", "5.36"]
$config->{"perl_versions"}
Truth table0%0/2
A
A= $config->{"perl_versions"}
Aresult
11
00
100 $yaml = generate_custom_perl_workflow({
101 min_perl_version => $perl_versions[0],
102 max_perl_version => $perl_versions[-1],
103 perl_versions => \@perl_versions,
104 os => $config->{os} // ['ubuntu-latest', 'macos-latest', 'windows-latest'],
105 enable_linter => $config->{enable_linter} // 1,
106 enable_linter_unused => $config->{enable_linter_unused} // 1,
107 enable_critic => $config->{enable_critic} // 1,
108 enable_coverage => $config->{enable_coverage} // 1,
109 timeout => $opts{timeout},
110 0 ▶ });
Condition0%0/10
$config->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
l!l
00
$config->{"enable_linter"} // 1
l!l
00
$config->{"enable_linter_unused"} // 1
l!l
00
$config->{"enable_critic"} // 1
l!l
00
$config->{"enable_coverage"} // 1
l!l
00
MC/DC0%0/1
$config->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
$config->{"os"}
MC/DC0%0/1
$config->{"enable_linter"} // 1
$config->{"enable_linter"}
MC/DC0%0/1
$config->{"enable_linter_unused"} // 1
$config->{"enable_linter_unused"}
MC/DC0%0/1
$config->{"enable_critic"} // 1
$config->{"enable_critic"}
MC/DC0%0/1
$config->{"enable_coverage"} // 1
$config->{"enable_coverage"}
Truth table0%0/2
A
A= $config->{"os"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_linter"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_linter_unused"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_critic"}
Aresult
11
00
Truth table0%0/2
A
A= $config->{"enable_coverage"}
Aresult
11
00
111 } elsif ($type eq 'perl') {
112 0 $yaml = generate_custom_perl_workflow({ timeout => $opts{timeout} });
113 } else {
114 0 $yaml = generate_workflow($type);
115 }
116  
117 0 ▶ unless ($yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($yaml) 0 0 0
118 0 die colored(['red'], 'Error: '), "Unknown project type '$type'. Use --list to see options.";
119 }
120  
121 # Determine output file
122 0 my $output_file = $opts{output};
123 0 ▶ unless ($output_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output_file) 0 0 0
124 0 my $workflows_dir = path('.github/workflows');
125 0 ▶ $workflows_dir->mkpath unless $workflows_dir->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $workflows_dir->exists 0 0 0
126 0 $output_file = $workflows_dir->child("$type-ci.yml");
127 }
128  
129 # Write the workflow
130 0 path($output_file)->spew_utf8($yaml);
131  
132 0 say colored(['green'], "✓ ") . 'Generated workflow: ' . colored(['bold'], $output_file);
133 0 say '';
134 0 say colored(['cyan'], "Next steps:");
135 0 say " 1. Review the generated workflow";
136 0 say " 2. Customize it for your project";
137 0 say " 3. Commit and push to trigger the workflow";
138 0 say '';
139 0 say colored(['yellow'], "💡 Tip: ") . "Run 'ghgen analyze' to check for optimizations";
140 }
141  
142 1 ▶sub cmd_analyze() {
Subroutine cmd_analyze: called CC=33 SCAR=66.9
143 1 my @workflow_files = find_workflows();
144  
145 1 ▶ unless (@workflow_files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@workflow_files) 0 1 1
146 0 die colored(['red'], 'Error: ') .
147 "No .github/workflows directory found\n" .
148 'Run this from the root of a repository with GitHub Actions.';
149 }
150  
151 1 say colored(['bold cyan'], "GitHub Actions Workflow Analyzer");
152 1 ▶ if ($opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix"}) 0 1 1
153 0 say colored(['yellow'], '(Auto-fix mode enabled)');
154 }
155 1 ▶ if ($opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"}) 1 0 1
156 1 say colored(['cyan'], "(Cost estimation mode)");
157 }
158 1 say colored(['cyan'], "=" x 50);
159 1 say '';
160  
161 # Get cost estimate first if requested
162 1 my $current_usage;
163 1 ▶ if ($opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"}) 1 0 1
164 1 say colored(['bold'], "📊 Estimating current CI usage...");
165 1 say '';
166 1 $current_usage = estimate_current_usage(\@workflow_files);
167  
168 0 say colored(['bold'], "Current Monthly Usage:");
169 0 say " Total CI minutes: " . colored(['yellow'], $current_usage->{total_minutes});
170 0 say " Billable minutes: " . colored(['yellow'], $current_usage->{billable_minutes}) .
171 " (after 2,000 free tier)";
172 0 say " Estimated cost: " . colored(['yellow'], sprintf("\$%.2f", $current_usage->{monthly_cost}));
173 0 say '';
174  
175 0 ▶ if (@{$current_usage->{workflows}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$current_usage->{"workflows"};} > 1) 0 0 0
176 0 say colored(['bold'], "Per-Workflow Breakdown:");
177 0 for my $wf (sort { $b->{minutes_per_month} <=> $a->{minutes_per_month} }
178 0 @{$current_usage->{workflows}}) {
179 say sprintf(" %-40s %4d min/month (%3d runs × %4.1f min/run)",
180 $wf->{name},
181 $wf->{minutes_per_month},
182 $wf->{runs_per_month},
183 0 $wf->{minutes_per_run});
184 }
185 0 say '';
186 }
187 }
188  
189 0 my @all_issues;
190 0 my $total_workflows = 0;
191 0 my $total_fixes = 0;
192  
193 # Analyze each workflow file
194 0 for my $file (@workflow_files) {
195 0 $total_workflows++;
196 0 say colored(['bold'], "📄 Analyzing: ") . $file->basename;
197  
198 0 my $workflow;
199 0 eval { $workflow = LoadFile($file) };
200 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
201 0 say colored(['red'], " ✗ Failed to parse YAML: $@");
202 0 next;
203 }
204  
205 0 my @issues = analyze_workflow($workflow, $file->basename);
206  
207 0 ▶ if (@issues) {
Branch: 1 branch
BranchTrueFalseTotal
if (@issues) { } 0 0 0
208 # Filter to auto-fixable issues if in fix mode
209 0 ▶ my @fixable = $opts{fix} ? grep { can_auto_fix($_) } @issues : @issues;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'fix'} ? : 0 0 0
210  
211 0 ▶ if ($opts{fix} && @fixable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'fix'} and @fixable) { } 0 0 0
Condition0%0/3
$opts{"fix"} and @fixable
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"fix"} and @fixable
$opts{"fix"} @fixable
Truth table0%0/3
A and B
A= $opts{"fix"}B= @fixable
ABresult
0X0
100
111
212 0 say " " . colored(['yellow'], "⚙ ") . "Applying " . scalar(@fixable) . " fix(es)...";
213  
214 0 my $fixes = fix_workflow($file, \@fixable);
215 0 $total_fixes += $fixes;
216  
217 0 ▶ if ($fixes > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixes > 0) { } 0 0 0
218 0 say " " . colored(['green'], "✓ ") . "Applied $fixes fix(es)";
219 } else {
220 0 say " " . colored(['yellow'], "⚠ ") . "Could not apply some fixes automatically";
221 }
222 } else {
223 # Just report issues
224 0 for my $issue (@issues) {
225 0 ▶ my $icon = can_auto_fix($issue) ? "⚠" : "ℹ";
Branch: 1 branch
BranchTrueFalseTotal
can_auto_fix($issue) ? : 0 0 0
226 0 say " " . colored(['yellow'], "$icon ") . $issue->{message};
227 0 ▶ if ($issue->{fix} && !$opts{fix} && !$opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}) 0 0 0
Condition0%0/6
$issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}
!ll&&!rl&&r
000
$issue->{"fix"} and not $opts{"fix"}
!ll&&!rl&&r
000
MC/DC0%0/3
$issue->{"fix"} and not $opts{"fix"} and not $opts{"estimate"}
$issue->{"fix"} not $opts{"fix"} not $opts{"estimate"}
Truth table0%0/4
A and not(B) and not(C)
A= $issue->{"fix"}B= not $opts{"fix"}C= not $opts{"estimate"}
ABCresult
0XX0
10X0
1100
1111
228 0 say colored(['cyan'], " 💡 Fix:");
229 0 for my $line (split /\n/, $issue->{fix}) {
230 0 say " " . $line;
231 }
232 }
233 }
234 }
235  
236 0 push @all_issues, map { { file => $file->basename, %$_ } } @issues;
237 } else {
238 0 say " " . colored(['green'], "✓ No issues found");
239 }
240 0 say '';
241 }
242  
243 # Summary
244 0 say colored(['bold cyan'], "=" x 50);
245 0 say colored(['bold'], "Summary:");
246 0 say " Workflows analyzed: $total_workflows";
247 0 say " Total issues found: " . scalar(@all_issues);
248  
249 0 ▶ if ($opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fix"}) 0 0 0
250 0 say " Fixes applied: " . colored(['green'], $total_fixes);
251 }
252  
253 # Cost savings estimate
254 0 ▶ if ($opts{estimate} && @all_issues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"estimate"} and @all_issues) 0 0 0
Condition0%0/3
$opts{"estimate"} and @all_issues
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"estimate"} and @all_issues
$opts{"estimate"} @all_issues
Truth table0%0/3
A and B
A= $opts{"estimate"}B= @all_issues
ABresult
0X0
100
111
255 0 say '';
256 0 my $savings = estimate_savings(\@all_issues, \@workflow_files);
257  
258 0 ▶ if ($savings->{minutes} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($savings->{"minutes"} > 0) 0 0 0
259 0 say colored(['bold'], "💰 Potential Savings:");
260 0 say ' With recommended changes: ' . colored(['green'], ($current_usage->{total_minutes} - $savings->{minutes})) .
261 " CI minutes/month";
262 0 say " Reduction: " . colored(['green'], "-$savings->{minutes} minutes") .
263 " (" . colored(['green'], "$savings->{percentage}%") . ")";
264 0 say " Cost savings: " . colored(['green'], "\$$savings->{cost}/month") .
265 " (for private repos)";
266  
267 0 ▶ if (@{$savings->{details}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$savings->{"details"};}) 0 0 0
268 0 say '';
269 0 say " Breakdown:";
270 0 for my $detail (@{$savings->{details}}) {
271 0 say " • $detail->{description}: ~$detail->{minutes} min/month";
272 }
273 }
274 }
275 }
276  
277 0 ▶ if (@all_issues && !$opts{fix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@all_issues and not $opts{"fix"}) 0 0 0
Condition0%0/3
@all_issues and not $opts{"fix"}
!ll&&!rl&&r
000
MC/DC0%0/2
@all_issues and not $opts{"fix"}
@all_issues not $opts{"fix"}
Truth table0%0/3
A and not(B)
A= @all_issuesB= not $opts{"fix"}
ABresult
0X0
100
111
278 0 say '';
279 0 say colored(['bold yellow'], "Recommendations:");
280 0 my %by_type;
281 0 push @{$by_type{$_->{type}}}, $_ for @all_issues;
282  
283 0 for my $type (sort keys %by_type) {
284 0 my $count = scalar @{$by_type{$type}};
285 0 my $fixable = grep { can_auto_fix($_) } @{$by_type{$type}};
286 0 ▶ my $suffix = $fixable > 0 ? " ($fixable auto-fixable)" : '';
Branch: 1 branch
BranchTrueFalseTotal
$fixable > 0 ? : 0 0 0
287 0 say " • " . colored(['yellow'], "$type") . ": $count workflow(s) affected$suffix";
288 }
289  
290 0 say '';
291 0 say colored(['cyan'], "💡 Tip: ") . "Run " . colored(['bold'], "ghgen analyze --fix") .
292 " to automatically apply fixes";
293  
294 0 ▶ if (!$opts{estimate}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"estimate"}) 0 0 0
295 0 say colored(['cyan'], "💡 Tip: ") . "Run " . colored(['bold'], "ghgen analyze --estimate") .
296 " to see potential cost savings";
297 }
298 }
299  
300 0 ▶ exit(@all_issues ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
@all_issues ? : 0 0 0
301 }
302  
303 0 ▶sub list_types() {
Subroutine list_types: not called CC=2 SCAR=17.9
304 0 say colored(['bold cyan'], "Available workflow templates:");
305 0 say '';
306  
307 0 my %types = list_workflow_types();
308  
309 0 for my $type (sort keys %types) {
310 0 say " " . colored(['green'], sprintf("%-10s", $type)) . " - $types{$type}";
311 }
312  
313 0 say '';
314 0 say "Usage: ghgen generate --type=<type> [--output=<file>]";
315 0 say " or: ghgen generate --interactive";
316 }
317  
318 0 ▶sub interactive_select_type() {
Subroutine interactive_select_type: not called CC=5 SCAR=34.0
319 0 say colored(['bold cyan'], "GitHub Actions Workflow Generator");
320 0 say colored(['cyan'], "=" x 50);
321 0 say '';
322 0 say "Select a project type:";
323 0 say '';
324  
325 0 my @types = qw(node python rust go ruby perl java cpp php docker static);
326 0 my %descriptions = (
327 node => 'Node.js/npm',
328 python => 'Python',
329 rust => 'Rust',
330 go => 'Go',
331 ruby => 'Ruby',
332 perl => 'Perl',
333 java => 'Java (Maven/Gradle)',
334 cpp => 'C++ (CMake)',
335 php => 'PHP (Composer)',
336 docker => 'Docker',
337 static => 'Static site (GitHub Pages)',
338 );
339  
340 0 for my $i (0..$#types) {
341 0 say " " . colored(['green'], $i + 1) . ". $descriptions{$types[$i]}";
342 }
343  
344 0 say '';
345 0 print "Enter number (1-" . scalar(@types) . "): ";
346 0 chomp(my $choice = <STDIN>);
347  
348 0 ▶ if ($choice =~ /^\d+$/ && $choice >= 1 && $choice <= @types) {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types) 0 0 0
Condition0%0/6
$choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types
!ll&&!rl&&r
000
$choice =~ /^\d+$/u and $choice >= 1
!ll&&!rl&&r
000
MC/DC0%0/3
$choice =~ /^\d+$/u and $choice >= 1 and $choice <= @types
$choice =~ /^\d+$/u $choice >= 1 $choice <= @types
Truth table0%0/4
A and B and C
A= $choice =~ /^\d+$/uB= $choice >= 1C= $choice <= @types
ABCresult
0XX0
10X0
1100
1111
349 0 return $types[$choice - 1];
350 }
351  
352 0 die colored(['red'], 'Invalid choice');
353 }
354  
355 0 ▶sub auto_detect_with_prompt() {
Subroutine auto_detect_with_prompt: not called CC=12 SCAR=50.5
356 0 say colored(['bold cyan'], "Auto-detecting project type...");
357 0 say '';
358  
359 0 my @detections = detect_project_type();
360  
361 0 ▶ unless (@detections) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@detections) 0 0 0
362 0 say colored(['yellow'], "⚠ ") . "Could not auto-detect project type.";
363 0 say '';
364 0 say "Try one of these options:";
365 0 say " • " . colored(['cyan'], "ghgen generate --list") . " - see all available types";
366 0 say " • " . colored(['cyan'], "ghgen generate --interactive") . " - choose interactively";
367 0 say " • " . colored(['cyan'], "ghgen generate --type=<type>") . " - specify type directly";
368 0 return undef;
369 }
370  
371 # Show top detection
372 0 my $top = $detections[0];
373 0 ▶ if(!defined($top->{type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $top->{"type"}) 0 0 0
374 0 die "Cound't autodetect the project type";
375 }
376  
377 0 say colored(['green'], "✓ ") . 'Detected project type: ' . colored(['bold'], uc($top->{type}));
378  
379 # Show evidence
380 0 my $indicators = get_project_indicators($top->{type});
381 0 my @found_indicators;
382 0 for my $indicator (@$indicators) {
383 # Simple file check (not glob patterns)
384 0 ▶ if ($indicator !~ /[\*\?]/ && path($indicator)->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $indicator =~ /[\*\?]/u and path($indicator)->exists) 0 0 0
Condition0%0/3
not $indicator =~ /[\*\?]/u and path($indicator)->exists
!ll&&!rl&&r
000
MC/DC0%0/2
not $indicator =~ /[\*\?]/u and path($indicator)->exists
not $indicator =~ /[\*\?]/u path($indicator)->exists
Truth table0%0/3
not(A) and B
A= not $indicator =~ /[\*\?]/uB= path($indicator)->exists
ABresult
0X0
100
111
385 0 push @found_indicators, $indicator;
386 0 ▶ last if @found_indicators >= 3; # Show max 3
Branch: 1 branch
BranchTrueFalseTotal
if @found_indicators >= 3 0 0 0
387 }
388 }
389  
390 0 ▶ if (@found_indicators) {
Branch: 1 branch
BranchTrueFalseTotal
if (@found_indicators) 0 0 0
391 0 say colored(['cyan'], " Evidence: ") . join(', ', @found_indicators);
392 }
393 0 say '';
394  
395 # Show alternatives if any
396 0 ▶ if (@detections > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@detections > 1) 0 0 0
397 0 say colored(['yellow'], "Other possibilities:");
398 0 for my $i (1 .. min(2, $#detections)) {
399 0 say " • $detections[$i]->{type} (confidence: " . int($detections[$i]->{score} / $top->{score} * 100) . "%)";
400 }
401 0 say '';
402 }
403  
404 # Prompt for confirmation
405 0 print "Generate " . colored(['bold'], uc($top->{type})) . " workflow? [Y/n]: ";
406 0 chomp(my $response = <STDIN>);
407  
408 0 ▶ if ($response =~ /^(?:y(?:es)?)?$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response =~ /^(?:y(?:es)?)?$/iu) { } 0 0 0
elsif ($response =~ /^n(?:o)?$/iu) { } 0 0 0
409 0 return $top->{type};
410 } elsif ($response =~ /^n(?:o)?$/i) {
411 0 say '';
412 0 say "Cancelled. Use " . colored(['cyan'], "--interactive") . " to choose manually.";
413 0 return undef;
414 } else {
415 0 say colored(['red'], "Invalid response. Cancelled.");
416 0 return undef;
417 }
418 }
419  
420 0 ▶sub min($a, $b) {
Subroutine min: not called CC=2 SCAR=17.9
421 0 ▶ return $a < $b ? $a : $b;
Branch: 1 branch
BranchTrueFalseTotal
$a < $b ? : 0 0 0
422 }
423  
424 __END__
↑ Summary lib/App/GHGen/PerlCustomizer.pm »