« 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
Condition0%0/3
-d ".prompts" and -e ".prompts/$review_type-review.prompt"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$self->get_prompt // ".prompts/$review_type-review.prompt"
$self->get_prompt
Truth table0%0/2
A
A= $self->get_prompt
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | my @profiles | ||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | = $review && !$self->get_prompt_profile ? @{ $review->{prompt_profiles} // [] } : @{ $self->get_prompt_profile // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/7
$review and not $self->get_prompt_profile
$review->{"prompt_profiles"} // []
$self->get_prompt_profile // []
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
Truth table0%0/2
A
A= $review->{"prompt_profiles"}
Truth table0%0/2
A
A= $self->get_prompt_profile
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | or die "ERROR: $f not found\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | die "ERROR: $f is empty or not found\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $abs_path and -s $abs_path
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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | copy "$dist_dir/$file", $dest | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return if $_ !~ /^\Q$name\E-review.*[.]\Q$review_type\E$/xsm; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $content = slurp $review_file; | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | die "ERROR: no content for $review_file\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$review and $review_file
MC/DC0%0/2
$review and $review_file
$review
$review_file
Truth table0%0/3
A and B
A= $reviewB= $review_file
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$review->{"mode"} // "review"
$review->{"mode"}
Truth table0%0/2
A
A= $review->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $findings = $review->{findings} // []; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$review->{"findings"} // []
MC/DC0%0/1
$review->{"findings"} // []
$review->{"findings"}
Truth table0%0/2
A
A= $review->{"findings"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ( $mode eq 'generate' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}) // "-"
$f->{"method"} // $f->{"section"}
MC/DC0%0/2
($f->{"method"} // $f->{"section"}) // "-"
$f->{"method"}
$f->{"section"}
Truth table0%0/3
A // B
A= $f->{"method"}B= $f->{"section"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$review and $review->{"model"}
MC/DC0%0/2
$review and $review->{"model"}
$review
$review->{"model"}
Truth table0%0/3
A and B
A= $reviewB= $review->{"model"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | api_key => $api_key, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | context_files => $self->get_context, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return $FAILURE | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$review and $review->{"model"}
MC/DC0%0/2
$review and $review->{"model"}
$review
$review->{"model"}
Truth table0%0/3
A and B
A= $reviewB= $review->{"model"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | return $FAILURE | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$review and $review->{"model"} and $model ne $review->{"model"}
$review and $review->{"model"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->set_model($model); | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my @context_files = $review && !$context_files ? @{ $review->{context} // [] } : @{ $context_files // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/7
$review and not $context_files
$review->{"context"} // []
$context_files // []
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
Truth table0%0/2
A
A= $review->{"context"}
Truth table0%0/2
A
A= $context_files
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$abs_path and -e $abs_path and -s $abs_path
$abs_path and -e $abs_path
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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $title = $review_type eq 'pod' ? basename($file) : 'primary: ' . basename($file); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | if !$content; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ( !$content->text ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if ( $self->get_prompt_profile ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $review->{prompt_profiles} = $self->get_prompt_profile; | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ( $self->get_context ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $review->{context} = $self->get_context; | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | open my $fh, '>', $review_file | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | if !$file; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | die "ERROR: finding ID is required\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | if !$finding_id; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | die "ERROR: finding ID must be a positive integer\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $finding_id =~ /^\d+$/msx or $finding_id < 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | if $finding_id !~ /^\d+$/xsm || $finding_id < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | die "ERROR: $file not found or inaccessible\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // "-"
MC/DC0%0/1
$finding->{"disposition"} // "-"
$finding->{"disposition"}
Truth table0%0/2
A
A= $finding->{"disposition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | $t->addRow( 'Comment', $finding->{comment} // '-' ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$finding->{"comment"} // "-"
MC/DC0%0/1
$finding->{"comment"} // "-"
$finding->{"comment"}
Truth table0%0/2
A
A= $finding->{"comment"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||