« lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitUselessTopic.pm
↑ Summary
lib/Perl/Critic/Policy/RegularExpressions/ProhibitFixedStringMatches.pm »
| 1 | package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use List::SomeUtils qw(all); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities :data_conversion }; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $DESC => q{Stricture disabled}; | |||||||||||||||||||||||||||||||||
| 18 | 40 | Readonly::Scalar my $EXPL => [ 429 ]; | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 91 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 23 | return ( | ||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||
| 25 | 91 | name => 'allow', | |||||||||||||||||||||||||||||||||
| 26 | description => 'Allow vars, subs, and/or refs.', | ||||||||||||||||||||||||||||||||||
| 27 | default_string => $EMPTY, | ||||||||||||||||||||||||||||||||||
| 28 | parser => \&_parse_allow, | ||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 74 | ▶ | sub default_severity { return $SEVERITY_HIGHEST } | ||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 34 | 91 | ▶ | sub default_themes { return qw( core pbp bugs certrec ) } | ||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 35 | 37 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 89 | ▶ | sub _parse_allow { | ||||||||||||||||||||||||||||||||
|
Subroutine
_parse_allow: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 40 | 89 | my ($self, undef, $config_string) = @_; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 89 | $self->{_allow} = {}; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 89 | ▶ | if( defined $config_string ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 2 | my $allowed = lc $config_string; #String of words | |||||||||||||||||||||||||||||||||
| 46 | 2 | my %allowed = hashify( $allowed =~ m/ (\w+) /gxms ); | |||||||||||||||||||||||||||||||||
| 47 | 2 | $self->{_allow} = \%allowed; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 89 | return; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 63 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=8 SCAR=39.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 56 | 63 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 63 | ▶ | return if $elem->type() ne 'no'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return if $elem->pragma() ne 'strict'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | #Arguments to 'no strict' are usually a list of literals or a qw() | ||||||||||||||||||||||||||||||||||
| 62 | #list. Rather than trying to parse the various PPI elements, I | ||||||||||||||||||||||||||||||||||
| 63 | #just use a regex to split the statement into words. This is | ||||||||||||||||||||||||||||||||||
| 64 | #kinda lame, but it does the trick for now. | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | # TODO consider: a possible alternate implementation: | ||||||||||||||||||||||||||||||||||
| 67 | # my $re = join q{|}, keys %{$self->{allow}}; | ||||||||||||||||||||||||||||||||||
| 68 | # return if $re && $stmnt =~ m/\b(?:$re)\b/mx; | ||||||||||||||||||||||||||||||||||
| 69 | # May need to detaint for that to work... Not sure. | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 0 | my $stmnt = $elem->statement(); | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return if !$stmnt; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | 0 | my @words = $stmnt =~ m/ ([[:lower:]]+) /gxms; | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | @words = grep { $_ ne 'qw' && $_ ne 'no' && $_ ne 'strict' } @words; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_ ne 'qw' && $_ ne 'no' && $_ ne 'strict'
$_ ne "qw" and $_ ne "no"
MC/DC0%0/3
$_ ne 'qw' && $_ ne 'no' && $_ ne 'strict'
$_ ne "qw"
$_ ne "no"
$_ ne 'strict'
Truth table0%0/4
A and B && C
A= $_ ne "qw"B= $_ ne "no"C= $_ ne 'strict'
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return if @words && all { exists $self->{_allow}->{$_} } @words; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
@words and &all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
MC/DC0%0/2
@words and &all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
@words
&all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
Truth table0%0/3
A and B
A= @wordsB= &all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
| |||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | #If we get here, then it must be a violation | ||||||||||||||||||||||||||||||||||
| 78 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 40 | 1; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||||