| 1 | package Perl::Critic::Policy::References::ProhibitUnnecessaryRefs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Scalar::Util qw/refaddr/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Perl::Critic::Utils qw/:severities :classification/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $VERSION = '0.1.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | Readonly::Scalar my $DESC=>q{Use Perl basic types.}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | Readonly::Scalar my $EXPL=>undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | name => 'self', | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | description => 'Report instances of $self.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | default_string => '0', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | behavior => 'boolean', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 62 | ▶ | sub applies_to { return qw/PPI::Statement::Variable PPI::Token::Operator/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 53 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub default_themes { return qw/cosmetic/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # When a subscript is encountered, what is it's sigiled type? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | my %subscriptToType=( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | '[]'=>'@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | '{}'=>'%', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | '()'=>'&', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # For these sigils, any subscript must be checked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # EG $$var[] versus $$var{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # EG @$var[] versus @$var{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | my %subscriptTypes=map {$_=>1} ('$','@'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # The following operators are considered when tracking variable assignments | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | my %assignmentOperator=map {$_=>1} qw{ = &&= ||= //= }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Create a randomly-named cache inside the policy instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 11 | my $cachekey; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | ▶ | sub initialize_if_enabled { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize_if_enabled: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | my ($self,$config)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | my $name='__PROHIBITUNNEEDEDREF'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | my $suffix=int(rand(1e9)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | my $retry=3; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | while($retry&&exists($$self{"$name$suffix"})) { $suffix=int(rand(1e9)); $retry-- } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$retry and exists $$self{"$name$suffix"}
MC/DC0%0/2
$retry and exists $$self{"$name$suffix"}
$retry
exists $$self{"$name$suffix"}
Truth table33%1/3
A and B
A= $retryB= exists $$self{"$name$suffix"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if(exists($$self{"$name$suffix"})) { warn 'RequireConsistentReturn unable to build subroutine cache' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | else { $cachekey="$name$suffix" } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 65 | ▶ | sub initCache { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initCache: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 65 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if(!$cachekey) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 65 | $$self{$cachekey}={ # Note that all stacks are push/pop based, so [-1] is the top of the stack | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | pending=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # 'lockey'=>[{type=>'stmt var', ...}, ...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | scope=>[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # node (Document, Statement::Block, ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | scopes=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # 'lockey of scope node'=>1 # present if we're still within self-or-descendant of that scope node | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | symbol=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # "$symbol"=>[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # {key=>"lockey $symbol", scope=>'lockey of scope node at declaration'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | var=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # 'lockey $symbol'=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # usage=>{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # 'x'=>1, for x=$@%&* | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # decl=>{node=>node} # maybe not needed, unsure | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub fetchCache { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchCache: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | return %{$$self{$cachekey}//{}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{$cachekey} // {}
MC/DC0%0/1
$self->{$cachekey} // {}
$self->{$cachekey}
Truth table50%1/2
A
A= $self->{$cachekey}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1291 | ▶ | sub lockey { my ($node)=@_; return join(q{ },map {$_//'u'} @{$node->location()//[]}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lockey: called CC=3 SCAR=11.0
Pod
undocumented
Condition75%3/4
$_ // "u"
$node->location // []
MC/DC100%1/1
$_ // "u"
$_
MC/DC0%0/1
$node->location // []
$node->location
Truth table100%2/2
A
A= $_
Truth table50%1/2
A
A= $node->location
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 337 | ▶ | sub symkey { my ($node,$symbol)=@_; return sprintf('%s %s',lockey($node),$symbol) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symkey: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 141 | ▶ | sub handlePending { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handlePending: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 141 | my ($self,%event)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 141 | ▶ | if($event{type} eq 'recordAssignment') { $self->recordAssignment(@event{qw/node symbol exempt/}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 141 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Consider the statement node S for "$x=f(x)". | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # The LHS node("$x") has parent=S, which means the scoping action to be performed occurs when S is entered (not when "$x" is left). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # This only happens when there's no next sibling, so there's no pending processing for non-terminal nodes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # When the top of document is reached, there is no parent and the step returns undefined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1034 | ▶ | sub step { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=16 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1034 | my ($self,$node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1034 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1034 | ▶ | if($node->isa('PPI::Node')&&($res=$node->schild(0))) { return $res } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node->isa("PPI::Node") and $res = $node->schild(0)
MC/DC100%2/2
$node->isa("PPI::Node") and $res = $node->schild(0)
$node->isa("PPI::Node")
$res = $node->schild(0)
Truth table100%3/3
A and B
A= $node->isa("PPI::Node")B= $res = $node->schild(0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 645 | ▶ | if($node->isa('PPI::Element')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 645 | my ($parent,$snext)=($node,$node->snext_sibling()); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 645 | ▶ | while($parent&&!$snext) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parent and not $snext
MC/DC100%2/2
$parent and not $snext
$parent
not $snext
Truth table100%3/3
A and not(B)
A= $parentB= not $snext
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 543 | $parent=$parent->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 543 | ▶ | $snext=$parent?$parent->snext_sibling():undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 543 | ▶ | if($parent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 478 | my $loc=lockey($parent); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 478 | ▶ | if(my $things=delete($$self{$cachekey}{pending}{$loc})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 104 | foreach my $thing (@$things) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 141 | $self->handlePending(%$thing) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 478 | ▶ | while(!$$self{$cachekey}{scope}[-1]->ancestor_of($snext?$snext:$parent)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 42 | my $locscope=lockey($$self{$cachekey}{scope}[-1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 42 | foreach my $varscopes (values %{$$self{$cachekey}{symbol}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 72 | ▶ | while(($#$varscopes>-1)&&($locscope eq $$varscopes[-1]{scope})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$varscopes->$#* > -1 and $locscope eq $varscopes->[-1]{"scope"}
MC/DC100%2/2
$varscopes->$#* > -1 and $locscope eq $varscopes->[-1]{"scope"}
$varscopes->$#* > -1
$locscope eq $varscopes->[-1]{"scope"}
Truth table100%3/3
A and B
A= $varscopes->$#* > -1B= $locscope eq $varscopes->[-1]{"scope"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | pop(@$varscopes) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 42 | delete($$self{$cachekey}{scopes}{lockey($$self{$cachekey}{scope}[-1])}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 42 | pop @{$$self{$cachekey}{scope}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 645 | ▶ | if($parent) { return $snext } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 65 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # If the $node is a basic casting operator, return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # type =>one of $@%&* | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # symbol=>'$var', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # node =>$varnode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # next =>$aftervarnode, # after the var, possibly a subscript | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # $$var | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # @$var | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # %$var | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # *$var | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # &$var | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # ${$var} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # @{$var} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # %{$var} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # *{$var} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # &{$var} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # $$var[idx] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # @$var[idxs] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # $$var{key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # @$var{keys} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # %$var{keys} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # ${$var}[idx] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # @{$var}[idxs] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # ${$var}{key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # @{$var}{keys} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # %{$var}{keys} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # *$globref{THING} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # *{$globref}{THING} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1064 | ▶ | sub isBasicCast { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isBasicCast: called CC=22 SCAR=31.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1064 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1064 | ▶ | if(!$node) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1063 | ▶ | if(!$node->isa('PPI::Token::Cast')) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 103 | my $sigil=$node->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 103 | ▶ | if($sigil eq '\\') { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 102 | my $next=$node->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if(!$next) { warn('Found casting operator applied to nothing'); return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 102 | ▶ | if($next->isa('PPI::Token::Symbol')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 82 | my $nnext=$next->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 82 | my $type=$sigil; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 82 | my $symbol=$next->symbol(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 82 | ▶ | if($subscriptTypes{$sigil}&&$nnext&&$nnext->isa('PPI::Structure::Subscript')) { $type=$subscriptToType{$nnext->braces()}//'?' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$subscriptTypes{$sigil} and $nnext and $nnext->isa("PPI::Structure::Subscript")
$subscriptTypes{$sigil} and $nnext
$subscriptToType{$nnext->braces} // "?"
MC/DC100%3/3
$subscriptTypes{$sigil} and $nnext and $nnext->isa("PPI::Structure::Subscript")
$subscriptTypes{$sigil}
$nnext
$nnext->isa("PPI::Structure::Subscript")
MC/DC0%0/1
$subscriptToType{$nnext->braces} // "?"
$subscriptToType{$nnext->braces}
Truth table100%4/4
A and B and C
A= $subscriptTypes{$sigil}B= $nnextC= $nnext->isa("PPI::Structure::Subscript")
Truth table50%1/2
A
A= $subscriptToType{$nnext->braces}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 82 | ▶ | if($sigil eq '*') { $symbol=$next->content() } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 82 | return (type=>$type,symbol=>$symbol,node=>$next,next=>$nnext); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif($next->isa('PPI::Structure::Block')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 18 | my @children=$next->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | ▶ | if($#children>0) { return } # this is a non-simple/evaluative block | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 17 | my $nnext=$children[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if(!$nnext->isa('PPI::Statement')) { return } # type guard | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 17 | @children=$nnext->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 17 | ▶ | if($#children>0) { return } # this is a compound etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 13 | my $nnnext=$children[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 13 | ▶ | if($nnnext->isa('PPI::Token::Symbol')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | my $subnext=$next->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 12 | my $type=$sigil; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | ▶ | if($subscriptTypes{$sigil}&&$subnext) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$subscriptTypes{$sigil} and $subnext
MC/DC100%2/2
$subscriptTypes{$sigil} and $subnext
$subscriptTypes{$sigil}
$subnext
Truth table100%3/3
A and B
A= $subscriptTypes{$sigil}B= $subnext
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | if($subnext->isa('PPI::Structure::Subscript')) { $type=$subscriptToType{$subnext->braces()}//'?' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$subscriptToType{$subnext->braces} // "?"
MC/DC0%0/1
$subscriptToType{$subnext->braces} // "?"
$subscriptToType{$subnext->braces}
Truth table50%1/2
A
A= $subscriptToType{$subnext->braces}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | if($subnext->isa('PPI::Structure::Constructor')) { $type=$subscriptToType{$subnext->braces()}//'?' } # PPI bug? | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$subscriptToType{$subnext->braces} // "?"
MC/DC0%0/1
$subscriptToType{$subnext->braces} // "?"
$subscriptToType{$subnext->braces}
Truth table50%1/2
A
A= $subscriptToType{$subnext->braces}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 12 | return (type=>$type, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | symbol=>$nnnext->symbol(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | node=>$nnnext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | next=>$subnext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # If the $node dereferences a scalar variable, return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # type =>one of $@%&* | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # symbol=>'$var', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # node =>$varnode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # next =>$aftervarnode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 974 | ▶ | sub isSubscriptedSymbol { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isSubscriptedSymbol: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 974 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if(!$node) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 974 | ▶ | if(!$node->isa('PPI::Token::Symbol')) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 82 | my ($next,$prev)=($node->snext_sibling(),$node->sprevious_sibling()); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 82 | ▶ | if($next&&$next->isa('PPI::Token::Operator')&&($next->content() eq '->')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$next and $next->isa("PPI::Token::Operator") and $next->content eq "->"
$next and $next->isa("PPI::Token::Operator")
MC/DC100%3/3
$next and $next->isa("PPI::Token::Operator") and $next->content eq "->"
$next
$next->isa("PPI::Token::Operator")
$next->content eq "->"
Truth table100%4/4
A and B and C
A= $nextB= $next->isa("PPI::Token::Operator")C= $next->content eq "->"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 27 | my $symbol=$node->symbol(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 27 | my $nnext=$next->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # The returned 'next' node is the '->' arrow, because step() will move onward to the subscript itself, which needs to be separately checked for usages | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 27 | ▶ | if($nnext->isa('PPI::Structure::Subscript')) { return (type=>$subscriptToType{$nnext->braces()},symbol=>$symbol,node=>$node,next=>$next) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | elsif($nnext->isa('PPI::Structure::List')) { return (type=>'&',symbol=>$symbol,node=>$node,next=>$next) } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | elsif($nnext->isa('PPI::Token::Word')) { return (type=>'B',symbol=>$symbol,node=>$node,next=>$next) } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | elsif($nnext->isa('PPI::Token::Cast')) { return; warn("Post-deref not yet supported") } # backwards=silence | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # isBasicCast already performed a precheck for casting | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # A PPI::Token::Symbol that is not resolvable with the above logic is not a "subscripted symbol" for the sake of this check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # For example, it may be the LHS of an assignment so the type cannot be established until usage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 55 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 85 | ▶ | sub recordUsage { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recordUsage: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 85 | my ($self,%data)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 85 | my $cache=$$self{$cachekey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 85 | ▶ | $$cache{symbol}{$data{symbol}}//=[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache->{"symbol"}{$data{"symbol"}} //= []
MC/DC100%1/1
$cache->{"symbol"}{$data{"symbol"}} //= []
$cache->{"symbol"}{$data{"symbol"}}
Truth table100%2/2
A
A= $cache->{"symbol"}{$data{"symbol"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 85 | @{$$cache{symbol}{$data{symbol}}} || | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | push @{$$cache{symbol}{$data{symbol}}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | key=>symkey($data{node},$data{symbol}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 85 | ▶ | scope=>lockey($$cache{scope}[-1]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 85 | my $symkey=$$cache{symbol}{$data{symbol}}[-1]{key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 85 | ▶ | $$cache{var}{$symkey}//={}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache->{"var"}{$symkey} //= {}
MC/DC100%1/1
$cache->{"var"}{$symkey} //= {}
$cache->{"var"}{$symkey}
Truth table100%2/2
A
A= $cache->{"var"}{$symkey}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 85 | $$cache{var}{$symkey}{usage}{$data{type}}=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 85 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # node is the location of the assignment operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # symbol is the Token::Symbol that is assigned | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 141 | ▶ | sub recordAssignment { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recordAssignment: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 141 | my ($self,$node,$symbol,$exempt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 141 | my $cache=$$self{$cachekey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 141 | ▶ | $$cache{symbol}{$symbol->content()}//=[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache->{"symbol"}{$symbol->content} //= []
MC/DC100%1/1
$cache->{"symbol"}{$symbol->content} //= []
$cache->{"symbol"}{$symbol->content}
Truth table100%2/2
A
A= $cache->{"symbol"}{$symbol->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 141 | my $C=$$cache{symbol}{$symbol->content()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 141 | my $symkey=symkey($node,$symbol->content()); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 141 | push @$C,{key=>$symkey,scope=>lockey($$cache{scope}[-1])}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 141 | my $type=$symbol->symbol_type(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if($type ne '$') { $$cache{var}{$symkey}{usage}{$type}=1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 141 | ▶ | if($exempt) { $$cache{var}{$symkey}{exempt}=1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 141 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Find all bare scalar symbols on the left of a known assignment node. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 160 | ▶ | sub assignedVariables { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assignedVariables: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 160 | my ($self,$node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 160 | my $parent=$node->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if(!$parent) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 160 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1170 | ▶ | $parent->find(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1170 | my (undef,$e)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1170 | my ($p,$n)=($e->sprevious_sibling(),$e->snext_sibling()); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1170 | ▶ | if($n&&$n->isa('PPI::Structure::Subscript')) { return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n and $n->isa("PPI::Structure::Subscript")
MC/DC100%2/2
$n and $n->isa("PPI::Structure::Subscript")
$n
$n->isa("PPI::Structure::Subscript")
Truth table100%3/3
A and B
A= $nB= $n->isa("PPI::Structure::Subscript")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if($p&&$p->isa('PPI::Token::Cast')) { return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p and $p->isa("PPI::Token::Cast")
MC/DC0%0/2
$p and $p->isa("PPI::Token::Cast")
$p
$p->isa("PPI::Token::Cast")
Truth table66%2/3
A and B
A= $pB= $p->isa("PPI::Token::Cast")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1124 | ▶ | if($e->isa('PPI::Token::Symbol')&&($e->symbol_type() eq '$')) { push @res,$e; return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$e->isa("PPI::Token::Symbol") and $e->symbol_type eq "\$"
MC/DC100%2/2
$e->isa("PPI::Token::Symbol") and $e->symbol_type eq "\$"
$e->isa("PPI::Token::Symbol")
$e->symbol_type eq "\$"
Truth table100%3/3
A and B
A= $e->isa("PPI::Token::Symbol")B= $e->symbol_type eq "\$"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 160 | ▶ | elsif($e->isa('PPI::Token::Operator')&&(refaddr($e)==refaddr($node))) { die 'done searching' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$e->isa("PPI::Token::Operator") and builtin::refaddr($e) == builtin::refaddr($node)
MC/DC100%2/2
$e->isa("PPI::Token::Operator") and builtin::refaddr($e) == builtin::refaddr($node)
$e->isa("PPI::Token::Operator")
builtin::refaddr($e) == builtin::refaddr($node)
Truth table100%3/3
A and B
A= $e->isa("PPI::Token::Operator")B= builtin::refaddr($e) == builtin::refaddr($node)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ▶ | elsif($e->isa('PPI::Token::Operator')&&$assignmentOperator{$e->content()}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$e->isa("PPI::Token::Operator") and $assignmentOperator{$e->content}
MC/DC100%2/2
$e->isa("PPI::Token::Operator") and $assignmentOperator{$e->content}
$e->isa("PPI::Token::Operator")
$assignmentOperator{$e->content}
Truth table100%3/3
A and B
A= $e->isa("PPI::Token::Operator")B= $assignmentOperator{$e->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # refaddr(e)!=refaddr(node) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # This is an assignment to the left of our assignment, and should have been captured using assignedVariables(e). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 36 | @res=(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 796 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 160 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 160 | return @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 65 | ▶ | sub analyze { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
analyze: called CC=20 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 65 | my ($self,$doc)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 65 | my $node=$doc; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if(!$node->isa('PPI::Node')) { die "Unable to analyze node ($node)" } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 65 | ▶ | while($node) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1034 | ▶ | if(my %cast=isBasicCast($node)) { $self->recordUsage(%cast); $node=$cast{next}||$cast{node} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%2/3
$cast{'next'} || $cast{'node'}
MC/DC0%0/2
$cast{'next'} || $cast{'node'}
$cast{'next'}
$cast{'node'}
Truth table66%2/3
A || B
A= $cast{'next'}B= $cast{'node'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 15 | ▶ | elsif(my %subscript=isSubscriptedSymbol($node)) { $self->recordUsage(%subscript); $node=$subscript{next}||$subscript{node} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$subscript{'next'} || $subscript{'node'}
MC/DC0%0/2
$subscript{'next'} || $subscript{'node'}
$subscript{'next'}
$subscript{'node'}
Truth table33%1/3
A || B
A= $subscript{'next'}B= $subscript{'node'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ▶ | elsif($node->isa('PPI::Structure::Block')||$node->isa('PPI::Statement::Compound')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$node->isa("PPI::Structure::Block") or $node->isa("PPI::Statement::Compound")
MC/DC100%2/2
$node->isa("PPI::Structure::Block") or $node->isa("PPI::Statement::Compound")
$node->isa("PPI::Structure::Block")
$node->isa("PPI::Statement::Compound")
Truth table100%3/3
A or B
A= $node->isa("PPI::Structure::Block")B= $node->isa("PPI::Statement::Compound")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 42 | push @{$$self{$cachekey}{scope}},$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 42 | $$self{$cachekey}{scopes}{lockey($node)}=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | elsif($node->isa('PPI::Statement::Variable')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 89 | foreach my $symbol (grep {'$' eq $_->symbol_type()} $node->symbols()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 104 | ▶ | my %exempt; if(($symbol eq '$self')&&!$$self{_self}) { %exempt=(exempt=>1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$symbol eq "\$self" and not $self->{"_self"}
MC/DC100%2/2
$symbol eq "\$self" and not $self->{"_self"}
$symbol eq "\$self"
not $self->{"_self"}
Truth table100%3/3
A and not(B)
A= $symbol eq "\$self"B= not $self->{"_self"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 104 | push @{$$self{$cachekey}{pending}{lockey($node)}},{type=>'recordAssignment',node=>$node,symbol=>$symbol,%exempt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 89 | ▶ | if(my $assign=$node->find_first(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 534 | my (undef,$e)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 534 | ▶ | if(!$e->isa('PPI::Token::Operator')) { return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 101 | ▶ | if($e->content() eq '=') { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 37 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 64 | })) { $node=$assign } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 25 | ▶ | else { $node=$node->last_element()||$node } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$node->last_element || $node
MC/DC0%0/2
$node->last_element || $node
$node->last_element
$node
Truth table33%1/3
A || B
A= $node->last_elementB= $node
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ▶ | elsif($node->isa('PPI::Token::Operator')&&$assignmentOperator{$node->content()}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$node->isa("PPI::Token::Operator") and $assignmentOperator{$node->content}
MC/DC100%2/2
$node->isa("PPI::Token::Operator") and $assignmentOperator{$node->content}
$node->isa("PPI::Token::Operator")
$assignmentOperator{$node->content}
Truth table100%3/3
A and B
A= $node->isa("PPI::Token::Operator")B= $assignmentOperator{$node->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 51 | foreach my $symbol ($self->assignedVariables($node)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 37 | ▶ | my %exempt; if(($symbol eq '$self')&&!$$self{_self}) { %exempt=(exempt=>1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$symbol eq "\$self" and not $self->{"_self"}
MC/DC100%2/2
$symbol eq "\$self" and not $self->{"_self"}
$symbol eq "\$self"
not $self->{"_self"}
Truth table100%3/3
A and not(B)
A= $symbol eq "\$self"B= not $self->{"_self"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 37 | push @{$$self{$cachekey}{pending}{lockey($node->parent())}},{type=>'recordAssignment',node=>$node,symbol=>$symbol,%exempt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1034 | $node=$self->step($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 65 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 65 | ▶ | sub prepare_to_scan_document { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_to_scan_document: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 65 | my ($self,$doc)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if(!$cachekey) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 65 | $self->initCache(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 65 | push @{$$self{$cachekey}{scope}},$doc; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 65 | $$self{$cachekey}{scopes}{lockey($doc)}=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 65 | $self->analyze($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 65 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 193 | ▶ | sub symbolUsageViolates { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbolUsageViolates: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 193 | my (%var)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 193 | ▶ | if($var{exempt}) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 188 | my ($sum,$sumah)=(0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 188 | ▶ | while(my ($k,$v)=each %{$var{usage}//{}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$var{"usage"} // {}
MC/DC100%1/1
$var{"usage"} // {}
$var{"usage"}
Truth table100%2/2
A
A= $var{"usage"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 61 | ▶ | if($v) { $sum++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 61 | ▶ | if(($k eq '@')||($k eq '%')) { $sumah++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$k eq "\@" or $k eq "%"
MC/DC100%2/2
$k eq "\@" or $k eq "%"
$k eq "\@"
$k eq "%"
Truth table100%3/3
A or B
A= $k eq "\@"B= $k eq "%"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | else { return } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 186 | return ($sumah==1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 53 | ▶ | sub invalid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invalid: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 53 | my ($self,$elem,$note)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 53 | ▶ | $note//=''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$note //= ""
MC/DC0%0/1
$note //= ""
$note
Truth table50%1/2
A
A= $note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 53 | ▶ | if($note) { $note=" ($note)" } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 53 | return $self->violation(sprintf("%s%s",$DESC,$note),$EXPL,$elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 252 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 252 | my ($self,$elem,undef)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if(!$cachekey) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 252 | ▶ | if($elem->isa('PPI::Token::Operator') && !$assignmentOperator{$elem->content()}) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$elem->isa("PPI::Token::Operator") and not $assignmentOperator{$elem->content}
MC/DC100%2/2
$elem->isa("PPI::Token::Operator") and not $assignmentOperator{$elem->content}
$elem->isa("PPI::Token::Operator")
not $assignmentOperator{$elem->content}
Truth table100%3/3
A and not(B)
A= $elem->isa("PPI::Token::Operator")B= not $assignmentOperator{$elem->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 192 | my %violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | my @vars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 192 | ▶ | if($elem->isa('PPI::Statement::Variable')) { @vars=$elem->variables() } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 109 | else { @vars=$self->assignedVariables($elem) } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 192 | foreach my $var (@vars) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 193 | ▶ | if(my $v=symkey($elem,$var)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 193 | ▶ | if(symbolUsageViolates(%{$$self{$cachekey}{var}{$v}//{}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{$cachekey}{"var"}{$v} // {}
MC/DC100%1/1
$self->{$cachekey}{"var"}{$v} // {}
$self->{$cachekey}{"var"}{$v}
Truth table100%2/2
A
A= $self->{$cachekey}{"var"}{$v}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 53 | $violations{$var}=undef } } } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 192 | ▶ | if(!%violations) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 53 | return $self->invalid($elem,join(',',sort keys(%violations))); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||