| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$file_list and @{$file_list;}
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;}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | eval { require Perl::Critic; 1; }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | die "ERROR: Perl::Critic is not installed!\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $severity = $ENV{PERLCRITIC_SEVERITY} || $DEFAULT_SEVERITY; | ||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'PERLCRITIC_SEVERITY'} || $CPAN::Maker::Bootstrapper::Role::Critic::DEFAULT_SEVERITY
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
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my %options = ( | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $ENV{PERLCRITICRC} ? ( '-profile' => $ENV{PERLCRITICRC} ) : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | if !-e "$base_file.pm"; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | open STDERR, '|-', 'tee', $base_file . '.crit' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 92 | or die $OS_ERROR; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | open STDERR, '>&', $old_stderr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | or die $OS_ERROR; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( keys %has_violations ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$has_violations{$_} // 0
$has_violations{$_}
Truth table0%0/2
A
A= $has_violations{$_}
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return keys %has_violations ? $FAILURE : $SUCCESS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | 1; | |||||||||||||||||||||||||||