| 1 | package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings; | ||||||||||||||||||||||||||||||||||||||||||
| 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::Exception::Fatal::Internal qw{ throw_internal }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities :data_conversion }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | Readonly::Scalar my $DESC => q{Warnings disabled}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $EXPL => [ 431 ]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 92 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 92 | name => 'allow', | |||||||||||||||||||||||||||||||||||||||||
| 27 | description => 'Permitted warning categories.', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | default_string => $EMPTY, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | parser => \&_parse_allow, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | name => 'allow_with_category_restriction', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | description => | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 'Allow "no warnings" if it restricts the kinds of warnings that are turned off.', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | default_string => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | behavior => 'boolean', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 74 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 91 | ▶ | sub default_themes { return qw( core bugs pbp certrec ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 33 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 90 | ▶ | sub _parse_allow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_allow: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 90 | my ($self, undef, $config_string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 90 | $self->{_allow} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 90 | ▶ | if( defined $config_string ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $allowed = lc $config_string; #String of words | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my %allowed = hashify( $allowed =~ m/ (experimental::\w+|\w+) /gxms ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $self->{_allow} = \%allowed; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 90 | return; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 61 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=44.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 61 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 61 | ▶ | return if $elem->type() ne 'no'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return if $elem->pragma() ne 'warnings'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my @words = _extract_potential_categories( $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | @words >= 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@words >= 2 and "no" eq $words[0] and "warnings" eq $words[1]
@words >= 2 and "no" eq $words[0]
MC/DC0%0/3
@words >= 2 and "no" eq $words[0] and "warnings" eq $words[1]
@words >= 2
"no" eq $words[0]
"warnings" eq $words[1]
Truth table0%0/4
A and B and C
A= @words >= 2B= "no" eq $words[0]C= "warnings" eq $words[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | and 'no' eq $words[0] | ||||||||||||||||||||||||||||||||||||||||||
| 74 | and 'warnings' eq $words[1] | ||||||||||||||||||||||||||||||||||||||||||
| 75 | or throw_internal | ||||||||||||||||||||||||||||||||||||||||||
| 76 | q<'no warnings' word list did not begin with qw{ no warnings }>; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | splice @words, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return if $self->{_allow_with_category_restriction} and @words; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_allow_with_category_restriction"} and @words
MC/DC0%0/2
$self->{"_allow_with_category_restriction"} and @words
$self->{"_allow_with_category_restriction"}
@words
Truth table0%0/3
A and B
A= $self->{"_allow_with_category_restriction"}B= @words
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 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)
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | #If we get here, then it must be a violation | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Traverse the element, accumulating and ultimately returning things | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # that might be warnings categories. These are: | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # * Words (because of the 'foo' in 'no warnings foo => "bar"'); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # * Quotes (because of 'no warnings "foo"'); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # * qw{} strings (obviously); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # * Nodes (because of 'no warnings ( "foo", "bar" )'). | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # We don't lop off the 'no' and 'warnings' because we recurse. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # RT #74647. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Readonly::Array my @HANDLER => ( | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | [ 'PPI::Token::Word' => sub { return $_[0]->content() } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | [ 'PPI::Token::QuoteLike::Words' => | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub { return $_[0]->literal() }, ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | [ 'PPI::Token::Quote' => sub { return $_[0]->string() } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | [ 'PPI::Node' => sub { _extract_potential_categories( $_[0] ) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _extract_potential_categories { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_potential_categories: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my @words; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | foreach my $child ( $elem->schildren() ) { | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $hdlr ( @HANDLER ) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $child->isa( $hdlr->[0] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | push @words, $hdlr->[1]->( $child ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return @words; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||