« CPAN/Maker/Bootstrapper/Role/LLM/Models.pm
↑ Summary
CPAN/Maker/Bootstrapper/Role/ResolveVars.pm »
| 1 | package CPAN::Maker::Bootstrapper::Role::LLM::Annotator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # implements cmd_annotate, cmd_update_annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use open ':std', ':encoding(UTF-8)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use CLI::Simple::Constants qw(:booleans); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use CLI::Simple::Utils qw(slurp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use CPAN::Maker::Bootstrapper::Constants qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Cwd qw(getcwd abs_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use File::Temp qw(tempfile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use List::Util qw(none); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub cmd_update_annotations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_update_annotations: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $self->_load_ASCIITable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my ($file) = $self->get_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | die "ERROR: file argument is required\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | if !$file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | die "ERROR: $file not found or inaccessible\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | if !abs_path($file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ( $review, $review_file ) = $self->_get_latest_review( $file, 'code' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | die "ERROR: no review file found 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | if !$review || !$review_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ( my $annotate_file = $review_file ) =~ s/[.]\w+\z/.annotate/xsm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( !-e $annotate_file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $generated = $self->_generate_annotate_file( $review, $review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | printf {*STDOUT} "Generated %s - edit and re-run to apply.\n", $generated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $parsed = $self->_parse_annotate_file($annotate_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $applied = $self->_apply_annotate_file( $review, $parsed ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ( $fh, $tempfile ) = tempfile( 'annotations-XXXX', DIR => getcwd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | die "ERROR: could not create temporary annotations file\n$OS_ERROR\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | if !$fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | print {$fh} JSON->new->pretty->utf8->encode($review); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | or die "ERROR: could not close temporary annotations file\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | rename $tempfile, $review_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | or die "ERROR: could not save $review_file\n$OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | printf {*STDOUT} "Applied %d disposition%s from %s\n\n", $applied, $applied == 1 ? q{} : 's', $annotate_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->_show_annotations( $review, $review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub cmd_annotate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_annotate: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $self->_load_ASCIITable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ( $file, $api_key ) = $self->get_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | die "ERROR: $file is a required argument\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | if !$file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | die "ERROR: $file not found or inaccessible\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | if !abs_path($file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ( $review, $review_file ) = $self->_get_latest_review( $file, 'code' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | die "ERROR: nothing to annotate. No review file found.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | if !$review_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # only save if things have changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ( $self->_annotate($review) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my ( $fh, $tempfile ) = tempfile( 'annotations-XXXX', DIR => getcwd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | die "ERROR: could not create temporary annotations file\n$OS_ERROR\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | if !$fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | print {$fh} JSON->new->pretty->utf8->encode($review); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | or die "ERROR: could not close temporary annotations file!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | rename $tempfile, $review_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | or die "ERROR: could not save $review_file\n$OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->_show_annotations( $review, $review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $self->get_finalize_annotations ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->_finalize_annotations( $review, $review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | elsif ( $self->get_auto_annotate ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # resubmit for review | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | my $llm_rsp = $self->_cmd_review( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | type => 'code', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | review => $review, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | model => $review->{model} // $DEFAULT_CODE_REVIEW_MODEL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$review->{"model"} // $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DEFAULT_CODE_REVIEW_MODEL
MC/DC0%0/2
$review->{"model"} // $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DEFAULT_CODE_REVIEW_MODEL
$review->{"model"}
$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DEFAULT_CODE_REVIEW_MODEL
Truth table0%0/3
A // B
A= $review->{"model"}B= $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DEFAULT_CODE_REVIEW_MODEL
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | api_key => $api_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | context_files => $self->get_context, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return $FAILURE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | if !$llm_rsp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->_print_token_usage( $llm_rsp, 'Code Review: Token Usage Report' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # keep .annotate file in sync with review JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( -e ( my $annotate_file = $review_file =~ s/[.]\w+\z/.annotate/xsmr ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->_generate_annotate_file( $review, $review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub _show_annotations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_annotations: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ( $self, $review, $review_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $color_on = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | require Term::ANSI::Color; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | Term::ANSIColor->import('colored'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | $color_on = $color_on && $self->get_color; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$color_on && $self->get_color
MC/DC0%0/2
$color_on && $self->get_color
$color_on
$self->get_color
Truth table0%0/3
A && B
A= $color_onB= $self->get_color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $t = Text::ASCIITable->new( { headingText => "Annotations: $review_file", allowANSI => $color_on } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $t->setCols( 'ID', 'Function', 'Severity', 'Disposition', 'Description' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $t->setColWidth( 'ID', 4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $t->setColWidth( 'Function', 30 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $t->setColWidth( 'Severity', $color_on ? 20 : 12 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $t->setColWidth( 'Disposition', $color_on ? 20 : 12 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $t->setColWidth( 'Description', 40 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $pending = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | foreach my $f ( sort { $a->{id} <=> $b->{id} } @{$findings} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $disposition = $f->{disposition} // q{-}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{"disposition"} // "-"
MC/DC0%0/1
$f->{"disposition"} // "-"
$f->{"disposition"}
Truth table0%0/2
A
A= $f->{"disposition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( $disposition eq q{-} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $pending++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $severity = $f->{severity}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | $t->addRow( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | $f->{id}, $f->{function}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $color_on ? colored( [ $COLORS->{$severity} // 'white' ], $severity ) : $severity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | $color_on ? colored( [ $COLORS->{ uc $disposition } // 'white' ], $disposition ) : $disposition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | $f->{description}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/4
$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS->{$severity} // "white"
$$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS{uc $disposition} // "white"
MC/DC0%0/1
$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS->{$severity} // "white"
$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS->{$severity}
MC/DC0%0/1
$$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS{uc $disposition} // "white"
$$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS{uc $disposition}
Truth table0%0/2
A
A= $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS->{$severity}
Truth table0%0/2
A
A= $$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::COLORS{uc $disposition}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | print {*STDOUT} $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $total = scalar @{$findings}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $applied = $total - $pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | printf {*STDOUT} "%d of %d annotated. %d pending.\n\n", $applied, $total, $pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub _generate_annotate_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_annotate_file: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my ( $self, $review, $review_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ( my $annotate_file = $review_file ) =~ s/[.]\w+\z/.annotate/xsm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | open my $fh, '>', $annotate_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | or die "ERROR: could not open $annotate_file for writing\n$OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | printf {$fh} "# source: %s\n", $review_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | printf {$fh} "# model: %s\n", $review->{model} // 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$review->{"model"} // "unknown"
MC/DC0%0/1
$review->{"model"} // "unknown"
$review->{"model"}
Truth table0%0/2
A
A= $review->{"model"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | printf {$fh} "# Dispositions: %s\n\n", join q{ }, sort keys %{$DISPOSITIONS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | foreach my $f ( sort { $a->{id} <=> $b->{id} } @{ $review->{findings} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | printf {$fh} "[%d]\n", $f->{id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | printf {$fh} "# %s | %s\n", $f->{function} // 'unknown', $f->{severity}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{"function"} // "unknown"
MC/DC0%0/1
$f->{"function"} // "unknown"
$f->{"function"}
Truth table0%0/2
A
A= $f->{"function"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | printf {$fh} "# %s\n", $f->{description}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | printf {$fh} "disposition: %s\n", $f->{disposition} // q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{"disposition"} // ""
MC/DC0%0/1
$f->{"disposition"} // ""
$f->{"disposition"}
Truth table0%0/2
A
A= $f->{"disposition"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | printf {$fh} "comment: %s\n\n", $f->{comment} // q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{"comment"} // ""
MC/DC0%0/1
$f->{"comment"} // ""
$f->{"comment"}
Truth table0%0/2
A
A= $f->{"comment"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | or warn "WARNING: could not close $annotate_file: $OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return $annotate_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub _parse_annotate_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_annotate_file: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ( $self, $annotate_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | open my $fh, '<', $annotate_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | or die "ERROR: could not open $annotate_file for reading\n$OS_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my %parsed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | my $current_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my @comment_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | next if $line =~ /\A#/xsm; # skip comment lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | next if $line =~ /\A\s*\z/xsm && !defined $current_id; # skip leading blanks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$line =~ /\A\s*\z/msx and not defined $current_id
MC/DC0%0/2
$line =~ /\A\s*\z/msx and not defined $current_id
$line =~ /\A\s*\z/msx
not defined $current_id
Truth table0%0/3
A and not(B)
A= $line =~ /\A\s*\z/msxB= not defined $current_id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ( $line =~ /\A\[(\d+)\]\z/xsm ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ( defined $current_id ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $parsed{$current_id}{comment} = join "\n", @comment_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $current_id = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | @comment_lines = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $parsed{$current_id} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | next if !defined $current_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ( $line =~ /\Adisposition:\s*(.*)\z/xsm ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $d = uc $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $parsed{$current_id}{disposition} = $d if length $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ( $line =~ /\Acomment:\s*(.*)\z/xsm ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | push @comment_lines, $1 if length $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # continuation line for comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ( $line =~ /\A\s+(.*)\z/xsm ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | push @comment_lines, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # flush final section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( defined $current_id ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $parsed{$current_id}{comment} = join "\n", @comment_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | or warn "WARNING: could not close $annotate_file: $OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return \%parsed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub _apply_annotate_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_annotate_file: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ( $self, $review, $parsed ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $applied = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | foreach my $f ( @{ $review->{findings} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | my $entry = $parsed->{ $f->{id} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ( my $d = $entry->{disposition} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | die sprintf "ERROR: invalid disposition '%s' for finding %d\n", $d, $f->{id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if !$DISPOSITIONS->{$d}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $f->{disposition} = $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $applied++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # only overwrite comment if the file supplied one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ( defined $entry->{comment} && length $entry->{comment} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $entry->{"comment"} and length $entry->{"comment"}
MC/DC0%0/2
defined $entry->{"comment"} and length $entry->{"comment"}
defined $entry->{"comment"}
length $entry->{"comment"}
Truth table0%0/3
A and B
A= defined $entry->{"comment"}B= length $entry->{"comment"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $f->{comment} = $entry->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return $applied; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub _annotate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_annotate: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my ( $self, $review ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my @annotations = @{ $self->get_annotate || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_annotate || []
MC/DC0%0/1
$self->get_annotate || []
$self->get_annotate
Truth table0%0/2
A
A= $self->get_annotate
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if !@annotations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $batch_comment = $self->get_comment; # may be undef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | foreach my $a (@annotations) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my ( $finding, $disposition, $inline_comment ) = split /:/, $a, 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $disposition = uc $disposition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | die sprintf "ERROR: invalid disposition, must be n:{disposition} where disposition=%s\n", join q{|}, keys %{$DISPOSITIONS} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if !$finding || $finding !~ /^\d+$/xsm || !$disposition || !$DISPOSITIONS->{$disposition}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$finding and $finding =~ /^\d+$/msx and $disposition and $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DISPOSITIONS->{$disposition}
$finding and $finding =~ /^\d+$/msx and $disposition
$finding and $finding =~ /^\d+$/msx
MC/DC0%0/4
$finding and $finding =~ /^\d+$/msx and $disposition and $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DISPOSITIONS->{$disposition}
$finding
$finding =~ /^\d+$/msx
$disposition
$CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DISPOSITIONS->{$disposition}
Truth table0%0/5
A and B and C and D
A= $findingB= $finding =~ /^\d+$/msxC= $dispositionD= $CPAN::Maker::Bootstrapper::Role::LLM::Annotator::DISPOSITIONS->{$disposition}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # inline comment beats --comment; --comment beats preserve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my $comment = $inline_comment // $batch_comment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$inline_comment // $batch_comment
MC/DC0%0/2
$inline_comment // $batch_comment
$inline_comment
$batch_comment
Truth table0%0/3
A // B
A= $inline_commentB= $batch_comment
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $self->_set_finding_disposition( $review, $finding, $disposition, $comment ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return $review; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub _set_finding_disposition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_finding_disposition: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ( $self, $review, $finding, $disposition, $comment ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $findings = $review->{findings}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if !$findings || !@{$findings}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$findings and @{$findings;}
MC/DC0%0/2
$findings and @{$findings;}
$findings
@{$findings;}
Truth table0%0/3
A and B
A= $findingsB= @{$findings;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | foreach my $f ( @{$findings} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | next if $finding != $f->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $f->{disposition} = $disposition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $f->{comment} = $comment if defined $comment; # preserve existing if not supplied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub _finalize_annotations { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finalize_annotations: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ( $self, $review, $review_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | die "ERROR: mark all findings before finalizing!\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | if !$self->_check_annotation_dispositions($review); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | foreach my $f ( @{ $review->{findings} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | next if !$f->{disposition} || $f->{disposition} ne 'WRONG'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $f->{"disposition"} or $f->{"disposition"} ne "WRONG"
MC/DC0%0/2
not $f->{"disposition"} or $f->{"disposition"} ne "WRONG"
not $f->{"disposition"}
$f->{"disposition"} ne "WRONG"
Truth table0%0/3
not(A) or B
A= not $f->{"disposition"}B= $f->{"disposition"} ne "WRONG"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $f->{disposition} = 'WRONG-RECONSIDER'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $version = eval { slurp('VERSION') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | die "ERROR: could not determine VERSION\n$EVAL_ERROR" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | if !$version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | chomp $version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my ($stem) = $review_file =~ /^(.*?)-review/xsm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $final_review_file = sprintf '%s-%s.review', $stem, $version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $final_annotate_file = sprintf '%s-%s.annotate', $stem, $version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # write modified review (with WRONG-RECONSIDER conversions) to final file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | open my $fh, '>', $final_review_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | or die "ERROR: could not open $final_review_file for writing: $OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | print {$fh} JSON->new->pretty->utf8->encode($review); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | or warn "WARNING: could not close $final_review_file: $OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # enshrine the annotate file if one exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ( my $annotate_file = $review_file ) =~ s/[.]\w+\z/.annotate/xsm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( -e $annotate_file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | copy $annotate_file, $final_annotate_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | or warn "WARNING: could not copy $annotate_file to $final_annotate_file: $OS_ERROR\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->_generate_annotate_file( $review, $final_review_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | sub _load_ASCIITable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_ASCIITable: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | require Text::ASCIITable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | require Text::ASCIITable::FixANSI; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub _check_annotation_dispositions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_annotation_dispositions: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my ( $self, $review ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | return $TRUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | if !$review; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | my @findings = @{ $review->{findings} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | return $TRUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if !@findings || none { !defined $_->{disposition} } @findings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
not @findings or &none(sub {
MC/DC0%0/2
not @findings or &none(sub {
not defined $_->{"disposition"};
}
, @findings)
not @findings
&none(sub {
not defined $_->{"disposition"};
}
, @findings)
Truth table0%0/3
not(A) or B
A= not @findingsB= &none(sub {
not defined $_->{"disposition"};
}
, @findings)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return $FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||