CPAN/Maker/Bootstrapper/Role/Critic.pm

filter: Statementstmt 45.8% 33 / 72 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 1 totaltotal 34.1% 43 / 126 CC 19 SCAR 55.2
CC
19
Cov
31%
cmd_critique
380.0
BEGIN
1.0
BEGIN
1.0
CRAP 249.3
« CPAN/Maker/Bootstrapper/Role/LLM/Reviewer.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Init.pm »
1 package CPAN::Maker::Bootstrapper::Role::Critic;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use CLI::Simple::Utils qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use List::Util qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 Readonly::Scalar our $DEFAULT_THEME => 'pbp';
18 2 Readonly::Scalar our $DEFAULT_SEVERITY => 5;
19  
20 ########################################################################
21 0 ▶sub cmd_critique {
Subroutine cmd_critique: not called CC=19 SCAR=59.4
Pod undocumented
22 ########################################################################
23 0 my ($self) = @_;
24  
25 0 my $file_list = eval {
26 0 ▶ if ( my $manifest = $self->get_file_list ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $manifest = $self->get_file_list) 0 0 0
27 0 my $list = slurp($manifest);
28 0 return [ split /\n/xsm, $list ];
29 }
30  
31 0 return [ ( $self->get_args ) ];
32 };
33  
34 die "ERROR: no files to critique\n$OS_ERROR"
35 0 ▶ if !$file_list || !@{$file_list};
Branch: 1 branch
BranchTrueFalseTotal
unless $file_list and @{$file_list;} 0 0 0
Condition0%0/3
$file_list and @{$file_list;}
!ll&&!rl&&r
000
MC/DC0%0/2
$file_list and @{$file_list;}
$file_list @{$file_list;}
Truth table0%0/3
A and B
A= $file_listB= @{$file_list;}
ABresult
0X0
100
111
36  
37 0 eval { require Perl::Critic; 1; };
38  
39 0 ▶ die "ERROR: Perl::Critic is not installed!\n"
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Maker::Bootstrapper::Role::Critic::EVAL_ERROR 0 0 0
40 if $EVAL_ERROR;
41  
42 0 ▶ my $theme = $ENV{PERLCRITIC_THEME} || $DEFAULT_THEME;
Condition0%0/3
$ENV{'PERLCRITIC_THEME'} || $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_THEME
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'PERLCRITIC_THEME'} || $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_THEME
$ENV{'PERLCRITIC_THEME'} $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_THEME
Truth table0%0/3
A || B
A= $ENV{'PERLCRITIC_THEME'}B= $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_THEME
ABresult
1X1
011
000
43 0 ▶ my $severity = $ENV{PERLCRITIC_SEVERITY} || $DEFAULT_SEVERITY;
Condition0%0/3
$ENV{'PERLCRITIC_SEVERITY'} || $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_SEVERITY
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'PERLCRITIC_SEVERITY'} || $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_SEVERITY
$ENV{'PERLCRITIC_SEVERITY'} $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_SEVERITY
Truth table0%0/3
A || B
A= $ENV{'PERLCRITIC_SEVERITY'}B= $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_SEVERITY
ABresult
1X1
011
000
44  
45 my %options = (
46 0 ▶ $ENV{PERLCRITICRC} ? ( '-profile' => $ENV{PERLCRITICRC} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERLCRITICRC'} ? : 0 0 0
47 '-theme' => $theme,
48 '-severity' => $severity,
49 );
50  
51 0 my $critic = Perl::Critic->new(%options);
52  
53 0 ▶ open my $old_stderr, '>&', \*STDERR
Branch: 1 branch
BranchTrueFalseTotal
open my $old_stderr, ">&", \*STDERR or die $CPAN::Maker::Bootstrapper::Role::Critic::OS_ERROR 0 0 0
54 or die $OS_ERROR;
55  
56 0 my %has_violations;
57  
58 0 foreach my $file ( @{$file_list} ) {
59 0 my ($base_file) = $file =~ /^(.*?)[.]p[ml](?:[.]in)?$/xsm;
60  
61 0 ▶ die "ERROR: $base_file not found.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$base_file.pm" 0 0 0
62 if !-e "$base_file.pm";
63  
64 0 ▶ open STDERR, '|-', 'tee', $base_file . '.crit'
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, "|-", "tee", $base_file . '.crit' or die "ERROR: could not open pipe to tee for $base_file.crit: $CPAN::Maker::Bootstrapper::Role::Critic::OS_ERROR\n" 0 0 0
65 or die "ERROR: could not open pipe to tee for $base_file.crit: $OS_ERROR\n";
66  
67 0 my @violations = $critic->critique( $base_file . '.pm' );
68  
69 0 foreach my $v (@violations) {
70 0 my $severity = $v->severity;
71 0 $has_violations{$severity}++;
72  
73 my $level = {
74 1 => 'info',
75 2 => 'info',
76 3 => 'warn',
77 4 => 'warn',
78 5 => 'error',
79 0 }->{$severity};
80  
81 0 my $violation_msg = $v->to_string;
82 0 chomp $violation_msg;
83 0 $violation_msg = "$violation_msg (Severity $severity)";
84 0 $self->get_logger->$level($violation_msg); # one write -> tee -> terminal AND .crit
85 }
86  
87 0 ▶ close STDERR
Branch: 1 branch
BranchTrueFalseTotal
close STDERR or die "ERROR: could not close pipe for $base_file.crit: $CPAN::Maker::Bootstrapper::Role::Critic::OS_ERROR\n" 0 0 0
88 or die "ERROR: could not close pipe for $base_file.crit: $OS_ERROR\n";
89 }
90  
91 0 ▶ open STDERR, '>&', $old_stderr
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $old_stderr or die $CPAN::Maker::Bootstrapper::Role::Critic::OS_ERROR 0 0 0
92 or die $OS_ERROR;
93  
94 0 ▶ open STDERR, '>&', $old_stderr
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $old_stderr or die $CPAN::Maker::Bootstrapper::Role::Critic::OS_ERROR 0 0 0
95 or die $OS_ERROR;
96  
97 0 ▶ if ( keys %has_violations ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %has_violations) 0 0 0
98 $self->get_logger->error( sprintf 'Total Violations: %s',
99 0 ▶ join q{, }, map { sprintf "%s: [%s]", $_, ( $has_violations{$_} // '0' ) } ( 1 .. 5 ) );
Condition0%0/2
$has_violations{$_} // 0
l!l
00
MC/DC0%0/1
$has_violations{$_} // 0
$has_violations{$_}
Truth table0%0/2
A
A= $has_violations{$_}
Aresult
11
00
100 }
101  
102 0 ▶ return keys %has_violations ? $FAILURE : $SUCCESS;
Branch: 1 branch
BranchTrueFalseTotal
keys %has_violations ? : 0 0 0
103 }
104  
105 2 1;
« CPAN/Maker/Bootstrapper/Role/LLM/Reviewer.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Init.pm »