CPAN/Maker/Bootstrapper/Role/LLM/Reviewer.pm

filter: Statementstmt 18.7% 46 / 246 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 62 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 57.6% 15 / 26 Podpod 0.0% 0 / 4 totaltotal 13.2% 61 / 461 CC 74 SCAR 56.3
CC
74
Cov
12%
_cmd_review
812.0
_get_review_prompt
182.0
cmd_code_finding
110.0
CRAP 277.9
« CPAN/Maker/Bootstrapper/Role/LLM/ReleaseNotes.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Critic.pm »
1 package CPAN::Maker::Bootstrapper::Role::LLM::Reviewer;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use open ':std', ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use CLI::Simple::Utils qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use CPAN::Maker::Bootstrapper::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Cwd qw(getcwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use File::Copy qw(copy);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 ########################################################################
22 0 ▶sub _get_review_prompt {
Subroutine _get_review_prompt: not called CC=13 SCAR=52.0
23 ########################################################################
24 0 my ( $self, $review_type, $review ) = @_;
25  
26 0 ▶ if ( !-d '.prompts' || !-e ".prompts/$review_type-review.prompt" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d ".prompts" and -e ".prompts/$review_type-review.prompt") 0 0 0
Condition0%0/3
-d ".prompts" and -e ".prompts/$review_type-review.prompt"
!ll&&!rl&&r
000
MC/DC0%0/2
-d ".prompts" and -e ".prompts/$review_type-review.prompt"
-d ".prompts" -e ".prompts/$review_type-review.prompt"
Truth table0%0/3
A and B
A= -d ".prompts"B= -e ".prompts/$review_type-review.prompt"
ABresult
0X0
100
111
27 0 $self->_install_prompts;
28 }
29  
30 0 ▶ my @prompts = ( $self->get_prompt // ".prompts/$review_type-review.prompt" );
Condition0%0/2
$self->get_prompt // ".prompts/$review_type-review.prompt"
l!l
00
MC/DC0%0/1
$self->get_prompt // ".prompts/$review_type-review.prompt"
$self->get_prompt
Truth table0%0/2
A
A= $self->get_prompt
Aresult
11
00
31 my @profiles
32 0 ▶ = $review && !$self->get_prompt_profile ? @{ $review->{prompt_profiles} // [] } : @{ $self->get_prompt_profile // [] };
Branch: 1 branch
BranchTrueFalseTotal
$review && !$self->get_prompt_profile ? : 0 0 0
Condition0%0/7
$review and not $self->get_prompt_profile
!ll&&!rl&&r
000
$review->{"prompt_profiles"} // []
l!l
00
$self->get_prompt_profile // []
l!l
00
MC/DC0%0/2
$review and not $self->get_prompt_profile
$review not $self->get_prompt_profile
MC/DC0%0/1
$review->{"prompt_profiles"} // []
$review->{"prompt_profiles"}
MC/DC0%0/1
$self->get_prompt_profile // []
$self->get_prompt_profile
Truth table0%0/3
A and not(B)
A= $reviewB= not $self->get_prompt_profile
ABresult
0X0
100
111
Truth table0%0/2
A
A= $review->{"prompt_profiles"}
Aresult
11
00
Truth table0%0/2
A
A= $self->get_prompt_profile
Aresult
11
00
33  
34 0 push @prompts, map {".prompts/$_.prompt"} @profiles;
35  
36 0 my $prompt = q{};
37  
38 0 foreach my $f (@prompts) {
39 0 ▶ my $abs_path = abs_path($f)
Branch: 1 branch
BranchTrueFalseTotal
my $abs_path = abs_path($f) or die "ERROR: $f not found\n" 0 0 0
40 or die "ERROR: $f not found\n";
41  
42 0 ▶ die "ERROR: $f is empty or not found\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $abs_path and -s $abs_path 0 0 0
Condition0%0/3
-e $abs_path and -s $abs_path
!ll&&!rl&&r
000
MC/DC0%0/2
-e $abs_path and -s $abs_path
-e $abs_path -s $abs_path
Truth table0%0/3
A and B
A= -e $abs_pathB= -s $abs_path
ABresult
0X0
100
111
43 if !-e $abs_path || !-s $abs_path;
44  
45 0 $prompt .= "\n" . slurp($abs_path);
46 }
47  
48 0 $prompt =~ s/^#[^\n]*(?:\n|\z)//xsmg;
49 0 $prompt =~ s/\n{2,}/\n/xsmg; # collapse 2+ blank lines to one
50 0 $prompt =~ s/\A\n+//xsm; # strip leading blank lines
51  
52 0 ▶ die "ERROR: prompt file prompt is essentially empty\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $prompt =~ /\S/msx 0 0 0
53 if $prompt !~ /\S/xsm;
54  
55 0 return $prompt;
56 }
57  
58 ########################################################################
59 0 ▶sub _install_prompts {
Subroutine _install_prompts: not called CC=5 SCAR=34.0
60 ########################################################################
61 0 my ($self) = @_;
62  
63 0 make_path('.prompts');
64  
65 0 ▶ die "ERROR: could not create .prompts directory\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d ".prompts" 0 0 0
66 if !-d '.prompts';
67  
68 0 my $dist_dir = $self->get_dist_dir;
69  
70 0 for my $type (qw(code pod)) {
71 0 my $file = "$type-review.prompt";
72 0 my $dest = ".prompts/$file";
73  
74 0 ▶ next if -e $dest;
Branch: 1 branch
BranchTrueFalseTotal
if -e $dest 0 0 0
75  
76 0 ▶ copy "$dist_dir/$file", $dest
Branch: 1 branch
BranchTrueFalseTotal
copy("$dist_dir/$file", $dest) or die "ERROR: could not install $file to .prompts/: $CPAN::Maker::Bootstrapper::Role::LLM::Reviewer::OS_ERROR\n" 0 0 0
77 or die "ERROR: could not install $file to .prompts/: $OS_ERROR\n";
78  
79 0 print "Installed default prompt: $dest\n";
80 }
81  
82 0 print "\nEdit these files to customize your review prompts.\n";
83 0 print "Set code-review-prompt or pod-review-prompt in your\n";
84 0 print "config to use prompts from an explicit path.\n\n";
85  
86 0 return;
87 }
88  
89 ########################################################################
90 0 ▶sub _get_latest_review {
Subroutine _get_latest_review: not called CC=3 SCAR=24.8
91 ########################################################################
92 0 my ( $self, $file, $review_type ) = @_;
93  
94 0 my $name = basename($file);
95 0 $name =~ s/[.]in\z//xsm;
96 0 $name =~ s/[.][^.]+\z//xsm;
97  
98 0 my @review_files;
99  
100 find(
101 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
102 0 ▶ return if !-f $File::Find::name;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $File::Find::name 0 0 0
103 0 ▶ return if $_ !~ /^\Q$name\E-review.*[.]\Q$review_type\E$/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /^\Q$name\E-review.*[.]\Q$review_type\E$/msx 0 0 0
104 0 push @review_files, $File::Find::name;
105 },
106 0 getcwd,
107 );
108  
109 0 my ($review_file) = reverse sort { $a cmp $b } @review_files;
110  
111 return ( undef, undef )
112 0 ▶ if !$review_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $review_file 0 0 0
113  
114 0 my $content = slurp $review_file;
115  
116 0 ▶ die "ERROR: no content for $review_file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless length $content 0 0 0
117 if !length $content;
118  
119 0 my $review = JSON->new->decode($content);
120  
121 0 return ( $review, $review_file );
122 }
123  
124 ########################################################################
125 0 ▶sub cmd_pod_finding {
Subroutine cmd_pod_finding: not called CC=3 SCAR=24.8
Pod undocumented
126 ########################################################################
127 0 my ($self) = @_;
128  
129 0 $self->_load_ASCIITable;
130  
131 0 my ($file) = $self->get_args;
132  
133 0 my ( $review, $review_file ) = $self->_get_latest_review( $file, 'pod' );
134  
135 0 ▶ die "ERROR: no findings for $file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $review and $review_file 0 0 0
Condition0%0/3
$review and $review_file
!ll&&!rl&&r
000
MC/DC0%0/2
$review and $review_file
$review $review_file
Truth table0%0/3
A and B
A= $reviewB= $review_file
ABresult
0X0
100
111
136 if !$review || !$review_file;
137  
138 0 $self->_show_pod_findings( $review, $review_file );
139  
140 0 return $SUCCESS;
141 }
142  
143 ########################################################################
144 0 ▶sub _show_pod_findings {
Subroutine _show_pod_findings: not called CC=9 SCAR=45.0
145 ########################################################################
146 0 my ( $self, $review, $review_file ) = @_;
147  
148 0 ▶ my $mode = $review->{mode} // 'review';
Condition0%0/2
$review->{"mode"} // "review"
l!l
00
MC/DC0%0/1
$review->{"mode"} // "review"
$review->{"mode"}
Truth table0%0/2
A
A= $review->{"mode"}
Aresult
11
00
149 0 ▶ my $findings = $review->{findings} // [];
Condition0%0/2
$review->{"findings"} // []
l!l
00
MC/DC0%0/1
$review->{"findings"} // []
$review->{"findings"}
Truth table0%0/2
A
A= $review->{"findings"}
Aresult
11
00
150  
151 0 ▶ if ( $mode eq 'generate' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "generate") 0 0 0
152 0 printf {*STDOUT} "Mode: POD generation\n\n";
153 }
154  
155 0 my $t = Text::ASCIITable->new( { headingText => "POD Review: $review_file" } );
156  
157 0 $t->setCols( 'ID', 'Section/Method', 'Severity', 'Description' );
158 0 $t->setColWidth( 'ID', 4 );
159 0 $t->setColWidth( 'Section/Method', 30 );
160 0 $t->setColWidth( 'Severity', 12 );
161 0 $t->setColWidth( 'Description', 40 );
162  
163 0 ▶ if ( !@{$findings} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$findings;}) 0 0 0
164 0 print {*STDOUT} "No findings.\n\n";
165 0 return;
166 }
167  
168 0 foreach my $f ( sort { $a->{id} <=> $b->{id} } @{$findings} ) {
169 0 ▶ my $location = $f->{method} // $f->{section} // '-';
Condition0%0/5
($f->{"method"} // $f->{"section"}) // "-"
l!l
00
$f->{"method"} // $f->{"section"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($f->{"method"} // $f->{"section"}) // "-"
$f->{"method"} $f->{"section"}
Truth table0%0/3
A // B
A= $f->{"method"}B= $f->{"section"}
ABresult
1X1
011
000
170 0 my $severity = $f->{severity};
171  
172 0 $t->addRow( $f->{id}, $location, $severity, $f->{description} );
173 0 $t->addRow( q{}, q{}, q{}, "\nDetail:\n\n" . $f->{detail} );
174 0 $t->addRow( q{}, q{}, q{}, "\nSuggestion:\n\n" . $f->{suggestion} );
175 0 $t->addRowLine;
176 }
177  
178 0 print {*STDOUT} $t;
179  
180 0 ▶ printf {*STDOUT} "%d finding%s.\n\n", scalar @{$findings}, scalar @{$findings} == 1 ? q{} : 's';
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$findings;} == 1 ? : 0 0 0
181  
182 0 return;
183 }
184  
185 ########################################################################
186 0 ▶sub cmd_code_review {
Subroutine cmd_code_review: not called CC=5 SCAR=34.0
Pod undocumented
187 ########################################################################
188 0 my ($self) = @_;
189  
190 0 $self->_load_ASCIITable;
191  
192 0 my ( $file, $api_key ) = $self->get_args;
193  
194 0 my ( $review, $review_file ) = $self->_get_latest_review( $file, 'code' );
195  
196 0 ▶ die "ERROR: set all disposition statuses before resubmitting a review\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_annotation_dispositions($review) 0 0 0
197 if !$self->_check_annotation_dispositions($review);
198  
199 my $llm_rsp = $self->_cmd_review(
200 type => 'code',
201 file => $file,
202 review => $review,
203 0 ▶ model => $review && $review->{model} ? $review->{model} : $DEFAULT_CODE_REVIEW_MODEL,
Branch: 1 branch
BranchTrueFalseTotal
$review && $review->{'model'} ? : 0 0 0
Condition0%0/3
$review and $review->{"model"}
!ll&&!rl&&r
000
MC/DC0%0/2
$review and $review->{"model"}
$review $review->{"model"}
Truth table0%0/3
A and B
A= $reviewB= $review->{"model"}
ABresult
0X0
100
111
204 api_key => $api_key,
205 context_files => $self->get_context,
206 );
207  
208 0 ▶ return $FAILURE
Branch: 1 branch
BranchTrueFalseTotal
unless $llm_rsp 0 0 0
209 if !$llm_rsp;
210  
211 0 $self->_print_token_usage( $llm_rsp, 'Code Review: Token Usage Report' );
212  
213 0 return $SUCCESS;
214 }
215  
216 ########################################################################
217 0 ▶sub cmd_pod_review {
Subroutine cmd_pod_review: not called CC=4 SCAR=30.0
Pod undocumented
218 ########################################################################
219 0 my ($self) = @_;
220  
221 0 $self->_load_ASCIITable;
222  
223 0 my ( $file, $api_key ) = $self->get_args;
224  
225 0 my ( $review, $review_file ) = $self->_get_latest_review( $file, 'pod' );
226  
227 my $llm_rsp = $self->_cmd_review(
228 type => 'pod',
229 file => $file,
230 api_key => $api_key,
231 0 ▶ model => $review && $review->{model} ? $review->{model} : $DEFAULT_POD_REVIEW_MODEL,
Branch: 1 branch
BranchTrueFalseTotal
$review && $review->{'model'} ? : 0 0 0
Condition0%0/3
$review and $review->{"model"}
!ll&&!rl&&r
000
MC/DC0%0/2
$review and $review->{"model"}
$review $review->{"model"}
Truth table0%0/3
A and B
A= $reviewB= $review->{"model"}
ABresult
0X0
100
111
232 );
233  
234 0 ▶ return $FAILURE
Branch: 1 branch
BranchTrueFalseTotal
unless $llm_rsp 0 0 0
235 if !$llm_rsp;
236  
237 0 $self->_print_token_usage( $llm_rsp, 'POD Review: Token Usage Report' );
238  
239 0 return $SUCCESS;
240 }
241  
242 ########################################################################
243 0 ▶sub _cmd_review {
Subroutine _cmd_review: not called CC=28 SCAR=67.0
244 ########################################################################
245 0 my ( $self, %args ) = @_;
246  
247 0 my ( $review_type, $api_key, $default_model ) = @args{qw(type api_key model)};
248  
249 0 my ( $file, $review, $context_files ) = @args{qw(file review context_files)};
250  
251 0 ▶ my $model = $self->get_model // $default_model;
Condition0%0/3
$self->get_model // $default_model
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_model // $default_model
$self->get_model $default_model
Truth table0%0/3
A // B
A= $self->get_modelB= $default_model
ABresult
1X1
011
000
252  
253 warn sprintf "WARNING: model changed from %s => %s\n", $review->{model}, $model
254 0 ▶ if $review && $review->{model} && $model ne $review->{model};
Branch: 1 branch
BranchTrueFalseTotal
if $review and $review->{"model"} and $model ne $review->{"model"} 0 0 0
Condition0%0/6
$review and $review->{"model"} and $model ne $review->{"model"}
!ll&&!rl&&r
000
$review and $review->{"model"}
!ll&&!rl&&r
000
MC/DC0%0/3
$review and $review->{"model"} and $model ne $review->{"model"}
$review $review->{"model"} $model ne $review->{"model"}
Truth table0%0/4
A and B and C
A= $reviewB= $review->{"model"}C= $model ne $review->{"model"}
ABCresult
0XX0
10X0
1100
1111
255  
256 0 $self->set_model($model);
257  
258 0 ▶ my @context_files = $review && !$context_files ? @{ $review->{context} // [] } : @{ $context_files // [] };
Branch: 1 branch
BranchTrueFalseTotal
$review && !$context_files ? : 0 0 0
Condition0%0/7
$review and not $context_files
!ll&&!rl&&r
000
$review->{"context"} // []
l!l
00
$context_files // []
l!l
00
MC/DC0%0/2
$review and not $context_files
$review not $context_files
MC/DC0%0/1
$review->{"context"} // []
$review->{"context"}
MC/DC0%0/1
$context_files // []
$context_files
Truth table0%0/3
A and not(B)
A= $reviewB= not $context_files
ABresult
0X0
100
111
Truth table0%0/2
A
A= $review->{"context"}
Aresult
11
00
Truth table0%0/2
A
A= $context_files
Aresult
11
00
259  
260 0 foreach my $f ( grep {defined} ( $file, @context_files ) ) {
261 0 my $abs_path = abs_path($f);
262  
263 0 ▶ die "ERROR: file [$f] not found or empty.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $abs_path and -e $abs_path and -s $abs_path 0 0 0
Condition0%0/6
$abs_path and -e $abs_path and -s $abs_path
!ll&&!rl&&r
000
$abs_path and -e $abs_path
!ll&&!rl&&r
000
MC/DC0%0/3
$abs_path and -e $abs_path and -s $abs_path
$abs_path -e $abs_path -s $abs_path
Truth table0%0/4
A and B and C
A= $abs_pathB= -e $abs_pathC= -s $abs_path
ABCresult
0XX0
10X0
1100
1111
264 if !$abs_path || !-e $abs_path || !-s $abs_path;
265 }
266  
267 0 my $llm = $self->_check_llm($api_key);
268  
269 0 my $prompt_str = $self->_get_review_prompt( $review_type, $review );
270  
271 0 my @prompt;
272  
273 0 push @prompt, $llm->text($prompt_str);
274  
275 0 ▶ my $text = $review_type eq 'pod' ? slurp( abs_path($file) ) : $self->_strip_pod( slurp( abs_path($file) ) );
Branch: 1 branch
BranchTrueFalseTotal
$review_type eq 'pod' ? : 0 0 0
276  
277 0 ▶ my $title = $review_type eq 'pod' ? basename($file) : 'primary: ' . basename($file);
Branch: 1 branch
BranchTrueFalseTotal
$review_type eq 'pod' ? : 0 0 0
278  
279 0 push @prompt,
280 $llm->document(
281 data => $text,
282 title => $title,
283 );
284  
285 0 foreach my $f (@context_files) {
286 0 push @prompt,
287 $llm->document(
288 data => $self->_strip_pod($f),
289 title => 'context:' . basename($f),
290 );
291 }
292  
293 0 ▶ if ($review) {
Branch: 1 branch
BranchTrueFalseTotal
if ($review) 0 0 0
294 0 push @prompt,
295 $llm->document(
296 data => JSON->new->utf8->encode($review),
297 title => 'annotations:' . basename($file),
298 );
299 }
300  
301 0 my ( $input_tokens, $input_cost ) = $llm->count_input_tokens( \@prompt );
302  
303 0 ▶ $self->_pre_submission_report(
Branch: 1 branch
BranchTrueFalseTotal
$review ? : 0 0 0
304 type => $review_type,
305 prompt => $prompt_str,
306 text => $text,
307 annotations => $review ? JSON->new->utf8->encode($review) : undef,
308 context_files => \@context_files,
309 max_tokens => $self->get_max_tokens,
310 input_tokens => $input_tokens,
311 input_cost => $input_cost,
312 );
313  
314 0 ▶ return $SUCCESS
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_dry_run 0 0 0
315 if $self->get_dry_run;
316  
317 0 my $llm_rsp = $self->_submit_prompt( $llm, \@prompt );
318 0 my $content = $llm_rsp->content;
319  
320 0 ▶ die "ERROR: no content object returned by LLM\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
321 if !$content;
322  
323 0 ▶ if ( !$content->text ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content->text) 0 0 0
324 0 warn "WARNING: LLM did not return any text from request.\n";
325 0 return;
326 }
327  
328 0 ▶ if ( $llm_rsp->was_cutoff ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llm_rsp->was_cutoff) 0 0 0
329 0 warn "WARNING: response was truncated (hit max_tokens). Increase --max-tokens for a complete response.\n";
330 }
331  
332 0 my $name = basename($file);
333 0 $name =~ s/[.].*$//xsm;
334  
335 0 my ( $sec, $min, $hour, $day, $month, $year ) = localtime;
336 0 $year += 1900;
337 0 $month++;
338  
339 0 my $ts = sprintf '%04d-%02d-%02d-%02d%02d%02d', $year, $month, $day, $hour, $min, $sec;
340  
341 0 my $review_file = sprintf '%s-review-%s.%s', $name, $ts, $review_type;
342  
343 0 my $json_text = $content->text;
344 0 $json_text =~ s/\A\s*```(?:json)?\s*\n?//xsm;
345 0 $json_text =~ s/\s*```\s*\z//xsm;
346  
347 0 $review = eval { JSON->new->decode($json_text); };
348  
349 0 ▶ die "ERROR: unable to decode JSON\n$EVAL_ERROR\nresponse was:\n" . $content->text
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Maker::Bootstrapper::Role::LLM::Reviewer::EVAL_ERROR 0 0 0
350 if $EVAL_ERROR;
351  
352 0 $review->{model} = $self->get_model; # save for next time
353  
354 0 ▶ if ( $review_type eq 'code' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($review_type eq "code") 0 0 0
355  
356 0 ▶ if ( $self->get_prompt_profile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_prompt_profile) 0 0 0
357 0 $review->{prompt_profiles} = $self->get_prompt_profile;
358 }
359  
360 0 ▶ if ( $self->get_context ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_context) 0 0 0
361 0 $review->{context} = $self->get_context;
362 }
363 }
364  
365 0 ▶ open my $fh, '>', $review_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $review_file or die "ERROR: could not open $review_file for writing.\n$CPAN::Maker::Bootstrapper::Role::LLM::Reviewer::OS_ERROR" 0 0 0
366 or die "ERROR: could not open $review_file for writing.\n$OS_ERROR";
367  
368 0 print {$fh} JSON->new->utf8->pretty->encode($review);
369  
370 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "WARNING: could not close ${review_file}: $CPAN::Maker::Bootstrapper::Role::LLM::Reviewer::OS_ERROR" 0 0 0
371 or warn "WARNING: could not close $review_file: $OS_ERROR";
372  
373 0 return $llm_rsp;
374 }
375  
376 ########################################################################
377 0 ▶sub cmd_code_finding {
Subroutine cmd_code_finding: not called CC=10 SCAR=47.0
Pod undocumented
378 ########################################################################
379 0 my ($self) = @_;
380  
381 0 $self->_load_ASCIITable;
382  
383 0 my ( $file, $finding_id ) = $self->get_args;
384  
385 0 ▶ die "ERROR: file argument is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
386 if !$file;
387  
388 0 ▶ die "ERROR: finding ID is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $finding_id 0 0 0
389 if !$finding_id;
390  
391 0 ▶ die "ERROR: finding ID must be a positive integer\n"
Branch: 1 branch
BranchTrueFalseTotal
if not $finding_id =~ /^\d+$/msx or $finding_id < 1 0 0 0
Condition0%0/3
not $finding_id =~ /^\d+$/msx or $finding_id < 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not $finding_id =~ /^\d+$/msx or $finding_id < 1
not $finding_id =~ /^\d+$/msx $finding_id < 1
Truth table0%0/3
not(A) or B
A= not $finding_id =~ /^\d+$/msxB= $finding_id < 1
ABresult
1X1
011
000
392 if $finding_id !~ /^\d+$/xsm || $finding_id < 1;
393  
394 0 ▶ die "ERROR: $file not found or inaccessible\n"
Branch: 1 branch
BranchTrueFalseTotal
unless abs_path($file) 0 0 0
395 if !abs_path($file);
396  
397 0 my ( $review, $review_file ) = $self->_get_latest_review( $file, 'code' );
398  
399 0 ▶ die "ERROR: no review file found for $file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $review 0 0 0
400 if !$review;
401  
402 0 my ($finding) = grep { $_->{id} == $finding_id } @{ $review->{findings} };
403  
404 0 ▶ die "ERROR: finding $finding_id not found in $review_file\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $finding 0 0 0
405 if !$finding;
406  
407 0 my $total = scalar @{ $review->{findings} };
408  
409 0 my $t = Text::ASCIITable->new( { headingText => sprintf 'Finding %d of %d - %s', $finding_id, $total, $review_file } );
410  
411 0 $t->setCols( 'Field', 'Value' );
412 0 $t->setColWidth( 'Field', 16 );
413 0 $t->setColWidth( 'Value', 56 );
414 0 ▶ $t->alignCol( Value => sub { return sprintf '%-56s', shift; } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
415  
416 0 $t->addRow( 'ID', $finding->{id} );
417 0 $t->addRow( 'Function', $finding->{function} );
418 0 $t->addRow( 'Severity', $finding->{severity} );
419 0 ▶ $t->addRow( 'Disposition', $finding->{disposition} // '-' );
Condition0%0/2
$finding->{"disposition"} // "-"
l!l
00
MC/DC0%0/1
$finding->{"disposition"} // "-"
$finding->{"disposition"}
Truth table0%0/2
A
A= $finding->{"disposition"}
Aresult
11
00
420 0 ▶ $t->addRow( 'Comment', $finding->{comment} // '-' );
Condition0%0/2
$finding->{"comment"} // "-"
l!l
00
MC/DC0%0/1
$finding->{"comment"} // "-"
$finding->{"comment"}
Truth table0%0/2
A
A= $finding->{"comment"}
Aresult
11
00
421 0 $t->addRowLine;
422 0 $t->addRow( 'Description', $finding->{description} );
423 0 $t->addRowLine;
424 0 $t->addRow( 'Excerpt', $finding->{excerpt} );
425 0 $t->addRowLine;
426 0 $t->addRow( 'Detail', $finding->{detail} );
427  
428 0 print {*STDOUT} $t;
429  
430 0 return $SUCCESS;
431 }
432  
433 2 1;
434  
435 __END__
« CPAN/Maker/Bootstrapper/Role/LLM/ReleaseNotes.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Critic.pm »