Review/Report.pm

filter: Statementstmt 100% 141 / 141 Branchbran 91.6% 44 / 48 Conditioncond 80.0% 24 / 30 MC/DCmcdc 64.7% 11 / 17 Subroutinesub 100% 17 / 17 Podpod 100% 11 / 11 totaltotal 93.9% 248 / 264 CC 47 SCAR 24.2
CC
47
Cov
95%
generate_summary
18.1
as_text
17.0
as_json
7.1
CRAP 11.2
« Review/Tools.pm ↑ Summary Review/Options.pm »
1 package Claude::Agent::Code::Review::Report;
2  
3 4 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Object::Proto ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Cpanel::JSON::XS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 Object::Proto::define('Claude::Agent::Code::Review::Report',
12 'summary:Str:required',
13 'issues:ArrayRef:default([])',
14 'metrics',
15 'perlcritic_issues:ArrayRef:default([])',
16 'perlcritic_enabled:Bool:default(0)',
17 'filtered_count:Int:default(0)',
18 );
19 }
20  
21 22 ▶sub has_issues {
Subroutine has_issues: called CC=1 SCAR=0.0
Pod documented
22 22 my ($self) = @_;
23 22 return @{$self->issues} > 0;
24 }
25  
26 2 ▶sub has_critical_issues {
Subroutine has_critical_issues: called CC=1 SCAR=0.0
Pod documented
27 2 my ($self) = @_;
28 2 return scalar(grep { $_->severity eq 'critical' } @{$self->issues}) > 0;
29 }
30  
31 2 ▶sub has_high_issues {
Subroutine has_high_issues: called CC=1 SCAR=0.0
Pod documented
32 2 my ($self) = @_;
33 2 return scalar(grep { $_->severity eq 'high' } @{$self->issues}) > 0;
34 }
35  
36 9 ▶sub issue_count {
Subroutine issue_count: called CC=1 SCAR=0.0
Pod documented
37 9 my ($self) = @_;
38 9 return scalar @{$self->issues};
39 }
40  
41 7 ▶sub generate_summary {
Subroutine generate_summary: called CC=18 SCAR=29.0
Pod documented
42 7 my ($self_or_class, $issues_ref) = @_;
43  
44 7 my @issues;
45 7 ▶ if (ref($self_or_class) && $self_or_class->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self_or_class and $self_or_class->isa(__PACKAGE__)) { } 1 6 7
Condition66%2/3
ref $self_or_class and $self_or_class->isa(__PACKAGE__)
!ll&&!rl&&r
601
MC/DC50%1/2
ref $self_or_class and $self_or_class->isa(__PACKAGE__)
ref $self_or_class $self_or_class->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= ref $self_or_classB= $self_or_class->isa(__PACKAGE__)
ABresult
0X0
100
111
46 1 @issues = @{$self_or_class->issues};
47 } else {
48 6 ▶ @issues = @{$issues_ref // []};
Condition50%1/2
$issues_ref // []
l!l
60
MC/DC0%0/1
$issues_ref // []
$issues_ref
Truth table50%1/2
A
A= $issues_ref
Aresult
11
00
49 }
50  
51 7 my $total = scalar @issues;
52 7 ▶ return "No issues found." unless $total > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $total > 0 1 6 7
53  
54 6 my %by_sev;
55 6 for my $issue (@issues) {
56 13 ▶ push @{$by_sev{$issue->severity} //= []}, $issue;
Condition100%2/2
$by_sev{$issue->severity} //= []
l!l
211
MC/DC100%1/1
$by_sev{$issue->severity} //= []
$by_sev{$issue->severity}
Truth table100%2/2
A
A= $by_sev{$issue->severity}
Aresult
11
00
57 }
58  
59 6 my %by_cat;
60 6 for my $issue (@issues) {
61 13 ▶ push @{$by_cat{$issue->category} //= []}, $issue;
Condition100%2/2
$by_cat{$issue->category} //= []
l!l
112
MC/DC100%1/1
$by_cat{$issue->category} //= []
$by_cat{$issue->category}
Truth table100%2/2
A
A= $by_cat{$issue->category}
Aresult
11
00
62 }
63  
64 6 my @sev_parts;
65 6 for my $sev (qw(critical high medium low info)) {
66 30 ▶ my $count = scalar(@{$by_sev{$sev} // []});
Condition100%2/2
$by_sev{$sev} // []
l!l
1119
MC/DC100%1/1
$by_sev{$sev} // []
$by_sev{$sev}
Truth table100%2/2
A
A= $by_sev{$sev}
Aresult
11
00
67 30 ▶ push @sev_parts, "$count $sev" if $count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 0 11 19 30
68 }
69  
70 6 my @cat_parts;
71 6 for my $cat (qw(security bugs performance maintainability style)) {
72 30 ▶ my $count = scalar(@{$by_cat{$cat} // []});
Condition100%2/2
$by_cat{$cat} // []
l!l
1218
MC/DC100%1/1
$by_cat{$cat} // []
$by_cat{$cat}
Truth table100%2/2
A
A= $by_cat{$cat}
Aresult
11
00
73 30 ▶ push @cat_parts, "$count $cat" if $count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 0 12 18 30
74 }
75  
76 6 ▶ my $summary = "Found $total issue" . ($total == 1 ? '' : 's');
Branch: 1 branch
BranchTrueFalseTotal
$total == 1 ? : 2 4 6
77 6 ▶ $summary .= ": " . join(", ", @sev_parts) if @sev_parts;
Branch: 1 branch
BranchTrueFalseTotal
if @sev_parts 6 0 6
78 6 ▶ $summary .= " (" . join(", ", @cat_parts) . ")" if @cat_parts;
Branch: 1 branch
BranchTrueFalseTotal
if @cat_parts 6 0 6
79 6 $summary .= ".";
80  
81 6 return $summary;
82 }
83  
84 1 ▶sub issues_by_category {
Subroutine issues_by_category: called CC=3 SCAR=11.0
Pod documented
85 1 my ($self) = @_;
86  
87 1 my %by_cat;
88 1 for my $issue (@{$self->issues}) {
89 3 ▶ push @{$by_cat{$issue->category} //= []}, $issue;
Condition50%1/2
$by_cat{$issue->category} //= []
l!l
03
MC/DC0%0/1
$by_cat{$issue->category} //= []
$by_cat{$issue->category}
Truth table50%1/2
A
A= $by_cat{$issue->category}
Aresult
11
00
90 }
91  
92 1 return \%by_cat;
93 }
94  
95 4 ▶sub issues_by_severity {
Subroutine issues_by_severity: called CC=3 SCAR=11.0
Pod documented
96 4 my ($self) = @_;
97  
98 4 my %by_sev;
99 4 for my $issue (@{$self->issues}) {
100 8 ▶ push @{$by_sev{$issue->severity} //= []}, $issue;
Condition50%1/2
$by_sev{$issue->severity} //= []
l!l
08
MC/DC0%0/1
$by_sev{$issue->severity} //= []
$by_sev{$issue->severity}
Truth table50%1/2
A
A= $by_sev{$issue->severity}
Aresult
11
00
101 }
102  
103 4 return \%by_sev;
104 }
105  
106 1 ▶sub issues_by_file {
Subroutine issues_by_file: called CC=3 SCAR=11.0
Pod documented
107 1 my ($self) = @_;
108  
109 1 my %by_file;
110 1 for my $issue (@{$self->issues}) {
111 3 ▶ push @{$by_file{$issue->file} //= []}, $issue;
Condition100%2/2
$by_file{$issue->file} //= []
l!l
12
MC/DC100%1/1
$by_file{$issue->file} //= []
$by_file{$issue->file}
Truth table100%2/2
A
A= $by_file{$issue->file}
Aresult
11
00
112 }
113  
114 1 return \%by_file;
115 }
116  
117 7 ▶sub as_text {
Subroutine as_text: called CC=17 SCAR=28.3
Pod documented
118 7 my ($self) = @_;
119  
120 7 my @lines;
121 7 push @lines, "=" x 60;
122 7 push @lines, "CODE REVIEW REPORT";
123 7 push @lines, "=" x 60;
124 7 push @lines, "";
125  
126 7 ▶ if ($self->perlcritic_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->perlcritic_enabled) 3 4 7
127 3 my $pc_count = scalar @{$self->perlcritic_issues};
128 3 ▶ if ($pc_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pc_count == 0) { } 2 1 3
129 2 push @lines, "Perl::Critic: *** NO PERLCRITIC ERRORS ***";
130 }
131 else {
132 1 push @lines, "Perl::Critic: $pc_count issue(s) found";
133 }
134 3 push @lines, "";
135 }
136  
137 7 push @lines, "Summary: " . $self->summary;
138 7 push @lines, "Total issues: " . $self->issue_count;
139 7 ▶ if ($self->filtered_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filtered_count > 0) 1 6 7
140 1 push @lines, "Filtered: " . $self->filtered_count . " likely false positive(s) removed";
141 }
142 7 push @lines, "";
143  
144 7 ▶ if ($self->has_issues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_issues) { } 3 4 7
145 3 my $by_sev = $self->issues_by_severity;
146  
147 3 for my $severity (qw(critical high medium low info)) {
148 15 ▶ my $issues = $by_sev->{$severity} // [];
Condition100%2/2
$by_sev->{$severity} // []
l!l
510
MC/DC100%1/1
$by_sev->{$severity} // []
$by_sev->{$severity}
Truth table100%2/2
A
A= $by_sev->{$severity}
Aresult
11
00
149 15 ▶ next unless @$issues;
Branch: 1 branch
BranchTrueFalseTotal
unless @$issues 10 5 15
150  
151 5 push @lines, "-" x 40;
152 5 push @lines, uc($severity) . " (" . scalar(@$issues) . ")";
153 5 push @lines, "-" x 40;
154  
155 5 for my $issue (@$issues) {
156 5 push @lines, "";
157 5 push @lines, sprintf("[%s] %s:%d", $issue->category, $issue->file, $issue->line);
158 5 push @lines, " " . $issue->description;
159  
160 5 ▶ if ($issue->has_explanation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->has_explanation) 1 4 5
161 1 push @lines, " Explanation: " . $issue->explanation;
162 }
163  
164 5 ▶ if ($issue->has_suggestion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->has_suggestion) 1 4 5
165 1 push @lines, " Suggestion: " . $issue->suggestion;
166 }
167  
168 5 ▶ if ($issue->has_code_before && $issue->has_code_after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue->has_code_before and $issue->has_code_after) 1 4 5
Condition66%2/3
$issue->has_code_before and $issue->has_code_after
!ll&&!rl&&r
401
MC/DC50%1/2
$issue->has_code_before and $issue->has_code_after
$issue->has_code_before $issue->has_code_after
Truth table66%2/3
A and B
A= $issue->has_code_beforeB= $issue->has_code_after
ABresult
0X0
100
111
169 1 push @lines, " Before: " . $issue->code_before;
170 1 push @lines, " After: " . $issue->code_after;
171 }
172 }
173 }
174 }
175 else {
176 4 push @lines, "No issues found.";
177 }
178  
179 7 push @lines, "";
180  
181 7 ▶ if ($self->has_issues && !$self->perlcritic_enabled) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_issues and not $self->perlcritic_enabled) { } 2 5 7
elsif ($self->has_issues and $self->perlcritic_enabled) { } 1 8 9
Condition100%3/3
$self->has_issues and not $self->perlcritic_enabled
!ll&&!rl&&r
412
MC/DC100%2/2
$self->has_issues and not $self->perlcritic_enabled
$self->has_issues not $self->perlcritic_enabled
Truth table100%3/3
A and not(B)
A= $self->has_issuesB= not $self->perlcritic_enabled
ABresult
0X0
100
111
182 2 push @lines, "-" x 60;
183 2 push @lines, "Note: AI review is non-deterministic. Results may vary.";
184 }
185 ▶ elsif ($self->has_issues && $self->perlcritic_enabled) {
Condition66%2/3
$self->has_issues and $self->perlcritic_enabled
!ll&&!rl&&r
401
MC/DC50%1/2
$self->has_issues and $self->perlcritic_enabled
$self->has_issues $self->perlcritic_enabled
Truth table66%2/3
A and B
A= $self->has_issuesB= $self->perlcritic_enabled
ABresult
0X0
100
111
186 1 push @lines, "-" x 60;
187 1 push @lines, "Note: AI issues above may vary between runs.";
188 1 push @lines, "Perl::Critic issues are deterministic and reproducible.";
189 }
190  
191 7 push @lines, "";
192 7 push @lines, "=" x 60;
193  
194 7 return join("\n", @lines) . "\n";
195 }
196  
197 3 ▶sub as_json {
Subroutine as_json: called CC=7 SCAR=19.6
Pod documented
198 3 my ($self) = @_;
199  
200 my $data = {
201 summary => $self->summary,
202 issues => [
203 map {
204 5 my $issue = $_;
205 {
206 5 ▶ severity => $issue->severity,
Branch: 5 branches
BranchTrueFalseTotal
$issue->has_end_line ? : 1 4 5
$issue->has_explanation ? : 1 4 5
$issue->has_suggestion ? : 1 4 5
$issue->has_code_before ? : 0 5 5
$issue->has_code_after ? : 0 5 5
207 category => $issue->category,
208 file => $issue->file,
209 line => $issue->line,
210 ($issue->has_end_line ? (end_line => $issue->end_line) : ()),
211 description => $issue->description,
212 ($issue->has_explanation ? (explanation => $issue->explanation) : ()),
213 ($issue->has_suggestion ? (suggestion => $issue->suggestion) : ()),
214 ($issue->has_code_before ? (code_before => $issue->code_before) : ()),
215 ($issue->has_code_after ? (code_after => $issue->code_after) : ()),
216 }
217 3 ▶ } @{$self->issues}
Branch: 1 branch
BranchTrueFalseTotal
$self->metrics ? : 1 2 3
218 ],
219 ($self->metrics ? (metrics => $self->metrics) : ()),
220 };
221  
222 3 return encode_json($data);
223 }
224  
225 2 ▶sub to_hash {
Subroutine to_hash: called CC=2 SCAR=6.9
Pod documented
226 2 my ($self) = @_;
227  
228 return {
229 summary => $self->summary,
230 2 ▶ issues => [ map { $_->to_hash } @{$self->issues} ],
Branch: 1 branch
BranchTrueFalseTotal
$self->metrics ? : 1 1 2
231 ($self->metrics ? (metrics => $self->metrics) : ()),
232 };
233 }
234  
235  
236 4 1;
237  
238 __END__
« Review/Tools.pm ↑ Summary Review/Options.pm »