Review.pm

filter: Statementstmt 42.2% 106 / 251 Branchbran 22.2% 20 / 90 Conditioncond 18.5% 13 / 70 MC/DCmcdc 9.5% 4 / 42 Subroutinesub 74.1% 23 / 31 Podpod 100% 3 / 3 totaltotal 34.7% 169 / 487 CC 72 SCAR 50.0
CC
72
Cov
34%
_build_report
552.0
review
72.0
review_files
72.0
CRAP 147.8
« Review/Perlcritic.pm ↑ Summary Review/Filter.pm »
1 package Claude::Agent::Code::Review;
2  
3 3 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our @EXPORT_OK = qw(review review_files review_diff);
9  
10 3 ▶use Claude::Agent qw(query tool create_sdk_mcp_server);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Claude::Agent::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Claude::Agent::Code::Review::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Claude::Agent::Code::Review::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Claude::Agent::Code::Review::Issue;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Claude::Agent::Code::Review::Tools;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Claude::Agent::Code::Review::Perlcritic;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Claude::Agent::Code::Review::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use IO::Async::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Cpanel::JSON::XS qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 our $VERSION = '0.03';
25  
26 0 ▶async sub review {
Subroutine review: not called CC=8 SCAR=42.8
Pod documented
27 0 my (%args) = @_;
28  
29 0 ▶ my $target = $args{target} // die "review() requires 'target' argument";
Condition0%0/2
$args{"target"} // die("review() requires 'target' argument")
l!l
00
MC/DC0%0/1
$args{"target"} // die("review() requires 'target' argument")
$args{"target"}
Truth table0%0/2
A
A= $args{"target"}
Aresult
11
00
30 0 ▶ my $options = $args{options} // Claude::Agent::Code::Review::Options->new();
Condition0%0/3
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
$args{"options"} "Claude::Agent::Code::Review::Options"->new
Truth table0%0/3
A // B
A= $args{"options"}B= "Claude::Agent::Code::Review::Options"->new
ABresult
1X1
011
000
31 0 ▶ my $loop = $args{loop} // IO::Async::Loop->new;
Condition0%0/3
$args{"loop"} // "IO::Async::Loop"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"loop"} // "IO::Async::Loop"->new
$args{"loop"} "IO::Async::Loop"->new
Truth table0%0/3
A // B
A= $args{"loop"}B= "IO::Async::Loop"->new
ABresult
1X1
011
000
32  
33 0 ▶ if ($target eq 'staged') {
Branch: 3 branches
BranchTrueFalseTotal
if ($target eq 'staged') { } 0 0 0
elsif (-d $target or -f $target) { } 0 0 0
elsif (_is_diff_content($target)) { } 0 0 0
34 0 return await review_diff(
35 staged => 1,
36 options => $options,
37 loop => $loop,
38 );
39 }
40 ▶ elsif (-d $target || -f $target) {
Condition0%0/3
-d $target or -f $target
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $target or -f $target
-d $target -f $target
Truth table0%0/3
A or B
A= -d $targetB= -f $target
ABresult
1X1
011
000
41 0 return await review_files(
42 paths => [$target],
43 options => $options,
44 loop => $loop,
45 );
46 }
47 elsif (_is_diff_content($target)) {
48 0 return await review_diff(
49 diff => $target,
50 options => $options,
51 loop => $loop,
52 );
53 }
54 else {
55 0 die "Unknown target type: $target";
56 }
57 3 }
58  
59 0 ▶async sub review_files {
Subroutine review_files: not called CC=8 SCAR=42.8
Pod documented
60 0 my (%args) = @_;
61  
62 0 ▶ my $paths = $args{paths} // die "review_files() requires 'paths' argument";
Condition0%0/2
$args{"paths"} // die("review_files() requires 'paths' argument")
l!l
00
MC/DC0%0/1
$args{"paths"} // die("review_files() requires 'paths' argument")
$args{"paths"}
Truth table0%0/2
A
A= $args{"paths"}
Aresult
11
00
63 0 ▶ my $options = $args{options} // Claude::Agent::Code::Review::Options->new();
Condition0%0/3
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
$args{"options"} "Claude::Agent::Code::Review::Options"->new
Truth table0%0/3
A // B
A= $args{"options"}B= "Claude::Agent::Code::Review::Options"->new
ABresult
1X1
011
000
64 0 ▶ my $loop = $args{loop} // IO::Async::Loop->new;
Condition0%0/3
$args{"loop"} // "IO::Async::Loop"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"loop"} // "IO::Async::Loop"->new
$args{"loop"} "IO::Async::Loop"->new
Truth table0%0/3
A // B
A= $args{"loop"}B= "IO::Async::Loop"->new
ABresult
1X1
011
000
65  
66 0 my $prompt = _build_files_prompt($paths, $options);
67 0 my $report = await _run_review($prompt, $options, $loop);
68  
69 0 my $filtered_count = 0;
70 0 ▶ if ($options->filter_false_positives) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->filter_false_positives) 0 0 0
71 0 my @original = @{$report->issues};
72 0 my @filtered = Claude::Agent::Code::Review::Filter->filter(
73 issues => \@original,
74 filters => $options->custom_filters,
75 );
76 0 $filtered_count = scalar(@original) - scalar(@filtered);
77 0 ▶ if ($filtered_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filtered_count > 0) 0 0 0
78 0 my $new_summary = Claude::Agent::Code::Review::Report->generate_summary(\@filtered);
79 0 $report = Claude::Agent::Code::Review::Report->new(
80 summary => $new_summary,
81 issues => \@filtered,
82 metrics => $report->metrics,
83 );
84 }
85 }
86  
87 0 ▶ if ($options->has_perlcritic) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options->has_perlcritic) { } 0 0 0
elsif ($filtered_count > 0) { } 0 0 0
88 0 my @pc_issues = Claude::Agent::Code::Review::Perlcritic->analyze(
89 paths => $paths,
90 options => $options,
91 );
92 0 my @all_issues = (@{$report->issues}, @pc_issues);
93 0 $report = Claude::Agent::Code::Review::Report->new(
94 summary => $report->summary,
95 issues => \@all_issues,
96 metrics => $report->metrics,
97 perlcritic_enabled => 1,
98 perlcritic_issues => \@pc_issues,
99 filtered_count => $filtered_count,
100 );
101 }
102 elsif ($filtered_count > 0) {
103 0 $report = Claude::Agent::Code::Review::Report->new(
104 summary => $report->summary,
105 issues => $report->issues,
106 metrics => $report->metrics,
107 filtered_count => $filtered_count,
108 );
109 }
110  
111 0 return $report;
112 3 }
113  
114 0 ▶async sub review_diff {
Subroutine review_diff: not called CC=8 SCAR=42.8
Pod documented
115 0 my (%args) = @_;
116  
117 0 ▶ my $options = $args{options} // Claude::Agent::Code::Review::Options->new();
Condition0%0/3
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"options"} // "Claude::Agent::Code::Review::Options"->new
$args{"options"} "Claude::Agent::Code::Review::Options"->new
Truth table0%0/3
A // B
A= $args{"options"}B= "Claude::Agent::Code::Review::Options"->new
ABresult
1X1
011
000
118 0 ▶ my $loop = $args{loop} // IO::Async::Loop->new;
Condition0%0/3
$args{"loop"} // "IO::Async::Loop"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"loop"} // "IO::Async::Loop"->new
$args{"loop"} "IO::Async::Loop"->new
Truth table0%0/3
A // B
A= $args{"loop"}B= "IO::Async::Loop"->new
ABresult
1X1
011
000
119  
120 0 my $diff;
121 0 ▶ if ($args{staged}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'staged'}) { } 0 0 0
elsif ($args{'diff'}) { } 0 0 0
122 0 my $result = await _run_git_diff_cached_async($loop);
123 0 ▶ if ($result->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"error"}) 0 0 0
124 return Claude::Agent::Code::Review::Report->new(
125 summary => $result->{error},
126 0 issues => [],
127 );
128 }
129 0 $diff = $result->{diff};
130 0 ▶ if (!$diff || $diff =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $diff or $diff =~ /^\s*$/u) 0 0 0
Condition0%0/3
not $diff or $diff =~ /^\s*$/u
l!l&&r!l&&!r
000
MC/DC0%0/2
not $diff or $diff =~ /^\s*$/u
not $diff $diff =~ /^\s*$/u
Truth table0%0/3
not(A) or B
A= not $diffB= $diff =~ /^\s*$/u
ABresult
1X1
011
000
131 0 return Claude::Agent::Code::Review::Report->new(
132 summary => 'No staged changes to review',
133 issues => [],
134 );
135 }
136 }
137 elsif ($args{diff}) {
138 0 $diff = $args{diff};
139 }
140 else {
141 0 die "review_diff() requires 'diff' or 'staged' argument";
142 }
143  
144 0 my $prompt = _build_diff_prompt($diff, $options);
145 0 return await _run_review($prompt, $options, $loop);
146 3 }
147  
148 3 ▶sub _build_files_prompt {
Subroutine _build_files_prompt: called CC=4 SCAR=13.9
149 3 my ($paths, $options) = @_;
150  
151 3 ▶ my @path_list = ref $paths eq 'ARRAY' ? @$paths : ($paths);
Branch: 1 branch
BranchTrueFalseTotal
ref $paths eq 'ARRAY' ? : 3 0 3
152 3 my $paths_str = join(', ', @path_list);
153  
154 3 my $categories = join(', ', @{$options->categories});
155 3 my $severity = $options->severity;
156  
157 3 my $focus = '';
158 3 ▶ if ($options->has_focus_areas && @{$options->focus_areas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->has_focus_areas and @{$options->focus_areas;}) 1 2 3
Condition66%2/3
$options->has_focus_areas and @{$options->focus_areas;}
!ll&&!rl&&r
201
MC/DC50%1/2
$options->has_focus_areas and @{$options->focus_areas;}
$options->has_focus_areas @{$options->focus_areas;}
Truth table66%2/3
A and B
A= $options->has_focus_areasB= @{$options->focus_areas;}
ABresult
0X0
100
111
159 1 $focus = "\n\nPay special attention to: " . join(', ', @{$options->focus_areas});
160 }
161  
162 3 return <<"END_PROMPT";
163 Review the following code paths for issues: $paths_str
164  
165 Categories to check: $categories
166 Minimum severity to report: $severity
167 $focus
168  
169 Use the provided tools to read files and gather context. For each issue found, provide:
170 - File path and line number
171 - Severity (critical, high, medium, low, info)
172 - Category (bugs, security, style, performance, maintainability)
173 - Clear description of the problem
174 - Suggested fix when possible
175  
176 Return your findings as a structured JSON response.
177 END_PROMPT
178 }
179  
180 1 ▶sub _build_diff_prompt {
Subroutine _build_diff_prompt: called CC=3 SCAR=12.7
181 1 my ($diff, $options) = @_;
182  
183 1 my $categories = join(', ', @{$options->categories});
184 1 my $severity = $options->severity;
185  
186 1 my $focus = '';
187 0 ▶ if ($options->has_focus_areas && @{$options->focus_areas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->has_focus_areas and @{$options->focus_areas;}) 0 1 1
Condition33%1/3
$options->has_focus_areas and @{$options->focus_areas;}
!ll&&!rl&&r
100
MC/DC0%0/2
$options->has_focus_areas and @{$options->focus_areas;}
$options->has_focus_areas @{$options->focus_areas;}
Truth table33%1/3
A and B
A= $options->has_focus_areasB= @{$options->focus_areas;}
ABresult
0X0
100
111
188 0 $focus = "\n\nPay special attention to: " . join(', ', @{$options->focus_areas});
189 }
190  
191 1 return <<"END_PROMPT";
192 Review the following diff for issues:
193  
194 ```diff
195 $diff
196 ```
197  
198 Categories to check: $categories
199 Minimum severity to report: $severity
200 $focus
201  
202 For each issue found in the changed code, provide:
203 - File path and line number
204 - Severity (critical, high, medium, low, info)
205 - Category (bugs, security, style, performance, maintainability)
206 - Clear description of the problem
207 - Suggested fix when possible
208  
209 Return your findings as a structured JSON response.
210 END_PROMPT
211 }
212  
213 0 ▶async sub _run_review {
Subroutine _run_review: not called CC=7 SCAR=40.3
214 0 my ($prompt, $options, $loop) = @_;
215  
216 0 my $tools_server = Claude::Agent::Code::Review::Tools->create_server();
217  
218 0 my $review_schema = _get_review_schema();
219  
220 my %claude_args = (
221 allowed_tools => [
222 'Read', 'Glob', 'Grep',
223 0 @{$tools_server->tool_names},
224 ],
225 mcp_servers => { review => $tools_server },
226 permission_mode => $options->permission_mode,
227 system_prompt => _get_system_prompt($options),
228 output_format => {
229 type => 'json_schema',
230 schema => $review_schema,
231 },
232 );
233 0 ▶ $claude_args{model} = $options->model if defined $options->model;
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->model 0 0 0
234 0 ▶ $claude_args{effort} = $options->effort if $options->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
if $options->has_effort 0 0 0
235  
236 0 my $claude_options = Claude::Agent::Options->new(%claude_args);
237  
238 0 my $iter = query(
239 prompt => $prompt,
240 options => $claude_options,
241 loop => $loop,
242 );
243  
244 0 my $result;
245 0 my $max_iterations = 1000;
246 0 my $iterations = 0;
247  
248 0 ▶ while (my $msg = await $iter->next_async) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $msg = <custom op await>) 0 0 0
249 0 $iterations++;
250 0 ▶ if ($msg->isa('Claude::Agent::Message::Result')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->isa("Claude::Agent::Message::Result")) 0 0 0
251 0 $result = $msg;
252 0 last;
253 }
254 0 ▶ if ($iterations >= $max_iterations) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iterations >= $max_iterations) 0 0 0
255 0 $iter->close;
256 0 return Claude::Agent::Code::Review::Report->new(
257 summary => 'Review timed out: exceeded maximum iterations',
258 issues => [],
259 );
260 }
261 }
262  
263 0 $iter->close;
264  
265 0 ▶ unless (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
266 0 return Claude::Agent::Code::Review::Report->new(
267 summary => 'Review failed - no result received from Claude',
268 issues => [],
269 );
270 }
271  
272 0 return _build_report($result, $options);
273 3 }
274  
275 1 ▶sub _get_system_prompt {
Subroutine _get_system_prompt: called CC=3 SCAR=11.3
276 1 my ($options) = @_;
277  
278 1 my $categories = join(', ', @{$options->categories});
279 1 my $focus = '';
280 1 ▶ if ($options->has_focus_areas && @{$options->focus_areas}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->has_focus_areas and @{$options->focus_areas;}) 1 0 1
Condition33%1/3
$options->has_focus_areas and @{$options->focus_areas;}
!ll&&!rl&&r
001
MC/DC0%0/2
$options->has_focus_areas and @{$options->focus_areas;}
$options->has_focus_areas @{$options->focus_areas;}
Truth table33%1/3
A and B
A= $options->has_focus_areasB= @{$options->focus_areas;}
ABresult
0X0
100
111
281 1 $focus = "\n\nPay special attention to: " . join(', ', @{$options->focus_areas});
282 }
283  
284 1 return <<"END_PROMPT";
285 You are an expert code reviewer. Your task is to systematically analyze code for issues.
286  
287 IMPORTANT: Follow this SYSTEMATIC methodology for consistent, reproducible results:
288  
289 1. ENUMERATE: First, list ALL files to be reviewed using Glob
290 2. FOR EACH FILE: Read the entire file, then check for issues in this EXACT order:
291 a. Security issues (injection, XSS, auth, data exposure)
292 b. Bugs (logic errors, null handling, race conditions, off-by-one)
293 c. Performance (inefficient algorithms, unnecessary operations)
294 d. Style (naming, organization) - only report if clearly problematic
295 e. Maintainability (complexity, duplication)
296 3. VERIFY: Before reporting an issue, check the surrounding code context to avoid false positives
297 4. SKIP: Do not report issues about documented limitations (comments with "Note:", "TODO:", etc.)
298  
299 Categories to check: $categories
300  
301 Severity guidelines:
302 - critical: Security vulnerabilities, data loss, crashes
303 - high: Bugs that will cause incorrect behavior
304 - medium: Potential bugs, minor security issues
305 - low: Code quality issues
306 - info: Suggestions for improvement
307  
308 For each issue:
309 - Provide exact file path and line number
310 - Explain the actual problem (not theoretical)
311 - Suggest a concrete fix
312 - Only report issues you are confident about$focus
313 END_PROMPT
314 }
315  
316 1 ▶sub _get_review_schema {
Subroutine _get_review_schema: called CC=1 SCAR=0.0
317 return {
318 1 type => 'object',
319 properties => {
320 summary => {
321 type => 'string',
322 description => 'Brief overview of findings',
323 },
324 issues => {
325 type => 'array',
326 items => {
327 type => 'object',
328 properties => {
329 severity => {
330 type => 'string',
331 enum => ['critical', 'high', 'medium', 'low', 'info'],
332 },
333 category => {
334 type => 'string',
335 enum => ['bugs', 'security', 'style', 'performance', 'maintainability'],
336 },
337 file => { type => 'string' },
338 line => { type => 'integer' },
339 end_line => { type => 'integer' },
340 description => { type => 'string' },
341 explanation => { type => 'string' },
342 suggestion => { type => 'string' },
343 code_before => { type => 'string' },
344 code_after => { type => 'string' },
345 },
346 required => ['severity', 'category', 'file', 'line', 'description'],
347 },
348 },
349 metrics => {
350 type => 'object',
351 properties => {
352 files_reviewed => { type => 'integer' },
353 lines_reviewed => { type => 'integer' },
354 issues_by_severity => { type => 'object' },
355 issues_by_category => { type => 'object' },
356 },
357 },
358 },
359 required => ['summary', 'issues'],
360 };
361 }
362  
363 0 ▶sub _build_report {
Subroutine _build_report: not called CC=23 SCAR=63.1
364 0 my ($result, $options) = @_;
365  
366 0 ▶ unless ($result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
367 0 return Claude::Agent::Code::Review::Report->new(
368 summary => 'Review failed - no result returned',
369 issues => [],
370 );
371 }
372  
373 0 my $data;
374 0 ▶ if ($result->has_structured_output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->has_structured_output) { } 0 0 0
375 0 $data = $result->structured_output;
376 }
377 else {
378 0 ▶ my $text = $result->result // '';
Condition0%0/2
$result->result // ""
l!l
00
MC/DC0%0/1
$result->result // ""
$result->result
Truth table0%0/2
A
A= $result->result
Aresult
11
00
379 0 ▶ if ($text eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($text eq "") 0 0 0
380 0 return Claude::Agent::Code::Review::Report->new(
381 summary => 'Review returned empty response',
382 issues => [],
383 );
384 }
385 0 my $parse_error;
386 0 ▶ eval { $data = decode_json($text); 1 } or $parse_error = $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $data = &decode_json($text); 1 } } or $parse_error = $@ 0 0 0
387 0 ▶ if ($parse_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse_error) 0 0 0
388 0 ▶ my $snippet = length($text) > 100 ? substr($text, 0, 100) . '...' : $text;
Branch: 1 branch
BranchTrueFalseTotal
length $text > 100 ? : 0 0 0
389 0 $snippet =~ s/api[_-]?key[^\s]*/[REDACTED]/gi;
390 0 $snippet =~ s/password[^\s]*/[REDACTED]/gi;
391 0 $snippet =~ s/token[^\s]*/[REDACTED]/gi;
392 0 return Claude::Agent::Code::Review::Report->new(
393 summary => "Failed to parse review output as JSON. Response started with: $snippet",
394 issues => [],
395 );
396 }
397 }
398  
399 0 my @issues;
400 0 my $missing_fields_count = 0;
401 0 my $invalid_values_count = 0;
402 0 my $issues_data = $data->{issues};
403  
404 0 ▶ if (defined $issues_data && ref($issues_data) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $issues_data and ref $issues_data ne "ARRAY") 0 0 0
Condition0%0/3
defined $issues_data and ref $issues_data ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $issues_data and ref $issues_data ne "ARRAY"
defined $issues_data ref $issues_data ne "ARRAY"
Truth table0%0/3
A and B
A= defined $issues_dataB= ref $issues_data ne "ARRAY"
ABresult
0X0
100
111
405 0 return Claude::Agent::Code::Review::Report->new(
406 summary => 'Invalid review output: issues must be an array',
407 issues => [],
408 );
409 }
410  
411 0 ▶ for my $issue_data (@{$issues_data // []}) {
Condition0%0/2
$issues_data // []
l!l
00
MC/DC0%0/1
$issues_data // []
$issues_data
Truth table0%0/2
A
A= $issues_data
Aresult
11
00
412 0 ▶ next unless ref($issue_data) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $issue_data eq "HASH" 0 0 0
413 0 my @missing = grep { !defined $issue_data->{$_} } qw(severity category file line description);
414 0 ▶ if (@missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing) 0 0 0
415 0 $missing_fields_count++;
416 0 next;
417 }
418  
419 0 ▶ next if $options->severity && !_meets_severity($issue_data->{severity}, $options->severity);
Branch: 1 branch
BranchTrueFalseTotal
if $options->severity and not _meets_severity($issue_data->{"severity"}, $options->severity) 0 0 0
Condition0%0/3
$options->severity and not _meets_severity($issue_data->{"severity"}, $options->severity)
!ll&&!rl&&r
000
MC/DC0%0/2
$options->severity and not _meets_severity($issue_data->{"severity"}, $options->severity)
$options->severity not _meets_severity($issue_data->{"severity"}, $options->severity)
Truth table0%0/3
A and not(B)
A= $options->severityB= not _meets_severity($issue_data->{"severity"}, $options->severity)
ABresult
0X0
100
111
420  
421 0 my $issue = eval {
422 Claude::Agent::Code::Review::Issue->new(
423 severity => $issue_data->{severity},
424 category => $issue_data->{category},
425 file => $issue_data->{file},
426 line => $issue_data->{line},
427 end_line => $issue_data->{end_line},
428 description => $issue_data->{description},
429 explanation => $issue_data->{explanation},
430 suggestion => $issue_data->{suggestion},
431 code_before => $issue_data->{code_before},
432 code_after => $issue_data->{code_after},
433 0 );
434 };
435 0 ▶ if (!$issue) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $issue) { } 0 0 0
436 0 $invalid_values_count++;
437 } else {
438 0 push @issues, $issue;
439 }
440 }
441  
442 0 ▶ if ($options->has_max_issues && $options->max_issues > 0 && @issues > $options->max_issues) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->has_max_issues and $options->max_issues > 0 and @issues > $options->max_issues) 0 0 0
Condition0%0/6
$options->has_max_issues and $options->max_issues > 0 and @issues > $options->max_issues
!ll&&!rl&&r
000
$options->has_max_issues and $options->max_issues > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$options->has_max_issues and $options->max_issues > 0 and @issues > $options->max_issues
$options->has_max_issues $options->max_issues > 0 @issues > $options->max_issues
Truth table0%0/4
A and B and C
A= $options->has_max_issuesB= $options->max_issues > 0C= @issues > $options->max_issues
ABCresult
0XX0
10X0
1100
1111
443 0 splice(@issues, $options->max_issues);
444 }
445  
446 0 ▶ my $metrics = $data->{metrics} // {};
Condition0%0/2
$data->{"metrics"} // {}
l!l
00
MC/DC0%0/1
$data->{"metrics"} // {}
$data->{"metrics"}
Truth table0%0/2
A
A= $data->{"metrics"}
Aresult
11
00
447 0 ▶ if ($missing_fields_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missing_fields_count > 0) 0 0 0
448 0 $metrics->{issues_missing_fields} = $missing_fields_count;
449 }
450 0 ▶ if ($invalid_values_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invalid_values_count > 0) 0 0 0
451 0 $metrics->{issues_invalid_values} = $invalid_values_count;
452 }
453  
454 0 my $summary = Claude::Agent::Code::Review::Report->generate_summary(\@issues);
455  
456 0 return Claude::Agent::Code::Review::Report->new(
457 summary => $summary,
458 issues => \@issues,
459 metrics => $metrics,
460 );
461 }
462  
463 0 ▶async sub _run_git_diff_cached_async {
Subroutine _run_git_diff_cached_async: not called CC=3 SCAR=24.8
464 0 my ($loop) = @_;
465  
466 0 my $stdout = '';
467 0 my $stderr = '';
468 0 my $finish_future = $loop->new_future;
469  
470 my $process = IO::Async::Process->new(
471 command => ['git', 'diff', '--cached'],
472 stdout => { into => \$stdout },
473 stderr => { into => \$stderr },
474 0 ▶ on_finish => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
475 0 my ($proc, $exitcode) = @_;
476 0 $finish_future->done($exitcode);
477 },
478 0 ▶ on_exception => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
479 0 my ($proc, $exception, $errno) = @_;
480 0 $finish_future->fail("Process exception: $exception");
481 },
482 0 );
483  
484 0 $loop->add($process);
485  
486 0 my $exitcode;
487 0 eval {
488 0 $exitcode = await $finish_future;
489 };
490 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
491 0 return { error => "Failed to run git diff: $@" };
492 }
493  
494 0 ▶ if ($exitcode != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exitcode != 0) 0 0 0
495 0 my $exit_code = $exitcode >> 8;
496 0 return { error => "Git command failed (exit code $exit_code): $stderr" };
497 }
498  
499 0 return { diff => $stdout };
500 3 }
501  
502 10 ▶sub _is_diff_content {
Subroutine _is_diff_content: called CC=12 SCAR=25.6
503 10 my ($content) = @_;
504 10 ▶ return 0 unless defined $content && length($content) > 10;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content and length $content > 10 4 6 10
Condition100%3/3
defined $content and length $content > 10
!ll&&!rl&&r
136
MC/DC100%2/2
defined $content and length $content > 10
defined $content length $content > 10
Truth table100%3/3
A and B
A= defined $contentB= length $content > 10
ABresult
0X0
100
111
505  
506 6 ▶ return 1 if $content =~ /\Adiff --git\s+\S+\s+\S+/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /\Adiff --git\s+\S+\s+\S+/u 1 5 6
507  
508 5 ▶ return 1 if $content =~ /\Adiff\s+-[a-zA-Z]/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /\Adiff\s+-[a-zA-Z]/u 1 4 5
509  
510 4 ▶ return 1 if $content =~ /\AIndex:\s+\S+/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /\AIndex:\s+\S+/u 1 3 4
511  
512 3 ▶ if ($content =~ /^---\s+(?:[ab]\/\S+|\S+\t)/m &&
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ /^\@\@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+\@@/mu) 1 2 3
Condition66%4/6
$content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ /^\@\@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+\@@/mu
!ll&&!rl&&r
201
$content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]mu
!ll&&!rl&&r
201
MC/DC33%1/3
$content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]mu and $content =~ /^\@\@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+\@@/mu
$content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]mu $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]mu $content =~ /^\@\@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+\@@/mu
Truth table50%2/4
A and B and C
A= $content =~ m[^---\s+(?:[ab]/\S+|\S+\t)]muB= $content =~ m[^\+\+\+\s+(?:[ab]/\S+|\S+\t)]muC= $content =~ /^\@\@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+\@@/mu
ABCresult
0XX0
10X0
1100
1111
513 $content =~ /^\+\+\+\s+(?:[ab]\/\S+|\S+\t)/m &&
514 $content =~ /^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m) {
515 1 my ($dash_pos) = $content =~ /^(.*?)^---\s+/ms;
516 1 my ($plus_pos) = $content =~ /^(.*?)^\+\+\+\s+/ms;
517 1 ▶ return 1 if defined $dash_pos && defined $plus_pos &&
Branch: 1 branch
BranchTrueFalseTotal
if defined $dash_pos and defined $plus_pos and length $dash_pos < length $plus_pos 1 0 1
Condition33%2/6
defined $dash_pos and defined $plus_pos and length $dash_pos < length $plus_pos
!ll&&!rl&&r
001
defined $dash_pos and defined $plus_pos
!ll&&!rl&&r
001
MC/DC0%0/3
defined $dash_pos and defined $plus_pos and length $dash_pos < length $plus_pos
defined $dash_pos defined $plus_pos length $dash_pos < length $plus_pos
Truth table25%1/4
A and B and C
A= defined $dash_posB= defined $plus_posC= length $dash_pos < length $plus_pos
ABCresult
0XX0
10X0
1100
1111
518 length($dash_pos) < length($plus_pos);
519 }
520  
521 2 return 0;
522 }
523  
524 18 ▶sub _meets_severity {
Subroutine _meets_severity: called CC=3 SCAR=11.0
525 18 my ($severity, $min_severity) = @_;
526  
527 18 my %severity_rank = (
528 critical => 5,
529 high => 4,
530 medium => 3,
531 low => 2,
532 info => 1,
533 );
534  
535 18 my $sev_rank = $severity_rank{$severity};
536 18 ▶ unless (defined $sev_rank) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sev_rank) 1 17 18
537 1 return 0;
538 }
539  
540 17 my $min_rank = $severity_rank{$min_severity};
541 17 ▶ unless (defined $min_rank) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $min_rank) 1 16 17
542 1 $min_rank = 1;
543 }
544  
545 17 return $sev_rank >= $min_rank;
546 }
547  
548  
549 3 1;
550  
551 __END__
« Review/Perlcritic.pm ↑ Summary Review/Filter.pm »