blib/lib/Perl/Critic/Policy/Variables/ProhibitCallsWithAliasedTopic.pm

filter: Statementstmt 99.3% 163 / 164 Branchbran 96.0% 73 / 76 Conditioncond 76.1% 67 / 88 MC/DCmcdc 58.3% 28 / 48 Subroutinesub 96.6% 29 / 30 Podpod 100% 9 / 9 totaltotal 88.9% 369 / 415 CC 72 SCAR 20.4
CC
72
Cov
92%
_is_call
16.1
_is_own_block
11.4
_list_region
10.1
CRAP 7.7
↑ Summary
1 package Perl::Critic::Policy::Variables::ProhibitCallsWithAliasedTopic 0.001;
2  
3 # ABSTRACT: Do not call a sub or method while $_ is an alias to the caller's data.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use re '/aa';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use List::Util qw{ any first };
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Scalar::Util qw{ refaddr };
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Perl::Critic::Distribution ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Perl::Critic::Utils qw{ :severities is_function_call is_method_call is_perl_builtin first_arg };
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use parent qw{Perl::Critic::Policy};
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 2 Readonly::Scalar my $DESC_BLOCK => q{A call in a list function block, while $_ is the caller's element};
22 2 Readonly::Scalar my $EXPL_BLOCK => q{Say "local ($_) = $_;" before the first call, so that a callee that writes $_ writes a copy};
23 2 Readonly::Scalar my $DESC_POSTFIX => q{A call in a statement with a postfix for, while $_ is the caller's element};
24 2 Readonly::Scalar my $EXPL_POSTFIX => q{Write a block "for my $x (...) { ... }" instead, so that $_ is not the element};
25  
26 Readonly::Array my @ALIASING_FUNCS => (
27 qw{ map grep },
28 220 map { ( $_, "List::Util::$_" ) } qw{ first any all none notall },
29 70 map { ( $_, "List::MoreUtils::$_", "List::SomeUtils::$_" ) } qw{
30 any all none notall true false firstidx first_index lastidx last_index
31 firstval first_value lastval last_value firstres first_result lastres
32 last_result onlyidx only_index onlyval only_value onlyres only_result
33 indexes after after_incl before before_incl part insert_after
34 },
35 2 map { ( $_, "List::UtilsBy::$_" ) } qw{ max_by min_by },
36 );
37  
38 2 Readonly::Hash my %LOOP => map { $_ => 1 } qw{ for foreach };
39  
40 # Change it when what the collector returns changes shape.
41 2 Readonly::Scalar my $DATA_FORMAT => 1;
42  
43  
44 5 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod documented
45 5 my %seen;
46 return (
47 {
48 name => 'allow',
49 description => q{Subs and methods that do not write $_},
50 default_string => q{can DOES isa VERSION},
51 behavior => 'string list',
52 },
53 {
54 name => 'list_funcs',
55 description => q{The functions whose block sees each element as $_},
56 5 default_string => join( q{ }, grep { !$seen{$_}++ } @ALIASING_FUNCS ),
57 behavior => 'string list',
58 },
59 {
60 name => 'add_list_funcs',
61 description => q{More functions whose block sees each element as $_},
62 default_string => q{},
63 behavior => 'string list',
64 },
65 );
66 }
67  
68 63 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
69 0 ▶sub default_themes { return qw{ bugs } }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
70 100 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
71  
72  
73 5 ▶sub initialize_if_enabled {
Subroutine initialize_if_enabled: called CC=2 SCAR=6.9
Pod documented
74 5 my ( $self, $config ) = @_;
75  
76 5 $self->{_all_list_funcs} = { map { $_ => 1 } keys %{ $self->{_list_funcs} }, keys %{ $self->{_add_list_funcs} } };
77  
78 Perl::Critic::Distribution->register(
79 name => __PACKAGE__,
80 version => join( q{/}, $DATA_FORMAT, Perl::Critic::Distribution->stamp(__FILE__) // q{} ),
81 2 ▶ collect => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 2 my ($ppi) = @_;
83 2 return { subs => [ sub_names_in($ppi) ] };
84 },
85 5 ▶ );
Condition50%1/2
"Perl::Critic::Distribution"->stamp(__FILE__) // ""
l!l
50
MC/DC0%0/1
"Perl::Critic::Distribution"->stamp(__FILE__) // ""
"Perl::Critic::Distribution"->stamp(__FILE__)
Truth table50%1/2
A
A= "Perl::Critic::Distribution"->stamp(__FILE__)
Aresult
11
00
86 5 return $self->SUPER::initialize_if_enabled($config);
87 }
88  
89  
90 360 ▶sub violates {
Subroutine violates: called CC=5 SCAR=16.1
Pod documented
91 360 my ( $self, $elem, $doc ) = @_;
92  
93 360 ▶ if ( my $statement = _postfix_statement($elem) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $statement = _postfix_statement($elem)) 17 343 360
94 17 ▶ my $call = $self->_first_call( {}, grep { _is_before( $_, $elem ) } $statement->schildren ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $call = $self->_first_call({}, grep({_is_before($_, $elem);} $statement->schildren)) or return 11 6 17
95 11 return $self->violation( $DESC_POSTFIX, $EXPL_POSTFIX, $call );
96 }
97  
98 343 ▶ my @region = $self->_list_region($elem) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@region) = $self->_list_region($elem) or return 80 263 343
99 80 ▶ my $call = $self->_first_call( $self->known_subs($doc), @region ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $call = $self->_first_call($self->known_subs($doc), @region) or return 51 29 80
100 51 return $self->violation( $DESC_BLOCK, $EXPL_BLOCK, $call );
101 }
102  
103 # The statement of $elem, when $elem is the for or foreach of a postfix for.
104 360 ▶sub _postfix_statement {
Subroutine _postfix_statement: called CC=6 SCAR=18.6
105 360 my ($elem) = @_;
106  
107 360 ▶ return if !$LOOP{ $elem->content };
Branch: 1 branch
BranchTrueFalseTotal
unless $LOOP{$elem->content} 336 24 360
108 24 my $statement = $elem->parent;
109 24 ▶ return if !$statement || !$statement->isa('PPI::Statement') || $statement->isa('PPI::Statement::Compound');
Branch: 1 branch
BranchTrueFalseTotal
if not $statement && $statement->isa("PPI::Statement") or $statement->isa("PPI::Statement::Compound") 7 17 24
Condition50%3/6
not $statement && $statement->isa("PPI::Statement") or $statement->isa("PPI::Statement::Compound")
l!l&&r!l&&!r
0717
$statement && $statement->isa('PPI::Statement')
!ll&&!rl&&r
0024
MC/DC33%1/3
not $statement && $statement->isa("PPI::Statement") or $statement->isa("PPI::Statement::Compound")
$statement $statement->isa('PPI::Statement') $statement->isa("PPI::Statement::Compound")
Truth table50%2/4
not(A && B) or C
A= $statementB= $statement->isa('PPI::Statement')C= $statement->isa("PPI::Statement::Compound")
ABCresult
0XX1
10X1
1111
1100
110 17 ▶ return if $statement->schild(0) == $elem;
Branch: 1 branch
BranchTrueFalseTotal
if $statement->schild(0) == $elem 0 17 17
111 17 return $statement;
112 }
113  
114 95 ▶sub _is_before {
Subroutine _is_before: called CC=3 SCAR=11.1
115 95 my ( $elem, $mark ) = @_;
116 95 my ( $line, $col ) = @{ $elem->location }[ 0, 1 ];
117 95 my ( $mline, $mcol ) = @{ $mark->location }[ 0, 1 ];
118 95 ▶ return $line < $mline || ( $line == $mline && $col < $mcol );
Condition66%4/6
$line < $mline || $line == $mline && $col < $mcol
l!l&&r!l&&!r
04055
$line == $mline and $col < $mcol
!ll&&!rl&&r
05540
MC/DC33%1/3
$line < $mline || $line == $mline && $col < $mcol
$line < $mline $line == $mline $col < $mcol
Truth table50%2/4
A || B and C
A= $line < $mlineB= $line == $mlineC= $col < $mcol
ABCresult
1XX1
0111
00X0
0100
119 }
120  
121 # What runs with $_ aliased when $elem is a list function: the statements of
122 # its block up to the first local $_, or the expression of map EXPR.
123 343 ▶sub _list_region {
Subroutine _list_region: called CC=10 SCAR=23.1
124 343 my ( $self, $elem ) = @_;
125  
126 343 ▶ return if !$self->{_all_list_funcs}{ $elem->content } || !is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_all_list_funcs"}{$elem->content} and is_function_call($elem) 263 80 343
Condition66%2/3
$self->{"_all_list_funcs"}{$elem->content} and is_function_call($elem)
!ll&&!rl&&r
263080
MC/DC50%1/2
$self->{"_all_list_funcs"}{$elem->content} and is_function_call($elem)
$self->{"_all_list_funcs"}{$elem->content} is_function_call($elem)
Truth table66%2/3
A and B
A= $self->{"_all_list_funcs"}{$elem->content}B= is_function_call($elem)
ABresult
0X0
100
111
127 80 ▶ my $arg = first_arg($elem) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $arg = first_arg($elem) or return 80 0 80
128  
129 80 ▶ if ( !$arg->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg->isa("PPI::Structure::Block")) 5 75 80
130 5 my @expr;
131 5 ▶ for ( my $part = $arg; $part && !( $part->isa('PPI::Token::Operator') && $part->content eq q{,} ); $part = $part->snext_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part and not $part->isa("PPI::Token::Operator") && $part->content eq ",") 8 5 13
Condition83%5/6
$part and not $part->isa("PPI::Token::Operator") && $part->content eq ","
!ll&&!rl&&r
148
$part->isa('PPI::Token::Operator') && $part->content eq ','
!ll&&!rl&&r
804
MC/DC66%2/3
$part and not $part->isa("PPI::Token::Operator") && $part->content eq ","
$part $part->isa('PPI::Token::Operator') $part->content eq ','
Truth table75%3/4
A and not(B && C)
A= $partB= $part->isa('PPI::Token::Operator')C= $part->content eq ','
ABCresult
0XX0
1110
10X1
1101
132 8 push @expr, $part;
133 }
134 5 return @expr;
135 }
136  
137 # The local statement is in the region, since its right side runs before
138 # $_ is localized.
139 75 my @region;
140 75 foreach my $statement ( $arg->schildren ) {
141 96 push @region, $statement;
142 96 ▶ last if _localizes_topic($statement);
Branch: 1 branch
BranchTrueFalseTotal
if _localizes_topic($statement) 5 91 96
143 }
144  
145 75 return @region;
146 }
147  
148 96 ▶sub _localizes_topic {
Subroutine _localizes_topic: called CC=3 SCAR=11.0
149 96 my ($statement) = @_;
150 96 ▶ return $statement->isa('PPI::Statement::Variable') && $statement->type eq 'local' && any { $_ eq q{$_} } $statement->variables;
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition100%6/6
$statement->isa('PPI::Statement::Variable') && $statement->type eq 'local' && &any(sub { $_ eq '$_'; } , $statement->variables)
!ll&&!rl&&r
9015
$statement->isa("PPI::Statement::Variable") and $statement->type eq "local"
!ll&&!rl&&r
8646
MC/DC100%3/3
$statement->isa('PPI::Statement::Variable') && $statement->type eq 'local' && &any(sub { $_ eq '$_'; } , $statement->variables)
$statement->isa("PPI::Statement::Variable") $statement->type eq "local" &any(sub { $_ eq '$_'; } , $statement->variables)
Truth table100%4/4
A and B && C
A= $statement->isa("PPI::Statement::Variable")B= $statement->type eq "local"C= &any(sub { $_ eq '$_'; } , $statement->variables)
ABCresult
0XX0
10X0
1100
1111
151 }
152  
153 # The first call in @queue, or inside it, that is not in a part where $_
154 # belongs to another construct.
155 97 ▶sub _first_call {
Subroutine _first_call: called CC=5 SCAR=16.1
156 97 my ( $self, $known, @queue ) = @_;
157  
158 97 ▶ while ( defined( my $elem = shift @queue ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $elem = shift @queue)) 375 35 410
159 375 ▶ next if _is_own_block($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _is_own_block($elem) 3 372 375
160 372 ▶ return $elem if $self->_is_call( $elem, $known );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_call($elem, $known) 62 310 372
161 310 ▶ next if !$elem->isa('PPI::Node');
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->isa("PPI::Node") 163 147 310
162 147 unshift @queue, _own_children($elem);
163 }
164 35 return;
165 }
166  
167 # The children of $node in which $_ is still the alias that was set outside it.
168 147 ▶sub _own_children {
Subroutine _own_children: called CC=10 SCAR=23.1
169 147 my ($node) = @_;
170  
171 147 ▶ return if $node->isa('PPI::Statement::Sub');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("PPI::Statement::Sub") 0 147 147
172  
173 147 my @children = $node->schildren;
174 147 ▶ if ( $node->isa('PPI::Statement::Compound') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("PPI::Statement::Compound")) 6 141 147
175 6 my $loop = $children[0];
176 6 my $var = $children[1];
177 6 ▶ if ( $loop && $LOOP{ $loop->content } && $var && ( $var->isa('PPI::Structure::List') || $var->content eq q{$_} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop and $LOOP{$loop->content} and $var and $var->isa("PPI::Structure::List") || $var->content eq "\$_") 2 4 6
Condition75%9/12
$loop and $LOOP{$loop->content} and $var and $var->isa("PPI::Structure::List") || $var->content eq "\$_"
!ll&&!rl&&r
222
$loop and $LOOP{$loop->content} and $var
!ll&&!rl&&r
204
$loop and $LOOP{$loop->content}
!ll&&!rl&&r
024
$var->isa("PPI::Structure::List") or $var->content eq "\$_"
l!l&&r!l&&!r
202
MC/DC40%2/5
$loop and $LOOP{$loop->content} and $var and $var->isa("PPI::Structure::List") || $var->content eq "\$_"
$loop $LOOP{$loop->content} $var $var->isa("PPI::Structure::List") $var->content eq "\$_"
Truth table50%3/6
A and B and C and D or E
A= $loopB= $LOOP{$loop->content}C= $varD= $var->isa("PPI::Structure::List")E= $var->content eq "\$_"
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
178 2 return grep { !$_->isa('PPI::Structure::Block') } @children;
179 }
180 4 return @children;
181 }
182 141 ▶ if ( $node->isa('PPI::Statement') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("PPI::Statement")) 110 31 141
183 110 ▶ my $postfix = first { $_->isa('PPI::Token::Word') && $LOOP{ $_->content } && $_ != $children[0] } @children;
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Word") and $LOOP{$_->content} and $_ != $children[0] 1 261 262
Condition100%3/3
$_->isa("PPI::Token::Word") and $LOOP{$_->content}
!ll&&!rl&&r
177841
MC/DC100%2/2
$_->isa("PPI::Token::Word") and $LOOP{$_->content}
$_->isa("PPI::Token::Word") $LOOP{$_->content}
Truth table100%3/3
A and B
A= $_->isa("PPI::Token::Word")B= $LOOP{$_->content}
ABresult
0X0
100
111
184 110 ▶ if ($postfix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postfix) 1 109 110
185 1 return grep { !_is_before( $_, $postfix ) } @children;
186 }
187 }
188 140 return @children;
189 }
190  
191 # Whether $elem is a block where $_ is not the alias from outside: that of an
192 # anonymous sub, which runs when it is called, or of a list function.
193 375 ▶sub _is_own_block {
Subroutine _is_own_block: called CC=11 SCAR=24.3
194 375 my ($elem) = @_;
195  
196 375 ▶ return if !$elem->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->isa("PPI::Structure::Block") 367 8 375
197 8 my $before = $elem->sprevious_sibling;
198 8 ▶ while ( $before && ( $before->isa('PPI::Token::Prototype') || $before->isa('PPI::Token::Attribute') || $before->isa('PPI::Structure::List') ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before and $before->isa("PPI::Token::Prototype") || $before->isa("PPI::Token::Attribute") || $before->isa("PPI::Structure::List")) 2 8 10
Condition77%7/9
$before and $before->isa("PPI::Token::Prototype") || $before->isa("PPI::Token::Attribute") || $before->isa("PPI::Structure::List")
!ll&&!rl&&r
082
$before->isa("PPI::Token::Prototype") or $before->isa("PPI::Token::Attribute") or $before->isa("PPI::Structure::List")
l!l&&r!l&&!r
118
$before->isa("PPI::Token::Prototype") or $before->isa("PPI::Token::Attribute")
l!l&&r!l&&!r
109
MC/DC50%2/4
$before and $before->isa("PPI::Token::Prototype") || $before->isa("PPI::Token::Attribute") || $before->isa("PPI::Structure::List")
$before $before->isa("PPI::Token::Prototype") $before->isa("PPI::Token::Attribute") $before->isa("PPI::Structure::List")
Truth table60%3/5
A and B or C or D
A= $beforeB= $before->isa("PPI::Token::Prototype")C= $before->isa("PPI::Token::Attribute")D= $before->isa("PPI::Structure::List")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
199 2 $before = $before->sprevious_sibling;
200 }
201 8 ▶ return if !$before || !$before->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $before and $before->isa("PPI::Token::Word") 3 5 8
Condition66%2/3
$before and $before->isa("PPI::Token::Word")
!ll&&!rl&&r
035
MC/DC50%1/2
$before and $before->isa("PPI::Token::Word")
$before $before->isa("PPI::Token::Word")
Truth table66%2/3
A and B
A= $beforeB= $before->isa("PPI::Token::Word")
ABresult
0X0
100
111
202 5 ▶ return 1 if $before->content eq 'sub';
Branch: 1 branch
BranchTrueFalseTotal
if $before->content eq "sub" 2 3 5
203 3 ▶ return if !is_function_call($before);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($before) 2 1 3
204 1 my $arg = first_arg($before);
205 1 ▶ return $arg && $arg == $elem;
Condition33%1/3
$arg && $arg == $elem
!ll&&!rl&&r
001
MC/DC0%0/2
$arg && $arg == $elem
$arg $arg == $elem
Truth table33%1/3
A && B
A= $argB= $arg == $elem
ABresult
0X0
100
111
206 }
207  
208 # Whether $elem calls a sub or method that is not a builtin, not allowed, and,
209 # for a sub, not in %$known.
210 372 ▶sub _is_call {
Subroutine _is_call: called CC=16 SCAR=27.8
211 372 my ( $self, $elem, $known ) = @_;
212  
213 372 ▶ if ( $elem->isa('PPI::Token::Word') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Word")) 113 259 372
214 113 my $name = $elem->content;
215 113 ▶ return if $self->{_allow}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_allow"}{$name} 6 107 113
216 107 ▶ return 1 if is_method_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_method_call($elem) 5 102 107
217 102 ▶ return if !is_function_call($elem) || $self->{_all_list_funcs}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if not is_function_call($elem) or $self->{"_all_list_funcs"}{$name} 17 85 102
Condition100%3/3
not is_function_call($elem) or $self->{"_all_list_funcs"}{$name}
l!l&&r!l&&!r
16185
MC/DC100%2/2
not is_function_call($elem) or $self->{"_all_list_funcs"}{$name}
not is_function_call($elem) $self->{"_all_list_funcs"}{$name}
Truth table100%3/3
not(A) or B
A= not is_function_call($elem)B= $self->{"_all_list_funcs"}{$name}
ABresult
1X1
011
000
218 85 ( my $core = $name ) =~ s/\ACORE::(?:GLOBAL::)?//xms;
219 85 ▶ return if is_perl_builtin($core);
Branch: 1 branch
BranchTrueFalseTotal
if is_perl_builtin($core) 26 59 85
220 59 return !$known->{ bare_name($name) };
221 }
222 259 ▶ if ( $elem->isa('PPI::Token::Symbol') && $elem->raw_type eq q{&} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "&") 1 258 259
Condition100%3/3
$elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "&"
!ll&&!rl&&r
197611
MC/DC100%2/2
$elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "&"
$elem->isa("PPI::Token::Symbol") $elem->raw_type eq "&"
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Symbol")B= $elem->raw_type eq "&"
ABresult
0X0
100
111
223 1 my $name = substr $elem->content, 1;
224 1 ▶ return !$self->{_allow}{$name} && !$known->{ bare_name($name) };
Condition33%1/3
$self->{'_allow'}{$name} || $$known{bare_name($name)}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{'_allow'}{$name} || $$known{bare_name($name)}
$self->{'_allow'}{$name} $$known{bare_name($name)}
Truth table33%1/3
A || B
A= $self->{'_allow'}{$name}B= $$known{bare_name($name)}
ABresult
1X1
011
000
225 }
226 258 ▶ return 1 if $elem->isa('PPI::Token::Cast') && $elem->content eq q{&};
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Cast") and $elem->content eq "&" 1 257 258
Condition66%2/3
$elem->isa("PPI::Token::Cast") and $elem->content eq "&"
!ll&&!rl&&r
25701
MC/DC50%1/2
$elem->isa("PPI::Token::Cast") and $elem->content eq "&"
$elem->isa("PPI::Token::Cast") $elem->content eq "&"
Truth table66%2/3
A and B
A= $elem->isa("PPI::Token::Cast")B= $elem->content eq "&"
ABresult
0X0
100
111
227 257 ▶ if ( $elem->isa('PPI::Token::Operator') && $elem->content eq q{->} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Operator") and $elem->content eq "->") 13 244 257
Condition100%3/3
$elem->isa("PPI::Token::Operator") and $elem->content eq "->"
!ll&&!rl&&r
2281613
MC/DC100%2/2
$elem->isa("PPI::Token::Operator") and $elem->content eq "->"
$elem->isa("PPI::Token::Operator") $elem->content eq "->"
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Operator")B= $elem->content eq "->"
ABresult
0X0
100
111
228 13 my $next = $elem->snext_sibling;
229 13 ▶ return $next && ( $next->isa('PPI::Structure::List') || $next->isa('PPI::Token::Symbol') );
Condition83%5/6
$next && ($next->isa('PPI::Structure::List') || $next->isa('PPI::Token::Symbol'))
!ll&&!rl&&r
0103
$next->isa("PPI::Structure::List") or $next->isa("PPI::Token::Symbol")
l!l&&r!l&&!r
2110
MC/DC66%2/3
$next && ($next->isa('PPI::Structure::List') || $next->isa('PPI::Token::Symbol'))
$next $next->isa("PPI::Structure::List") $next->isa("PPI::Token::Symbol")
Truth table75%3/4
A && B or C
A= $nextB= $next->isa("PPI::Structure::List")C= $next->isa("PPI::Token::Symbol")
ABCresult
0XX0
1000
11X1
1011
230 }
231 244 return;
232 }
233  
234  
235 80 ▶sub known_subs {
Subroutine known_subs: called CC=7 SCAR=19.5
Pod documented
236 80 my ( $self, $doc ) = @_;
237  
238 # The document is held, not just its address, so the address cannot be
239 # handed to the next document while this still answers for it.
240 80 my $last = $self->{_known};
241 80 ▶ return $last->{subs} if $last && refaddr( $last->{doc} ) == refaddr($doc);
Branch: 1 branch
BranchTrueFalseTotal
if $last and builtin::refaddr($last->{"doc"}) == builtin::refaddr($doc) 4 76 80
Condition100%3/3
$last and builtin::refaddr($last->{"doc"}) == builtin::refaddr($doc)
!ll&&!rl&&r
4724
MC/DC100%2/2
$last and builtin::refaddr($last->{"doc"}) == builtin::refaddr($doc)
$last builtin::refaddr($last->{"doc"}) == builtin::refaddr($doc)
Truth table100%3/3
A and B
A= $lastB= builtin::refaddr($last->{"doc"}) == builtin::refaddr($doc)
ABresult
0X0
100
111
242  
243 76 my %subs = map { $_ => 1 } sub_names_in($doc);
244  
245 76 my $filename = $doc->filename;
246 76 ▶ if ( my $dist = defined $filename && Perl::Critic::Distribution->for_file($filename) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dist = defined $filename && "Perl::Critic::Distribution"->for_file($filename)) 1 75 76
Condition66%2/3
defined $filename && 'Perl::Critic::Distribution'->for_file($filename)
!ll&&!rl&&r
7501
MC/DC50%1/2
defined $filename && 'Perl::Critic::Distribution'->for_file($filename)
defined $filename 'Perl::Critic::Distribution'->for_file($filename)
Truth table66%2/3
A && B
A= defined $filenameB= 'Perl::Critic::Distribution'->for_file($filename)
ABresult
0X0
100
111
247 1 foreach my $file ( values %{ $dist->collected(__PACKAGE__) } ) {
248 2 $subs{$_} = 1 for @{ $file->{subs} };
249 }
250 }
251  
252 76 $self->{_known} = { doc => $doc, subs => \%subs };
253 76 return \%subs;
254 }
255  
256  
257 78 ▶sub sub_names_in {
Subroutine sub_names_in: called CC=2 SCAR=6.9
Pod documented
258 78 my ($ppi) = @_;
259 78 ▶ return map { bare_name( $_->name ) } grep { defined $_->name } @{ $ppi->find('PPI::Statement::Sub') || [] };
Condition100%2/2
$ppi->find('PPI::Statement::Sub') || []
l!l
969
MC/DC100%1/1
$ppi->find('PPI::Statement::Sub') || []
$ppi->find('PPI::Statement::Sub')
Truth table100%2/2
A
A= $ppi->find('PPI::Statement::Sub')
Aresult
11
00
260 }
261  
262  
263 75 ▶sub bare_name {
Subroutine bare_name: called CC=2 SCAR=6.9
Pod documented
264 75 my ($name) = @_;
265 75 my $at = rindex $name, '::';
266 75 ▶ return $at < 0 ? $name : substr $name, $at + 2;
Branch: 1 branch
BranchTrueFalseTotal
$at < 0 ? : 71 4 75
267 }
268  
269 2 1;
270  
271 __END__
↑ Summary