Policy/ValuesAndExpressions/ProhibitArrayAssignAref.pm

filter: Statementstmt 100% 45 / 45 Branchbran 87.5% 14 / 16 Conditioncond 70.0% 7 / 10 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 91.0% 81 / 89 CC 13 SCAR 20.8
CC
13
Cov
93%
violates
13.3
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
« Policy/ValuesAndExpressions/ProhibitEmptyCommas.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitNullStatements.pm »
1 # Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
2  
3 # Perl-Critic-Pulp is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 3, or (at your option) any later
6 # version.
7 #
8 # Perl-Critic-Pulp is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
15  
16  
17 # eg.
18 # perlcritic -s ProhibitArrayAssignAref /usr/lib/perl5/Template/Test.pm
19  
20  
21 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref;
22 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use Perl::Critic::Pulp;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # uncomment this to run the ### lines
31 #use Smart::Comments;
32  
33 40 our $VERSION = 100;
34  
35 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_MEDIUM;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 40 ▶use constant default_themes => qw(pulp bugs);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 40 ▶use constant applies_to => ('PPI::Token::Symbol',
Subroutine BEGIN: called CC=1 SCAR=0.0
39 40 'PPI::Token::Cast');
40  
41 24 ▶sub violates {
Subroutine violates: called CC=13 SCAR=25.9
Pod documented
42 24 my ($self, $elem, $document) = @_;
43  
44 24 ▶ ($elem->isa('PPI::Token::Cast') ? $elem->content : $elem->raw_type)
Branch: 2 branches
BranchTrueFalseTotal
($elem->isa("PPI::Token::Cast") ? $elem->content : $elem->raw_type) eq "\@" or return 18 6 24
$elem->isa('PPI::Token::Cast') ? : 10 14 24
45 eq '@' or return;
46 ### ProhibitArrayAssignAref: $elem->content
47  
48 18 my $thing = 'Array';
49 18 for (;;) {
50 39 ▶ $elem = $elem->snext_sibling || return;
Condition50%1/2
$elem->snext_sibling || (return)
l!l
390
MC/DC0%0/1
$elem->snext_sibling || (return)
$elem->snext_sibling
Truth table50%1/2
A
A= $elem->snext_sibling
Aresult
11
00
51 39 ▶ last if $elem->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Operator") 18 21 39
52 ### skip: ref $elem
53  
54 # @foo[1,2] gives the [1,2] as a PPI::Structure::Subscript
55 # @{foo()}[1,2] gives the [1,2] as a PPI::Structure::Constructor
56 # the latter is probably wrong (as of PPI 1.215)
57 21 ▶ if ($elem->isa('PPI::Structure::Subscript')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Structure::Subscript") or $elem->isa("PPI::Structure::Constructor")) 11 10 21
Condition100%3/3
$elem->isa("PPI::Structure::Subscript") or $elem->isa("PPI::Structure::Constructor")
l!l&&r!l&&!r
8310
MC/DC100%2/2
$elem->isa("PPI::Structure::Subscript") or $elem->isa("PPI::Structure::Constructor")
$elem->isa("PPI::Structure::Subscript") $elem->isa("PPI::Structure::Constructor")
Truth table100%3/3
A or B
A= $elem->isa("PPI::Structure::Subscript")B= $elem->isa("PPI::Structure::Constructor")
ABresult
1X1
011
000
58 || $elem->isa('PPI::Structure::Constructor')) {
59 11 ▶ if ($elem->start eq '[') {
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->start eq '[') { } 5 6 11
elsif ($elem->start eq '{') { } 6 0 6
60 5 $thing = 'Array slice';
61 } elsif ($elem->start eq '{') {
62 6 $thing = 'Hash slice';
63 }
64 }
65 }
66 ### $thing
67 ### operator: $elem->content
68 18 ▶ $elem eq '=' or return;
Branch: 1 branch
BranchTrueFalseTotal
$elem eq "=" or return 18 0 18
69  
70 18 ▶ $elem = $elem->snext_sibling || return;
Condition50%1/2
$elem->snext_sibling || (return)
l!l
180
MC/DC0%0/1
$elem->snext_sibling || (return)
$elem->snext_sibling
Truth table50%1/2
A
A= $elem->snext_sibling
Aresult
11
00
71 18 ▶ ($elem->isa('PPI::Structure::Constructor') && $elem->start eq '[')
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Structure::Constructor") and $elem->start eq "[" or return 11 7 18
Condition66%2/3
$elem->isa("PPI::Structure::Constructor") and $elem->start eq "["
!ll&&!rl&&r
7011
MC/DC50%1/2
$elem->isa("PPI::Structure::Constructor") and $elem->start eq "["
$elem->isa("PPI::Structure::Constructor") $elem->start eq "["
Truth table66%2/3
A and B
A= $elem->isa("PPI::Structure::Constructor")B= $elem->start eq "["
ABresult
0X0
100
111
72 or return;
73  
74 11 return $self->violation
75 ("$thing assigned a [] arrayref, should it be a () list ?",
76 '', $elem);
77 }
78  
79 40 1;
80 __END__
« Policy/ValuesAndExpressions/ProhibitEmptyCommas.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitNullStatements.pm »