blib/lib/PPIx/EditorTools.pm

filter: Statementstmt 72.5% 103 / 142 Branchbran 61.8% 47 / 76 Conditioncond 55.9% 52 / 93 MC/DCmcdc 31.3% 16 / 51 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 6 totaltotal 60.7% 232 / 382 CC 77 SCAR 40.2
CC
77
Cov
65%
get_all_variable_declarations
97.9
find_variable_declaration
77.5
find_token_at_location
9.5
CRAP 55.7
↑ Summary blib/lib/PPIx/EditorTools/RenameVariable.pm »
1 package PPIx::EditorTools;
2 24 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Utility methods and base class for manipulating Perl via PPI
4 24 $PPIx::EditorTools::VERSION = '0.21';
5 24 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Class::XSAccessor 1.02 constructor => 'new', accessors => {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 'code' => 'code',
11 'ppi' => 'ppi',
12 24 };
13  
14 24 ▶use PPI 1.203;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use PPIx::EditorTools::ReturnObject;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 # Used by all the PPIx::EditorTools::* modules
19 # Checks for either PPI::Document or take the code as a string and
20 # creates the ppi document
21  
22 56 ▶sub process_doc {
Subroutine process_doc: called CC=7 SCAR=21.3
Pod undocumented
23 56 my ( $self, %args ) = @_;
24  
25 56 ▶ $self->ppi( $args{ppi} ) if defined $args{ppi};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"ppi"} 0 56 56
26 56 ▶ return 1 if $self->ppi && $self->ppi->isa('PPI::Document');
Branch: 1 branch
BranchTrueFalseTotal
if $self->ppi and $self->ppi->isa("PPI::Document") 10 45 55
Condition66%2/3
$self->ppi and $self->ppi->isa("PPI::Document")
!ll&&!rl&&r
45010
MC/DC50%1/2
$self->ppi and $self->ppi->isa("PPI::Document")
$self->ppi $self->ppi->isa("PPI::Document")
Truth table66%2/3
A and B
A= $self->ppiB= $self->ppi->isa("PPI::Document")
ABresult
0X0
100
111
27  
28 # TODO: inefficient to pass around full code/ppi
29 45 ▶ $self->code( $args{code} ) if $args{code};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"code"} 44 1 45
30 45 my $code = $self->code;
31 45 $self->ppi( PPI::Document->new( \$code ) );
32 45 ▶ return 1 if $self->ppi && $self->ppi->isa('PPI::Document');
Branch: 1 branch
BranchTrueFalseTotal
if $self->ppi and $self->ppi->isa("PPI::Document") 45 0 45
Condition33%1/3
$self->ppi and $self->ppi->isa("PPI::Document")
!ll&&!rl&&r
0045
MC/DC0%0/2
$self->ppi and $self->ppi->isa("PPI::Document")
$self->ppi $self->ppi->isa("PPI::Document")
Truth table33%1/3
A and B
A= $self->ppiB= $self->ppi->isa("PPI::Document")
ABresult
0X0
100
111
33  
34 0 croak "arguments ppi or code required";
35 0 return;
36 }
37  
38  
39  
40  
41  
42 #####################################################################
43 # Assorted Search Functions
44  
45 59 ▶sub find_unmatched_brace {
Subroutine find_unmatched_brace: called CC=5 SCAR=16.3
Pod undocumented
46 59 ▶ $_[1]->isa('PPI::Statement::UnmatchedBrace') and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Statement::UnmatchedBrace") and return 1 0 58 58
47 58 ▶ $_[1]->isa('PPI::Structure') or return '';
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Structure") or return "" 3 55 58
48 3 ▶ $_[1]->start and $_[1]->finish and return '';
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->start and $_[1]->finish and return "" 1 2 3
Condition66%2/3
$_[1]->start and $_[1]->finish
!ll&&!rl&&r
021
MC/DC50%1/2
$_[1]->start and $_[1]->finish
$_[1]->start $_[1]->finish
Truth table66%2/3
A and B
A= $_[1]->startB= $_[1]->finish
ABresult
0X0
100
111
49 2 return 1;
50 }
51  
52 # scans a document for variable declarations and
53 # sorts them into three categories:
54 # lexical (my)
55 # our (our, doh)
56 # dynamic (local)
57 # package (use vars)
58 # Returns a hash reference containing the three category names
59 # each pointing at a hash which contains '$variablename' => locations.
60 # locations is an array reference containing one or more PPI-style
61 # locations. Example:
62 # {
63 # lexical => {
64 # '$foo' => [ [ 2, 3, 3], [ 6, 7, 7 ] ],
65 # },
66 # ...
67 # }
68 # Thus, there are two places where a "my $foo" was declared. On line 2 col 3
69 # and line 6 col 7.
70 3 ▶sub get_all_variable_declarations {
Subroutine get_all_variable_declarations: called CC=23 SCAR=45.8
Pod undocumented
71 3 my $document = shift;
72  
73 my $declarations = $document->find(
74 55 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
75 55 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include") or $_[1]->isa("PPI::Statement::Compound") 52 3 55
Condition83%5/6
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include") or $_[1]->isa("PPI::Statement::Compound")
l!l&&r!l&&!r
1252
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include")
l!l&&r!l&&!r
0154
MC/DC66%2/3
$_[1]->isa("PPI::Statement::Variable") or $_[1]->isa("PPI::Statement::Include") or $_[1]->isa("PPI::Statement::Compound")
$_[1]->isa("PPI::Statement::Variable") $_[1]->isa("PPI::Statement::Include") $_[1]->isa("PPI::Statement::Compound")
Truth table75%3/4
A or B or C
A= $_[1]->isa("PPI::Statement::Variable")B= $_[1]->isa("PPI::Statement::Include")C= $_[1]->isa("PPI::Statement::Compound")
ABCresult
1XX1
01X1
0011
0000
76 unless $_[1]->isa('PPI::Statement::Variable')
77 or $_[1]->isa('PPI::Statement::Include')
78 or $_[1]->isa('PPI::Statement::Compound');
79 3 return 1;
80 },
81 3 );
82  
83 2 my %our;
84 my %lexical;
85 2 my %dynamic;
86 2 my %package;
87 2 foreach my $decl (@$declarations) {
88 3 ▶ if ( $decl->isa('PPI::Statement::Variable') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($decl->isa('PPI::Statement::Variable')) { } 0 3 3
elsif ($decl->isa('PPI::Statement::Include') and $decl->module eq 'vars' and $decl->type eq 'use') { } 0 3 3
elsif ($decl->isa('PPI::Statement::Compound') and $decl->type eq 'for' || $decl->type eq 'foreach') { } 2 2 4
89 0 my $type = $decl->type();
90 0 my @vars = $decl->variables;
91 0 my $location = $decl->location;
92  
93 0 my $target_type;
94  
95 0 ▶ if ( $type eq 'my' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'my') { } 0 0 0
elsif ($type eq 'our') { } 0 0 0
elsif ($type eq 'local') { } 0 0 0
96 0 $target_type = \%lexical;
97 } elsif ( $type eq 'our' ) {
98 0 $target_type = \%our;
99 } elsif ( $type eq 'local' ) {
100 0 $target_type = \%dynamic;
101 }
102  
103 0 foreach my $var (@vars) {
104 0 ▶ $target_type->{$var} ||= [];
Condition0%0/2
$target_type->{$var} ||= []
l!l
00
MC/DC0%0/1
$target_type->{$var} ||= []
$target_type->{$var}
Truth table0%0/2
A
A= $target_type->{$var}
Aresult
11
00
105 0 push @{ $target_type->{$var} }, $location;
106 }
107 }
108  
109 # find use vars...
110 ▶ elsif ( $decl->isa('PPI::Statement::Include')
Condition50%3/6
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars" and $decl->type eq "use"
!ll&&!rl&&r
300
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars"
!ll&&!rl&&r
210
MC/DC0%0/3
$decl->isa("PPI::Statement::Include") and $decl->module eq "vars" and $decl->type eq "use"
$decl->isa("PPI::Statement::Include") $decl->module eq "vars" $decl->type eq "use"
Truth table50%2/4
A and B and C
A= $decl->isa("PPI::Statement::Include")B= $decl->module eq "vars"C= $decl->type eq "use"
ABCresult
0XX0
10X0
1100
1111
111 and $decl->module eq 'vars'
112 and $decl->type eq 'use' )
113 {
114  
115 # do it the low-tech way
116 0 my $string = $decl->content();
117 0 my $location = $decl->location;
118  
119 0 my @vars = $string =~ /([\%\@\$][\w_:]+)/g;
120 0 foreach my $var (@vars) {
121 0 ▶ $package{$var} ||= [];
Condition0%0/2
$package{$var} ||= []
l!l
00
MC/DC0%0/1
$package{$var} ||= []
$package{$var}
Truth table0%0/2
A
A= $package{$var}
Aresult
11
00
122 0 push @{ $package{$var} }, $location;
123 }
124  
125 }
126  
127 # find for/foreach loop variables
128 ▶ elsif ( $decl->isa('PPI::Statement::Compound')
Condition50%3/6
$decl->isa("PPI::Statement::Compound") and $decl->type eq "for" || $decl->type eq "foreach"
!ll&&!rl&&r
102
$decl->type eq "for" or $decl->type eq "foreach"
l!l&&r!l&&!r
020
MC/DC33%1/3
$decl->isa("PPI::Statement::Compound") and $decl->type eq "for" || $decl->type eq "foreach"
$decl->isa("PPI::Statement::Compound") $decl->type eq "for" $decl->type eq "foreach"
Truth table50%2/4
A and B or C
A= $decl->isa("PPI::Statement::Compound")B= $decl->type eq "for"C= $decl->type eq "foreach"
ABCresult
0XX0
1000
11X1
1011
129 && ( $decl->type eq 'for' or $decl->type eq 'foreach' ) )
130 {
131 2 my @elems = $decl->elements;
132  
133 2 ▶ next if scalar(@elems) < 5;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @elems < 5 0 2 2
134 2 my $location = $decl->location;
135 2 my $type = $elems[2]->content();
136 2 ▶ if ( $elems[4]->isa('PPI::Token::Symbol')
Branch: 1 branch
BranchTrueFalseTotal
if ($elems[4]->isa("PPI::Token::Symbol") and $type eq "my" || $type eq "our") 2 0 2
Condition33%2/6
$elems[4]->isa("PPI::Token::Symbol") and $type eq "my" || $type eq "our"
!ll&&!rl&&r
002
$type eq "my" or $type eq "our"
l!l&&r!l&&!r
200
MC/DC0%0/3
$elems[4]->isa("PPI::Token::Symbol") and $type eq "my" || $type eq "our"
$elems[4]->isa("PPI::Token::Symbol") $type eq "my" $type eq "our"
Truth table25%1/4
A and B or C
A= $elems[4]->isa("PPI::Token::Symbol")B= $type eq "my"C= $type eq "our"
ABCresult
0XX0
1000
11X1
1011
137 && ( $type eq 'my' || $type eq 'our' ) )
138 {
139 2 my $target_type;
140  
141 # Only my and our are valid for loop variable
142 2 ▶ if ( $type eq 'my' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'my') { } 2 0 2
elsif ($type eq 'our') { } 0 0 0
143 2 $target_type = \%lexical;
144 } elsif ( $type eq 'our' ) {
145 0 $target_type = \%our;
146 }
147  
148 2 my $var = $elems[4]->content();
149 2 ▶ $target_type->{$var} ||= [];
Condition50%1/2
$target_type->{$var} ||= []
l!l
02
MC/DC0%0/1
$target_type->{$var} ||= []
$target_type->{$var}
Truth table50%1/2
A
A= $target_type->{$var}
Aresult
11
00
150 2 push @{ $target_type->{$var} }, $location;
151 }
152 }
153 } # end foreach declaration
154  
155 return (
156 2 { our => \%our,
157 lexical => \%lexical,
158 dynamic => \%dynamic,
159 package => \%package
160 }
161 );
162 }
163  
164  
165  
166  
167  
168 #####################################################################
169 # Stuff that should be in PPI itself
170  
171 1 ▶sub element_depth {
Subroutine element_depth: called CC=2 SCAR=10.1
Pod undocumented
172 1 my $cursor = shift;
173 1 my $depth = 0;
174 1 ▶ while ( $cursor = $cursor->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor = $cursor->parent) 0 0 0
175 0 $depth += 1;
176 }
177 0 return $depth;
178 }
179  
180 # TODO: PPIx::IndexOffsets or something similar might help.
181 # TODO: See the 71... tests. If we don#t flush locations there, this breaks.
182 21 ▶sub find_token_at_location {
Subroutine find_token_at_location: called CC=9 SCAR=22.5
Pod undocumented
183 21 my $document = shift;
184 21 my $location = shift;
185  
186 21 ▶ if ( not defined $document
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $document and $document->isa("PPI::Document") and defined $location and ref $location eq "ARRAY") 1 20 21
Condition66%6/9
defined $document and $document->isa("PPI::Document") and defined $location and ref $location eq "ARRAY"
!ll&&!rl&&r
1020
defined $document and $document->isa("PPI::Document") and defined $location
!ll&&!rl&&r
1020
defined $document and $document->isa("PPI::Document")
!ll&&!rl&&r
0120
MC/DC25%1/4
defined $document and $document->isa("PPI::Document") and defined $location and ref $location eq "ARRAY"
defined $document $document->isa("PPI::Document") defined $location ref $location eq "ARRAY"
Truth table40%2/5
A and B and C and D
A= defined $documentB= $document->isa("PPI::Document")C= defined $locationD= ref $location eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
187 or not $document->isa('PPI::Document')
188 or not defined $location
189 or not ref($location) eq 'ARRAY' )
190 {
191 1 require Carp;
192 1 Carp::croak("find_token_at_location() requires a PPI::Document and a PPI-style location as arguments");
193 }
194  
195 20 $document->index_locations();
196  
197 20 foreach my $token ( $document->tokens ) {
198 946 my $loc = $token->location;
199 946 ▶ if ( $loc->[0] > $location->[0]
Branch: 1 branch
BranchTrueFalseTotal
if ($loc->[0] > $location->[0] or $loc->[0] == $location->[0] and $loc->[1] > $location->[1]) 20 926 946
Condition83%5/6
$loc->[0] > $location->[0] or $loc->[0] == $location->[0] and $loc->[1] > $location->[1]
l!l&&r!l&&!r
020926
$loc->[0] == $location->[0] and $loc->[1] > $location->[1]
!ll&&!rl&&r
8398720
MC/DC66%2/3
$loc->[0] > $location->[0] or $loc->[0] == $location->[0] and $loc->[1] > $location->[1]
$loc->[0] > $location->[0] $loc->[0] == $location->[0] $loc->[1] > $location->[1]
Truth table75%3/4
A or B and C
A= $loc->[0] > $location->[0]B= $loc->[0] == $location->[0]C= $loc->[1] > $location->[1]
ABCresult
1XX1
0111
00X0
0100
200 or ( $loc->[0] == $location->[0] and $loc->[1] > $location->[1] ) )
201 {
202 20 $document->flush_locations();
203 20 return $token->previous_token();
204 }
205 }
206 0 $document->flush_locations();
207 0 return ();
208 }
209  
210 # given either a PPI::Token::Symbol (i.e. a variable)
211 # or a PPI::Token which contains something that looks like
212 # a variable (quoted vars, interpolated vars in regexes...)
213 # find where that variable has been declared lexically.
214 # Doesn't find stuff like "use vars...".
215 14 ▶sub find_variable_declaration {
Subroutine find_variable_declaration: called CC=33 SCAR=43.5
Pod undocumented
216 14 my $cursor = shift;
217 return ()
218 14 ▶ if not $cursor
Branch: 1 branch
BranchTrueFalseTotal
unless $cursor and $cursor->isa("PPI::Token") 0 14 14
Condition33%1/3
$cursor and $cursor->isa("PPI::Token")
!ll&&!rl&&r
0014
MC/DC0%0/2
$cursor and $cursor->isa("PPI::Token")
$cursor $cursor->isa("PPI::Token")
Truth table33%1/3
A and B
A= $cursorB= $cursor->isa("PPI::Token")
ABresult
0X0
100
111
219 or not $cursor->isa("PPI::Token");
220 14 my ( $varname, $token_str );
221 14 ▶ if ( $cursor->isa("PPI::Token::Symbol") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor->isa('PPI::Token::Symbol')) { } 14 0 14
222 14 $varname = $cursor->symbol;
223 14 $token_str = $cursor->content;
224 } else {
225 0 my $content = $cursor->content;
226 0 ▶ if ( $content =~ /((?:\$#?|[@%*])[\w:\']+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /((?:\$#?|[@%*])[\w:\']+)/) 0 0 0
227 0 $varname = $1;
228 0 $token_str = $1;
229 }
230 }
231 return ()
232 14 ▶ if not defined $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $varname 0 14 14
233  
234 14 $varname =~ s/^\$\#/@/;
235  
236 14 my $document = $cursor->top();
237 14 my $declaration;
238 my $prev_cursor;
239  
240 # This finds variable declarations if you're above it
241 14 ▶ if ( $cursor->parent->isa('PPI::Statement::Variable') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor->parent->isa("PPI::Statement::Variable")) 8 6 14
242 8 return $cursor->parent;
243 }
244  
245 # This finds variable declarations if you're above it and it has the form my ($foo , $bar);
246 6 ▶ if ( $cursor->parent->isa('PPI::Statement::Expression')
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor->parent->isa("PPI::Statement::Expression") and $cursor->parent->parent->parent->isa("PPI::Statement::Variable")) 0 6 6
Condition33%1/3
$cursor->parent->isa("PPI::Statement::Expression") and $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
!ll&&!rl&&r
600
MC/DC0%0/2
$cursor->parent->isa("PPI::Statement::Expression") and $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
$cursor->parent->isa("PPI::Statement::Expression") $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
Truth table33%1/3
A and B
A= $cursor->parent->isa("PPI::Statement::Expression")B= $cursor->parent->parent->parent->isa("PPI::Statement::Variable")
ABresult
0X0
100
111
247 && $cursor->parent->parent->parent->isa('PPI::Statement::Variable') )
248 {
249 0 return $cursor->parent->parent->parent;
250 }
251  
252 6 while (1) {
253 18 $prev_cursor = $cursor;
254 18 $cursor = $cursor->parent;
255 18 ▶ if ( $cursor->isa("PPI::Structure::Block") or $cursor == $document ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cursor->isa('PPI::Structure::Block') or $cursor == $document) { } 9 9 18
elsif ($cursor->isa('PPI::Statement::Compound') and $cursor->type =~ /^for/) { } 3 12 15
Condition100%3/3
$cursor->isa("PPI::Structure::Block") or $cursor == $document
l!l&&r!l&&!r
819
MC/DC100%2/2
$cursor->isa("PPI::Structure::Block") or $cursor == $document
$cursor->isa("PPI::Structure::Block") $cursor == $document
Truth table100%3/3
A or B
A= $cursor->isa("PPI::Structure::Block")B= $cursor == $document
ABresult
1X1
011
000
256 9 my @elems = $cursor->elements;
257 9 foreach my $elem (@elems) {
258  
259 # Stop scanning this scope if we're at the branch we're coming
260 # from. This is to ignore declarations later in the block.
261 66 ▶ last if $elem == $prev_cursor;
Branch: 1 branch
BranchTrueFalseTotal
if $elem == $prev_cursor 3 63 66
262  
263 63 ▶ if ( $elem->isa("PPI::Statement::Variable")
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->isa('PPI::Statement::Variable') and grep {$_ eq $varname;} $elem->variables) { } 6 57 63
elsif ($elem->isa('PPI::Statement::Include') and $elem->module eq 'vars' and $elem->type eq 'use') { } 0 114 114
Condition100%3/3
$elem->isa("PPI::Statement::Variable") and grep {$_ eq $varname;} $elem->variables
!ll&&!rl&&r
5436
MC/DC100%2/2
$elem->isa("PPI::Statement::Variable") and grep {$_ eq $varname;} $elem->variables
$elem->isa("PPI::Statement::Variable") grep {$_ eq $varname;} $elem->variables
Truth table100%3/3
A and B
A= $elem->isa("PPI::Statement::Variable")B= grep {$_ eq $varname;} $elem->variables
ABresult
0X0
100
111
264 9 and grep { $_ eq $varname } $elem->variables )
265 {
266 6 $declaration = $elem;
267 6 last;
268 }
269  
270 # find use vars ...
271 ▶ elsif ( $elem->isa("PPI::Statement::Include")
Condition50%3/6
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars" and $elem->type eq "use"
!ll&&!rl&&r
5700
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars"
!ll&&!rl&&r
5520
MC/DC0%0/3
$elem->isa("PPI::Statement::Include") and $elem->module eq "vars" and $elem->type eq "use"
$elem->isa("PPI::Statement::Include") $elem->module eq "vars" $elem->type eq "use"
Truth table50%2/4
A and B and C
A= $elem->isa("PPI::Statement::Include")B= $elem->module eq "vars"C= $elem->type eq "use"
ABCresult
0XX0
10X0
1100
1111
272 and $elem->module eq 'vars'
273 and $elem->type eq 'use' )
274 {
275  
276 # do it the low-tech way
277 0 my $string = $elem->content();
278 0 my @vars = $string =~ /([\%\@\$][\w_:]+)/g;
279 0 ▶ if ( grep { $varname eq $_ } @vars ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$varname eq $_;} @vars) 0 0 0
280 0 $declaration = $elem;
281 0 last;
282 }
283 }
284  
285 }
286 9 ▶ last if $declaration or $cursor == $document;
Branch: 1 branch
BranchTrueFalseTotal
if $declaration or $cursor == $document 6 3 9
Condition66%2/3
$declaration or $cursor == $document
l!l&&r!l&&!r
603
MC/DC50%1/2
$declaration or $cursor == $document
$declaration $cursor == $document
Truth table66%2/3
A or B
A= $declarationB= $cursor == $document
ABresult
1X1
011
000
287 }
288  
289 # this is for "foreach my $i ..."
290 ▶ elsif ( $cursor->isa("PPI::Statement::Compound")
Condition66%2/3
$cursor->isa("PPI::Statement::Compound") and $cursor->type =~ /^for/
!ll&&!rl&&r
603
MC/DC50%1/2
$cursor->isa("PPI::Statement::Compound") and $cursor->type =~ /^for/
$cursor->isa("PPI::Statement::Compound") $cursor->type =~ /^for/
Truth table66%2/3
A and B
A= $cursor->isa("PPI::Statement::Compound")B= $cursor->type =~ /^for/
ABresult
0X0
100
111
291 and $cursor->type() =~ /^for/ )
292 {
293 3 my @elems = $cursor->elements;
294 3 foreach my $elem (@elems) {
295  
296 # Stop scanning this scope if we're at the branch we're coming
297 # from. This is to ignore declarations later in the block.
298 27 ▶ last if $elem == $prev_cursor;
Branch: 1 branch
BranchTrueFalseTotal
if $elem == $prev_cursor 3 24 27
299  
300 24 ▶ if ( $elem->isa("PPI::Token::Word")
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Word") and $elem->content =~ /^(?:my|our)$/) 3 21 24
Condition100%3/3
$elem->isa("PPI::Token::Word") and $elem->content =~ /^(?:my|our)$/
!ll&&!rl&&r
1833
MC/DC100%2/2
$elem->isa("PPI::Token::Word") and $elem->content =~ /^(?:my|our)$/
$elem->isa("PPI::Token::Word") $elem->content =~ /^(?:my|our)$/
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Word")B= $elem->content =~ /^(?:my|our)$/
ABresult
0X0
100
111
301 and $elem->content() =~ /^(?:my|our)$/ )
302 {
303 3 my $nelem = $elem->snext_sibling();
304 3 ▶ if ( defined $nelem
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nelem and $nelem->isa("PPI::Token::Symbol") and $nelem->symbol eq $varname || $nelem->content eq $token_str) 0 3 3
Condition33%3/9
defined $nelem and $nelem->isa("PPI::Token::Symbol") and $nelem->symbol eq $varname || $nelem->content eq $token_str
!ll&&!rl&&r
030
defined $nelem and $nelem->isa("PPI::Token::Symbol")
!ll&&!rl&&r
003
$nelem->symbol eq $varname or $nelem->content eq $token_str
l!l&&r!l&&!r
003
MC/DC0%0/4
defined $nelem and $nelem->isa("PPI::Token::Symbol") and $nelem->symbol eq $varname || $nelem->content eq $token_str
defined $nelem $nelem->isa("PPI::Token::Symbol") $nelem->symbol eq $varname $nelem->content eq $token_str
Truth table20%1/5
A and B and C or D
A= defined $nelemB= $nelem->isa("PPI::Token::Symbol")C= $nelem->symbol eq $varnameD= $nelem->content eq $token_str
ABCDresult
0XXX0
10XX0
11000
111X1
11011
305 and $nelem->isa("PPI::Token::Symbol")
306 and $nelem->symbol() eq $varname || $nelem->content() eq $token_str )
307 {
308 0 $declaration = $nelem;
309 0 last;
310 }
311 }
312 }
313 3 ▶ last if $declaration or $cursor == $document;
Branch: 1 branch
BranchTrueFalseTotal
if $declaration or $cursor == $document 0 3 3
Condition33%1/3
$declaration or $cursor == $document
l!l&&r!l&&!r
003
MC/DC0%0/2
$declaration or $cursor == $document
$declaration $cursor == $document
Truth table33%1/3
A or B
A= $declarationB= $cursor == $document
ABresult
1X1
011
000
314 }
315 } # end while not top level
316  
317 6 return $declaration;
318 }
319  
320 24 1;
321  
322 =pod
323  
324 =encoding UTF-8
325  
326 =head1 NAME
327  
328 PPIx::EditorTools - Utility methods and base class for manipulating Perl via PPI
329  
330 =head1 VERSION
331  
332 version 0.21
333  
334 =head1 SYNOPSIS
335  
336 See PPIx::EditorTools::*
337  
338 =head1 DESCRIPTION
339  
340 Base class and utility methods for manipulating Perl via PPI. Pulled out from
341 the C<Padre::Task::PPI> code.
342  
343 =head1 METHODS
344  
345 =over 4
346  
347 =item new()
348  
349 Constructor. Generally shouldn't be called with any arguments.
350  
351 =back
352  
353 =head1 SEE ALSO
354  
355 C<PPIx::EditorTools::*>, L<Padre>, L<App::EditorTools>, L<Padre>, and L<PPI>.
356  
357 =head1 AUTHORS
358  
359 =over 4
360  
361 =item *
362  
363 Steffen Mueller C<smueller@cpan.org>
364  
365 =item *
366  
367 Mark Grimes C<mgrimes@cpan.org>
368  
369 =item *
370  
371 Ahmad M. Zawawi <ahmad.zawawi@gmail.com>
372  
373 =item *
374  
375 Gabor Szabo <gabor@szabgab.com>
376  
377 =item *
378  
379 Yanick Champoux <yanick@cpan.org>
380  
381 =back
382  
383 =head1 COPYRIGHT AND LICENSE
384  
385 This software is copyright (c) 2017, 2014, 2012 by The Padre development team as listed in Padre.pm..
386  
387 This is free software; you can redistribute it and/or modify it under
388 the same terms as the Perl 5 programming language system itself.
389  
390 =cut
391  
392 __END__
↑ Summary blib/lib/PPIx/EditorTools/RenameVariable.pm »