lib/Perl/Critic/Policy/CodeLayout/ProhibitQuotedWordLists.pm

filter: Statementstmt 64.5% 31 / 48 Branchbran 20.8% 5 / 24 Conditioncond 13.3% 2 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 46.4% 53 / 114 CC 19 SCAR 46.1
CC
19
Cov
44%
violates
167.0
_is_literal
6.0
BEGIN
1.0
CRAP 101.0
« lib/Perl/Critic/TestUtils.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/RequireArgUnpacking.pm »
1 package Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists;
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  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :characters :severities :classification};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $DESC => q{List of quoted literal words};
17 40 Readonly::Scalar my $EXPL => q{Use 'qw()' instead};
18  
19 #-----------------------------------------------------------------------------
20  
21 92 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22 return (
23 {
24 92 name => 'min_elements',
25 description => 'The minimum number of words in a list that will be complained about.',
26 default_string => '2',
27 behavior => 'integer',
28 integer_minimum => 1,
29 },
30 {
31 name => 'strict',
32 description => 'Complain even if there are non-word characters in the values.',
33 default_string => '0',
34 behavior => 'boolean',
35 },
36 );
37 }
38  
39 73 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
40 83 ▶sub default_themes { return qw( core cosmetic ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
41 31 ▶sub applies_to { return 'PPI::Structure::List' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
42  
43 #-----------------------------------------------------------------------------
44  
45 22 ▶sub violates {
Subroutine violates: called CC=18 SCAR=51.2
Pod documented
46 22 my ( $self, $elem, undef ) = @_;
47  
48 # Don't worry about subroutine calls
49 22 my $sibling = $elem->sprevious_sibling();
50 22 ▶ return if not $sibling;
Branch: 1 branch
BranchTrueFalseTotal
unless $sibling 0 22 22
51  
52 22 ▶ return if $sibling->isa('PPI::Token::Symbol');
Branch: 1 branch
BranchTrueFalseTotal
if $sibling->isa("PPI::Token::Symbol") 6 16 22
53 16 ▶ return if $sibling->isa('PPI::Token::Operator') and $sibling eq '->';
Branch: 1 branch
BranchTrueFalseTotal
if $sibling->isa("PPI::Token::Operator") and $sibling eq "->" 0 16 16
Condition33%1/3
$sibling->isa("PPI::Token::Operator") and $sibling eq "->"
!ll&&!rl&&r
1600
MC/DC0%0/2
$sibling->isa("PPI::Token::Operator") and $sibling eq "->"
$sibling->isa("PPI::Token::Operator") $sibling eq "->"
Truth table33%1/3
A and B
A= $sibling->isa("PPI::Token::Operator")B= $sibling eq "->"
ABresult
0X0
100
111
54 16 ▶ return if $sibling->isa('PPI::Token::Word') and not is_included_module_name($sibling);
Branch: 1 branch
BranchTrueFalseTotal
if $sibling->isa("PPI::Token::Word") and not is_included_module_name($sibling) 16 0 16
Condition33%1/3
$sibling->isa("PPI::Token::Word") and not is_included_module_name($sibling)
!ll&&!rl&&r
0016
MC/DC0%0/2
$sibling->isa("PPI::Token::Word") and not is_included_module_name($sibling)
$sibling->isa("PPI::Token::Word") not is_included_module_name($sibling)
Truth table33%1/3
A and not(B)
A= $sibling->isa("PPI::Token::Word")B= not is_included_module_name($sibling)
ABresult
0X0
100
111
55  
56 # Get the list elements
57 0 my $expr = $elem->schild(0);
58 0 ▶ return if not $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 0 0 0
59 0 my @children = $expr->schildren();
60 0 ▶ return if not @children;
Branch: 1 branch
BranchTrueFalseTotal
unless @children 0 0 0
61  
62 0 my $count = 0;
63 0 for my $child ( @children ) {
64 0 ▶ next if $child->isa('PPI::Token::Operator') && $child eq $COMMA;
Branch: 1 branch
BranchTrueFalseTotal
if $child->isa("PPI::Token::Operator") and $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA 0 0 0
Condition0%0/3
$child->isa("PPI::Token::Operator") and $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
!ll&&!rl&&r
000
MC/DC0%0/2
$child->isa("PPI::Token::Operator") and $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
$child->isa("PPI::Token::Operator") $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
Truth table0%0/3
A and B
A= $child->isa("PPI::Token::Operator")B= $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
ABresult
0X0
100
111
65  
66 # All elements must be literal strings,
67 # and must contain 1 or more word characters.
68  
69 0 ▶ return if not _is_literal($child);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_literal($child) 0 0 0
70  
71 0 my $string = $child->string();
72 0 ▶ return if $string =~ m{ \s }xms;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ / \s /msx 0 0 0
73 0 ▶ return if $string eq $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if $string eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::EMPTY 0 0 0
74 0 ▶ return if not $self->{_strict} and $string !~ m{\A [\w-]+ \z}xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_strict"} or $string =~ /\A [\w-]+ \z/msx 0 0 0
Condition0%0/3
$self->{"_strict"} or $string =~ /\A [\w-]+ \z/msx
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_strict"} or $string =~ /\A [\w-]+ \z/msx
$self->{"_strict"} $string =~ /\A [\w-]+ \z/msx
Truth table0%0/3
A or B
A= $self->{"_strict"}B= $string =~ /\A [\w-]+ \z/msx
ABresult
1X1
011
000
75 0 $count++;
76 }
77  
78 # Were there enough?
79 0 ▶ return if $count < $self->{_min_elements};
Branch: 1 branch
BranchTrueFalseTotal
if $count < $self->{"_min_elements"} 0 0 0
80  
81 # If we get here, then all elements were literals
82 0 return $self->violation( $DESC, $EXPL, $elem );
83 }
84  
85 0 ▶sub _is_literal {
Subroutine _is_literal: not called CC=2 SCAR=17.9
86 0 my $elem = shift;
87 0 ▶ return $elem->isa('PPI::Token::Quote::Single')
Condition0%0/3
$elem->isa('PPI::Token::Quote::Single') || $elem->isa('PPI::Token::Quote::Literal')
l!l&&r!l&&!r
000
MC/DC0%0/2
$elem->isa('PPI::Token::Quote::Single') || $elem->isa('PPI::Token::Quote::Literal')
$elem->isa('PPI::Token::Quote::Single') $elem->isa('PPI::Token::Quote::Literal')
Truth table0%0/3
A || B
A= $elem->isa('PPI::Token::Quote::Single')B= $elem->isa('PPI::Token::Quote::Literal')
ABresult
1X1
011
000
88 || $elem->isa('PPI::Token::Quote::Literal');
89 }
90  
91 40 1;
92  
93 __END__
« lib/Perl/Critic/TestUtils.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/RequireArgUnpacking.pm »