Review/Perlcritic.pm

filter: Statementstmt 23.6% 21 / 89 Branchbran 2.5% 1 / 40 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 16.7% 31 / 185 CC 34 SCAR 61.8
CC
34
Cov
14%
analyze
756.0
_policy_to_category
42.0
_map_severity
6.0
CRAP 481.1
↑ Summary Review.pm »
1 package Claude::Agent::Code::Review::Perlcritic;
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 Claude::Agent::Code::Review::Issue;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Claude::Agent::Code::Review::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub analyze {
Subroutine analyze: not called CC=27 SCAR=66.3
Pod documented
12 0 my ($class, %args) = @_;
13  
14 0 ▶ my $paths = $args{paths} // die "analyze() requires 'paths' argument";
Condition0%0/2
$args{"paths"} // die("analyze() requires 'paths' argument")
l!l
00
MC/DC0%0/1
$args{"paths"} // die("analyze() requires 'paths' argument")
$args{"paths"}
Truth table0%0/2
A
A= $args{"paths"}
Aresult
11
00
15 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
16  
17 0 ▶ eval { require Perl::Critic; 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Perl::Critic; 1 } } or do { warn "Perl::Critic not available: $@"; return () } 0 0 0
18 0 warn "Perl::Critic not available: $@";
19 0 return ();
20 };
21  
22 0 my %critic_args;
23 0 ▶ my $severity = $options->perlcritic_severity // 4;
Condition0%0/2
$options->perlcritic_severity // 4
l!l
00
MC/DC0%0/1
$options->perlcritic_severity // 4
$options->perlcritic_severity
Truth table0%0/2
A
A= $options->perlcritic_severity
Aresult
11
00
24 0 $critic_args{'-severity'} = 0 + $severity;
25  
26 0 my $base_dir = path('.')->realpath;
27  
28 0 ▶ if ($options->perlcritic_profile && -f $options->perlcritic_profile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->perlcritic_profile and -f $options->perlcritic_profile) 0 0 0
Condition0%0/3
$options->perlcritic_profile and -f $options->perlcritic_profile
!ll&&!rl&&r
000
MC/DC0%0/2
$options->perlcritic_profile and -f $options->perlcritic_profile
$options->perlcritic_profile -f $options->perlcritic_profile
Truth table0%0/3
A and B
A= $options->perlcritic_profileB= -f $options->perlcritic_profile
ABresult
0X0
100
111
29 0 my $profile_path = eval { path($options->perlcritic_profile)->realpath };
30 0 ▶ if ($profile_path && $base_dir->subsumes($profile_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile_path and $base_dir->subsumes($profile_path)) 0 0 0
Condition0%0/3
$profile_path and $base_dir->subsumes($profile_path)
!ll&&!rl&&r
000
MC/DC0%0/2
$profile_path and $base_dir->subsumes($profile_path)
$profile_path $base_dir->subsumes($profile_path)
Truth table0%0/3
A and B
A= $profile_pathB= $base_dir->subsumes($profile_path)
ABresult
0X0
100
111
31 0 $critic_args{'-profile'} = $profile_path->stringify;
32 }
33 }
34  
35 0 my $critic = Perl::Critic->new(%critic_args);
36 0 my @files;
37 0 for my $path (@$paths) {
38 0 ▶ if (-d $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 0 0 0
elsif (-f $path) { } 0 0 0
39 0 my $dir_real = eval { path($path)->realpath };
40 0 ▶ next unless $dir_real && $base_dir->subsumes($dir_real);
Branch: 1 branch
BranchTrueFalseTotal
unless $dir_real and $base_dir->subsumes($dir_real) 0 0 0
Condition0%0/3
$dir_real and $base_dir->subsumes($dir_real)
!ll&&!rl&&r
000
MC/DC0%0/2
$dir_real and $base_dir->subsumes($dir_real)
$dir_real $base_dir->subsumes($dir_real)
Truth table0%0/3
A and B
A= $dir_realB= $base_dir->subsumes($dir_real)
ABresult
0X0
100
111
41 0 my $iter = $dir_real->iterator({ recurse => 1 });
42 0 ▶ while (my $file = $iter->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = &$iter()) 0 0 0
43 0 ▶ next unless $file->is_file && $file =~ /\.(?:p[lm]|t|psgi)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->is_file and $file =~ /\.(?:p[lm]|t|psgi)$/u 0 0 0
Condition0%0/3
$file->is_file and $file =~ /\.(?:p[lm]|t|psgi)$/u
!ll&&!rl&&r
000
MC/DC0%0/2
$file->is_file and $file =~ /\.(?:p[lm]|t|psgi)$/u
$file->is_file $file =~ /\.(?:p[lm]|t|psgi)$/u
Truth table0%0/3
A and B
A= $file->is_fileB= $file =~ /\.(?:p[lm]|t|psgi)$/u
ABresult
0X0
100
111
44 0 my $real = eval { $file->realpath };
45 0 ▶ next unless $real && $base_dir->subsumes($real);
Branch: 1 branch
BranchTrueFalseTotal
unless $real and $base_dir->subsumes($real) 0 0 0
Condition0%0/3
$real and $base_dir->subsumes($real)
!ll&&!rl&&r
000
MC/DC0%0/2
$real and $base_dir->subsumes($real)
$real $base_dir->subsumes($real)
Truth table0%0/3
A and B
A= $realB= $base_dir->subsumes($real)
ABresult
0X0
100
111
46 0 push @files, $file;
47 }
48 }
49 elsif (-f $path) {
50 0 my $file = path($path);
51 0 my $real = eval { $file->realpath };
52 0 ▶ next unless $real && $base_dir->subsumes($real);
Branch: 1 branch
BranchTrueFalseTotal
unless $real and $base_dir->subsumes($real) 0 0 0
Condition0%0/3
$real and $base_dir->subsumes($real)
!ll&&!rl&&r
000
MC/DC0%0/2
$real and $base_dir->subsumes($real)
$real $base_dir->subsumes($real)
Truth table0%0/3
A and B
A= $realB= $base_dir->subsumes($real)
ABresult
0X0
100
111
53 0 push @files, $file;
54 }
55 }
56  
57 0 my @issues;
58 0 for my $file (@files) {
59 0 my @violations = eval { $critic->critique("$file") };
60 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
61 0 my $safe_error = $@;
62 0 $safe_error =~ s/at \/.*? line \d+.*//s;
63 0 $safe_error =~ s/\s+/ /g;
64 0 ▶ $safe_error = substr($safe_error, 0, 100) if length($safe_error) > 100;
Branch: 1 branch
BranchTrueFalseTotal
if length $safe_error > 100 0 0 0
65 0 my $error_issue = eval {
66 0 Claude::Agent::Code::Review::Issue->new(
67 severity => 'low',
68 category => 'bugs',
69 file => "$file",
70 line => 1,
71 description => "Perl::Critic analysis failed: $safe_error",
72 explanation => "File could not be parsed by Perl::Critic. This may indicate a syntax error.",
73 );
74 };
75 0 ▶ push @issues, $error_issue if $error_issue;
Branch: 1 branch
BranchTrueFalseTotal
if $error_issue 0 0 0
76 0 next;
77 }
78  
79 0 for my $violation (@violations) {
80 0 my $pc_severity = $violation->severity;
81 0 my $our_severity = _map_severity($pc_severity);
82 0 my $category = _policy_to_category($violation->policy);
83  
84 0 my $issue = eval {
85 0 Claude::Agent::Code::Review::Issue->new(
86 severity => $our_severity,
87 category => $category,
88 file => "$file",
89 line => $violation->line_number,
90 column => $violation->column_number,
91 description => $violation->description,
92 explanation => "Perl::Critic policy: " . $violation->policy,
93 );
94 };
95  
96 0 ▶ push @issues, $issue if $issue;
Branch: 1 branch
BranchTrueFalseTotal
if $issue 0 0 0
97 }
98 }
99  
100 0 return @issues;
101 }
102  
103 3 ▶sub is_available {
Subroutine is_available: called CC=2 SCAR=7.6
Pod documented
104 3 my ($class) = @_;
105 0 ▶ return eval { require Perl::Critic; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Perl::Critic; 1 } } ? : 0 3 3
106 }
107  
108 0 ▶sub _map_severity {
Subroutine _map_severity: not called CC=2 SCAR=17.9
109 0 my ($pc_severity) = @_;
110  
111 0 my %map = (
112 5 => 'critical',
113 4 => 'high',
114 3 => 'medium',
115 2 => 'low',
116 1 => 'info',
117 );
118  
119 0 ▶ return $map{$pc_severity} // 'medium';
Condition0%0/2
$map{$pc_severity} // "medium"
l!l
00
MC/DC0%0/1
$map{$pc_severity} // "medium"
$map{$pc_severity}
Truth table0%0/2
A
A= $map{$pc_severity}
Aresult
11
00
120 }
121  
122 0 ▶sub _policy_to_category {
Subroutine _policy_to_category: not called CC=6 SCAR=37.4
123 0 my ($policy) = @_;
124  
125 0 ▶ return 'style' unless $policy;
Branch: 1 branch
BranchTrueFalseTotal
unless $policy 0 0 0
126  
127 0 ▶ return 'security' if $policy =~ /Security|InputOutput::RequireChecked/i;
Branch: 1 branch
BranchTrueFalseTotal
if $policy =~ /Security|InputOutput::RequireChecked/iu 0 0 0
128 0 ▶ return 'bugs' if $policy =~ /Bug|Error|Strict|RequireExplicit/i;
Branch: 1 branch
BranchTrueFalseTotal
if $policy =~ /Bug|Error|Strict|RequireExplicit/iu 0 0 0
129 0 ▶ return 'performance' if $policy =~ /Perform|RegularExpressions::Prohibit/i;
Branch: 1 branch
BranchTrueFalseTotal
if $policy =~ /Perform|RegularExpressions::Prohibit/iu 0 0 0
130 0 ▶ return 'maintainability' if $policy =~ /Complex|Subroutines::Prohibit|Modules::Require/i;
Branch: 1 branch
BranchTrueFalseTotal
if $policy =~ /Complex|Subroutines::Prohibit|Modules::Require/iu 0 0 0
131 0 return 'style';
132 }
133  
134  
135 4 1;
136  
137 __END__
↑ Summary Review.pm »