Policy/ValuesAndExpressions/ProhibitListsInMultiConstants.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 79.1% 19 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 91.3% 74 / 81 CC 13 SCAR 14.6
CC
13
Cov
91%
violates
7.1
__ANON__
6.0
default_themes
2.0
CRAP 4.3
« Policy/CodeLayout/RequireKRParens.pm ↑ Summary Policy/CodeLayout/RequireSpaceAroundBinaryOperators.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitListsInMultiConstants;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use parent qw[ Perl::Critic::Policy ];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Critic::Utils qw[ :severities :classification ];
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use constant { # PPI search return values
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 MATCH => 1,
9 NO_MATCH => 0,
10 NO_DESCEND => undef,
11 2 };
12  
13 2 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
14 0 ▶sub default_themes { return qw[ bugs ] }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
15 4 ▶sub applies_to { return 'PPI::Statement::Include' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
16  
17 5 ▶sub violates {
Subroutine violates: called CC=7 SCAR=19.6
Pod documented
18 5 my ($self, $elem, $doc) = @_;
19 5 ▶ return if not $elem->pragma;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->pragma 0 5 5
20 5 ▶ return if $elem->module ne 'constant';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->module ne "constant" 0 5 5
21  
22 5 my ($hash) = $elem->arguments;
23 5 ▶ return if not $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $hash 0 5 5
24 5 ▶ return if not $hash->isa('PPI::Structure::Constructor');
Branch: 1 branch
BranchTrueFalseTotal
unless $hash->isa("PPI::Structure::Constructor") 2 3 5
25 3 ▶ return if $hash->braces ne '{}';
Branch: 1 branch
BranchTrueFalseTotal
if $hash->braces ne "{}" 0 3 3
26  
27 66 ▶ my $lists_ref = $hash->find(sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
28 66 my $el = $_[1];
29  
30 66 ▶ if ($el->isa('PPI::Structure::List')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->isa("PPI::Structure::List")) 3 63 66
31 3 ▶ return _is_function_arg($el) ? NO_DESCEND : MATCH;
Branch: 1 branch
BranchTrueFalseTotal
_is_function_arg($el) ? : 2 1 3
32 }
33 63 ▶ return MATCH if $el->isa('PPI::Token::QuoteLike::Words');
Branch: 1 branch
BranchTrueFalseTotal
if $el->isa("PPI::Token::QuoteLike::Words") 1 62 63
34  
35 # descend only into top-level expressions
36 62 ▶ return NO_DESCEND if not $el->isa('PPI::Statement::Expression');
Branch: 1 branch
BranchTrueFalseTotal
unless $el->isa("PPI::Statement::Expression") 58 4 62
37 4 ▶ return NO_DESCEND if $el->parent->isa('PPI::Statement::Expression');
Branch: 1 branch
BranchTrueFalseTotal
if $el->parent->isa("PPI::Statement::Expression") 0 4 4
38  
39 4 return NO_MATCH;
40 3 });
41 3 ▶ return if not $lists_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $lists_ref 2 1 3
42  
43 my @violations = map {
44 1 $self->violation('List inside a multiple constant declaration',
45 'Use a separate constant declaration to use a list', $_)
46 } @$lists_ref;
47 1 return @violations;
48 }
49  
50 3 ▶sub _is_function_arg {
Subroutine _is_function_arg: called CC=2 SCAR=6.9
51 3 my ($elem) = @_;
52 3 my $prev = $elem->sprevious_sibling;
53 3 ▶ return if not $prev->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $prev->isa("PPI::Token::Word") 1 2 3
54 2 return is_function_call($prev);
55 }
56  
57 2 1;
58 __END__
« Policy/CodeLayout/RequireKRParens.pm ↑ Summary Policy/CodeLayout/RequireSpaceAroundBinaryOperators.pm »