| 1 | package Perl::Critic::Policy::logicLAB::ModuleBlacklist; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Perl::Critic::Utils qw{ $SEVERITY_MEDIUM :booleans}; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp qw(carp); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use constant supported_parameters => qw(modules debug); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use constant default_severity => $SEVERITY_MEDIUM; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use constant default_themes => qw(logiclab); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 19 | return ( | ||||||||||||||||||||||||||||||||
| 20 | 9 | qw( | |||||||||||||||||||||||||||||||
| 21 | PPI::Statement::Include | ||||||||||||||||||||||||||||||||
| 22 | ) | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 17 | ▶ | sub violates { | ||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 27 | 17 | my ( $self, $elem ) = @_; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | #Policy not configured, nothing to assert | ||||||||||||||||||||||||||||||||
| 30 | 17 | ▶ | if ( not $self->{_modules} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 0 | return; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 17 | my @children = $elem->children; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 17 | ▶ | if ( $children[0]->content eq 'use' or $children[0]->content eq 'require' ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$children[0]->content eq "use" or $children[0]->content eq "require"
MC/DC100%2/2
$children[0]->content eq "use" or $children[0]->content eq "require"
$children[0]->content eq "use"
$children[0]->content eq "require"
Truth table100%3/3
A or B
A= $children[0]->content eq "use"B= $children[0]->content eq "require"
| |||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 16 | my $package = $children[2]->content; | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 16 | ▶ | if ( $self->{debug} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 0 | print STDERR "located include: $package\n"; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 16 | foreach my $module ( keys %{ $self->{_modules} } ) { | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 40 | ▶ | if ( $package eq $module ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | if ( defined $self->{_modules}->{$module} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 4 | my $recommendation = $self->{_modules}->{$module}; | |||||||||||||||||||||||||||||||
| 51 | 4 | return $self->violation( | |||||||||||||||||||||||||||||||
| 52 | "Blacklisted: $package is not recommended by required standard", | ||||||||||||||||||||||||||||||||
| 53 | "Use recommended module: $recommendation instead of $package", | ||||||||||||||||||||||||||||||||
| 54 | $elem, | ||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 4 | return $self->violation( | |||||||||||||||||||||||||||||||
| 61 | "Blacklisted: $package is not recommended by required standard", | ||||||||||||||||||||||||||||||||
| 62 | "Use alternative implementation or module instead of $package", | ||||||||||||||||||||||||||||||||
| 63 | $elem, | ||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | #we ignore negative use statements, they are for pragma [issue1] | ||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | elsif ( $children[0]->content eq 'no' ) { | ||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | if ( $self->{debug} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | print STDERR "located 'no' use/require statement\n"; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||
| 77 | 0 | carp 'Unable to locate package keyword'; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 9 | return; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub initialize_if_enabled { | ||||||||||||||||||||||||||||||
|
Subroutine
initialize_if_enabled: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 84 | 1 | my ( $self, $config ) = @_; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | #debug - order is significant, since we might need debugging | ||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | $self->{debug} = $config->get('debug') || $FALSE; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$config->get('debug') || $Perl::Critic::Policy::logicLAB::ModuleBlacklist::FALSE
MC/DC0%0/2
$config->get('debug') || $Perl::Critic::Policy::logicLAB::ModuleBlacklist::FALSE
$config->get('debug')
$Perl::Critic::Policy::logicLAB::ModuleBlacklist::FALSE
Truth table33%1/3
A || B
A= $config->get('debug')B= $Perl::Critic::Policy::logicLAB::ModuleBlacklist::FALSE
| |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | #Names: | ||||||||||||||||||||||||||||||||
| 90 | #fetching list of blacklisted modules | ||||||||||||||||||||||||||||||||
| 91 | 1 | my $modules = $config->get('modules'); | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if ( $self->{debug} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 0 | carp "Blacklisted modules are: $modules\n"; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | #parsing blacklisted modules, see also _parse_blacklist | ||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | if ($modules) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | $self->{_modules} = $self->_parse_modules($modules) || q{}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_parse_modules($modules) || ''
MC/DC0%0/1
$self->_parse_modules($modules) || ''
$self->_parse_modules($modules)
Truth table50%1/2
A
A= $self->_parse_modules($modules)
| |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 1 | return $TRUE; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub _parse_modules { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_modules: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 106 | 1 | my ( $self, $config_string ) = @_; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | #first we split on commas | ||||||||||||||||||||||||||||||||
| 109 | 1 | my @parameters = split /\s*,\s*/, $config_string; | |||||||||||||||||||||||||||||||
| 110 | 1 | my %modules; | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | #then we split on fat commas, to locate recommendations | ||||||||||||||||||||||||||||||||
| 113 | 1 | foreach my $parameter (@parameters) { | |||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | if ( $parameter =~ m/\s*=>\s*/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 2 | my @p = split /\s*=>\s*/, $parameter; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 2 | $modules{ $p[0] } = $p[1]; | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||
| 120 | 1 | $modules{$parameter} = undef; | |||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 1 | return \%modules; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 3 | 1; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||