| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPIx::EditorTools; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Utility methods and base class for manipulating Perl via PPI |
|
4
|
|
|
|
|
|
|
$PPIx::EditorTools::VERSION = '0.21'; |
|
5
|
11
|
|
|
11
|
|
189161
|
use 5.008; |
|
|
11
|
|
|
|
|
37
|
|
|
6
|
11
|
|
|
11
|
|
49
|
use strict; |
|
|
11
|
|
|
|
|
15
|
|
|
|
11
|
|
|
|
|
235
|
|
|
7
|
11
|
|
|
11
|
|
42
|
use warnings; |
|
|
11
|
|
|
|
|
17
|
|
|
|
11
|
|
|
|
|
299
|
|
|
8
|
11
|
|
|
11
|
|
44
|
use Carp; |
|
|
11
|
|
|
|
|
35
|
|
|
|
11
|
|
|
|
|
722
|
|
|
9
|
11
|
|
|
|
|
60
|
use Class::XSAccessor 1.02 constructor => 'new', accessors => { |
|
10
|
|
|
|
|
|
|
'code' => 'code', |
|
11
|
|
|
|
|
|
|
'ppi' => 'ppi', |
|
12
|
11
|
|
|
11
|
|
3674
|
}; |
|
|
11
|
|
|
|
|
18719
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
11
|
|
|
11
|
|
3050
|
use PPI 1.203; |
|
|
11
|
|
|
|
|
99055
|
|
|
|
11
|
|
|
|
|
209
|
|
|
15
|
11
|
|
|
11
|
|
4343
|
use PPIx::EditorTools::ReturnObject; |
|
|
11
|
|
|
|
|
22
|
|
|
|
11
|
|
|
|
|
13874
|
|
|
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
|
|
|
|
|
|
|
sub process_doc { |
|
23
|
52
|
|
|
52
|
0
|
5688
|
my ( $self, %args ) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
52
|
50
|
|
|
|
173
|
$self->ppi( $args{ppi} ) if defined $args{ppi}; |
|
26
|
52
|
100
|
66
|
|
|
261
|
return 1 if $self->ppi && $self->ppi->isa('PPI::Document'); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# TODO: inefficient to pass around full code/ppi |
|
29
|
41
|
100
|
|
|
|
178
|
$self->code( $args{code} ) if $args{code}; |
|
30
|
41
|
|
|
|
|
81
|
my $code = $self->code; |
|
31
|
41
|
|
|
|
|
283
|
$self->ppi( PPI::Document->new( \$code ) ); |
|
32
|
41
|
100
|
66
|
|
|
263533
|
return 1 if $self->ppi && $self->ppi->isa('PPI::Document'); |
|
33
|
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
12
|
croak "arguments ppi or code required"; |
|
35
|
0
|
|
|
|
|
0
|
return; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
##################################################################### |
|
43
|
|
|
|
|
|
|
# Assorted Search Functions |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub find_unmatched_brace { |
|
46
|
59
|
50
|
|
59
|
0
|
667
|
$_[1]->isa('PPI::Statement::UnmatchedBrace') and return 1; |
|
47
|
58
|
100
|
|
|
|
142
|
$_[1]->isa('PPI::Structure') or return ''; |
|
48
|
3
|
100
|
66
|
|
|
17
|
$_[1]->start and $_[1]->finish and return ''; |
|
49
|
2
|
|
|
|
|
24
|
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
|
|
|
|
|
|
|
sub get_all_variable_declarations { |
|
71
|
3
|
|
|
3
|
0
|
9137
|
my $document = shift; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $declarations = $document->find( |
|
74
|
|
|
|
|
|
|
sub { |
|
75
|
55
|
100
|
66
|
55
|
|
752
|
return 0 |
|
|
|
|
100
|
|
|
|
|
|
76
|
|
|
|
|
|
|
unless $_[1]->isa('PPI::Statement::Variable') |
|
77
|
|
|
|
|
|
|
or $_[1]->isa('PPI::Statement::Include') |
|
78
|
|
|
|
|
|
|
or $_[1]->isa('PPI::Statement::Compound'); |
|
79
|
3
|
|
|
|
|
6
|
return 1; |
|
80
|
|
|
|
|
|
|
}, |
|
81
|
3
|
|
|
|
|
35
|
); |
|
82
|
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
26
|
my %our; |
|
84
|
|
|
|
|
|
|
my %lexical; |
|
85
|
2
|
|
|
|
|
0
|
my %dynamic; |
|
86
|
2
|
|
|
|
|
0
|
my %package; |
|
87
|
2
|
|
|
|
|
4
|
foreach my $decl (@$declarations) { |
|
88
|
3
|
50
|
66
|
|
|
61
|
if ( $decl->isa('PPI::Statement::Variable') ) { |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
my $type = $decl->type(); |
|
90
|
0
|
|
|
|
|
0
|
my @vars = $decl->variables; |
|
91
|
0
|
|
|
|
|
0
|
my $location = $decl->location; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
my $target_type; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
0
|
if ( $type eq 'my' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
$target_type = \%lexical; |
|
97
|
|
|
|
|
|
|
} elsif ( $type eq 'our' ) { |
|
98
|
0
|
|
|
|
|
0
|
$target_type = \%our; |
|
99
|
|
|
|
|
|
|
} elsif ( $type eq 'local' ) { |
|
100
|
0
|
|
|
|
|
0
|
$target_type = \%dynamic; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
foreach my $var (@vars) { |
|
104
|
0
|
|
0
|
|
|
0
|
$target_type->{$var} ||= []; |
|
105
|
0
|
|
|
|
|
0
|
push @{ $target_type->{$var} }, $location; |
|
|
0
|
|
|
|
|
0
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# find use vars... |
|
110
|
|
|
|
|
|
|
elsif ( $decl->isa('PPI::Statement::Include') |
|
111
|
|
|
|
|
|
|
and $decl->module eq 'vars' |
|
112
|
|
|
|
|
|
|
and $decl->type eq 'use' ) |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# do it the low-tech way |
|
116
|
0
|
|
|
|
|
0
|
my $string = $decl->content(); |
|
117
|
0
|
|
|
|
|
0
|
my $location = $decl->location; |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
my @vars = $string =~ /([\%\@\$][\w_:]+)/g; |
|
120
|
0
|
|
|
|
|
0
|
foreach my $var (@vars) { |
|
121
|
0
|
|
0
|
|
|
0
|
$package{$var} ||= []; |
|
122
|
0
|
|
|
|
|
0
|
push @{ $package{$var} }, $location; |
|
|
0
|
|
|
|
|
0
|
|
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# find for/foreach loop variables |
|
128
|
|
|
|
|
|
|
elsif ( $decl->isa('PPI::Statement::Compound') |
|
129
|
|
|
|
|
|
|
&& ( $decl->type eq 'for' or $decl->type eq 'foreach' ) ) |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
2
|
|
|
|
|
150
|
my @elems = $decl->elements; |
|
132
|
|
|
|
|
|
|
|
|
133
|
2
|
50
|
|
|
|
23
|
next if scalar(@elems) < 5; |
|
134
|
2
|
|
|
|
|
7
|
my $location = $decl->location; |
|
135
|
2
|
|
|
|
|
1214
|
my $type = $elems[2]->content(); |
|
136
|
2
|
50
|
33
|
|
|
15
|
if ( $elems[4]->isa('PPI::Token::Symbol') |
|
|
|
|
33
|
|
|
|
|
|
137
|
|
|
|
|
|
|
&& ( $type eq 'my' || $type eq 'our' ) ) |
|
138
|
|
|
|
|
|
|
{ |
|
139
|
2
|
|
|
|
|
3
|
my $target_type; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Only my and our are valid for loop variable |
|
142
|
2
|
50
|
|
|
|
4
|
if ( $type eq 'my' ) { |
|
|
|
0
|
|
|
|
|
|
|
143
|
2
|
|
|
|
|
3
|
$target_type = \%lexical; |
|
144
|
|
|
|
|
|
|
} elsif ( $type eq 'our' ) { |
|
145
|
0
|
|
|
|
|
0
|
$target_type = \%our; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
2
|
|
|
|
|
5
|
my $var = $elems[4]->content(); |
|
149
|
2
|
|
50
|
|
|
20
|
$target_type->{$var} ||= []; |
|
150
|
2
|
|
|
|
|
3
|
push @{ $target_type->{$var} }, $location; |
|
|
2
|
|
|
|
|
6
|
|
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} # end foreach declaration |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return ( |
|
156
|
2
|
|
|
|
|
15
|
{ 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
|
|
|
|
|
|
|
sub element_depth { |
|
172
|
1
|
|
|
1
|
0
|
26
|
my $cursor = shift; |
|
173
|
1
|
|
|
|
|
2
|
my $depth = 0; |
|
174
|
1
|
|
|
|
|
11
|
while ( $cursor = $cursor->parent ) { |
|
175
|
0
|
|
|
|
|
0
|
$depth += 1; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub find_token_at_location { |
|
183
|
17
|
|
|
17
|
0
|
52
|
my $document = shift; |
|
184
|
17
|
|
|
|
|
24
|
my $location = shift; |
|
185
|
|
|
|
|
|
|
|
|
186
|
17
|
50
|
66
|
|
|
182
|
if ( not defined $document |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
187
|
|
|
|
|
|
|
or not $document->isa('PPI::Document') |
|
188
|
|
|
|
|
|
|
or not defined $location |
|
189
|
|
|
|
|
|
|
or not ref($location) eq 'ARRAY' ) |
|
190
|
|
|
|
|
|
|
{ |
|
191
|
1
|
|
|
|
|
5
|
require Carp; |
|
192
|
1
|
|
|
|
|
8
|
Carp::croak("find_token_at_location() requires a PPI::Document and a PPI-style location as arguments"); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
16
|
|
|
|
|
85
|
$document->index_locations(); |
|
196
|
|
|
|
|
|
|
|
|
197
|
16
|
|
|
|
|
29857
|
foreach my $token ( $document->tokens ) { |
|
198
|
656
|
|
|
|
|
4252
|
my $loc = $token->location; |
|
199
|
656
|
100
|
100
|
|
|
6866
|
if ( $loc->[0] > $location->[0] |
|
|
|
|
66
|
|
|
|
|
|
200
|
|
|
|
|
|
|
or ( $loc->[0] == $location->[0] and $loc->[1] > $location->[1] ) ) |
|
201
|
|
|
|
|
|
|
{ |
|
202
|
16
|
|
|
|
|
48
|
$document->flush_locations(); |
|
203
|
16
|
|
|
|
|
5059
|
return $token->previous_token(); |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
} |
|
206
|
0
|
|
|
|
|
0
|
$document->flush_locations(); |
|
207
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub find_variable_declaration { |
|
216
|
10
|
|
|
10
|
0
|
16
|
my $cursor = shift; |
|
217
|
|
|
|
|
|
|
return () |
|
218
|
10
|
50
|
33
|
|
|
52
|
if not $cursor |
|
219
|
|
|
|
|
|
|
or not $cursor->isa("PPI::Token"); |
|
220
|
10
|
|
|
|
|
20
|
my ( $varname, $token_str ); |
|
221
|
10
|
50
|
|
|
|
26
|
if ( $cursor->isa("PPI::Token::Symbol") ) { |
|
222
|
10
|
|
|
|
|
34
|
$varname = $cursor->symbol; |
|
223
|
10
|
|
|
|
|
611
|
$token_str = $cursor->content; |
|
224
|
|
|
|
|
|
|
} else { |
|
225
|
0
|
|
|
|
|
0
|
my $content = $cursor->content; |
|
226
|
0
|
0
|
|
|
|
0
|
if ( $content =~ /((?:\$#?|[@%*])[\w:\']+)/ ) { |
|
227
|
0
|
|
|
|
|
0
|
$varname = $1; |
|
228
|
0
|
|
|
|
|
0
|
$token_str = $1; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
return () |
|
232
|
10
|
50
|
|
|
|
45
|
if not defined $varname; |
|
233
|
|
|
|
|
|
|
|
|
234
|
10
|
|
|
|
|
34
|
$varname =~ s/^\$\#/@/; |
|
235
|
|
|
|
|
|
|
|
|
236
|
10
|
|
|
|
|
29
|
my $document = $cursor->top(); |
|
237
|
10
|
|
|
|
|
136
|
my $declaration; |
|
238
|
|
|
|
|
|
|
my $prev_cursor; |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# This finds variable declarations if you're above it |
|
241
|
10
|
100
|
|
|
|
42
|
if ( $cursor->parent->isa('PPI::Statement::Variable') ) { |
|
242
|
6
|
|
|
|
|
52
|
return $cursor->parent; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# This finds variable declarations if you're above it and it has the form my ($foo , $bar); |
|
246
|
4
|
50
|
33
|
|
|
36
|
if ( $cursor->parent->isa('PPI::Statement::Expression') |
|
247
|
|
|
|
|
|
|
&& $cursor->parent->parent->parent->isa('PPI::Statement::Variable') ) |
|
248
|
|
|
|
|
|
|
{ |
|
249
|
0
|
|
|
|
|
0
|
return $cursor->parent->parent->parent; |
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
4
|
|
|
|
|
29
|
while (1) { |
|
253
|
12
|
|
|
|
|
75
|
$prev_cursor = $cursor; |
|
254
|
12
|
|
|
|
|
50
|
$cursor = $cursor->parent; |
|
255
|
12
|
100
|
100
|
|
|
79
|
if ( $cursor->isa("PPI::Structure::Block") or $cursor == $document ) { |
|
|
|
100
|
66
|
|
|
|
|
|
256
|
6
|
|
|
|
|
27
|
my @elems = $cursor->elements; |
|
257
|
6
|
|
|
|
|
94
|
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
|
45
|
100
|
|
|
|
165
|
last if $elem == $prev_cursor; |
|
262
|
|
|
|
|
|
|
|
|
263
|
43
|
100
|
100
|
|
|
316
|
if ( $elem->isa("PPI::Statement::Variable") |
|
|
|
50
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
264
|
6
|
|
|
|
|
246
|
and grep { $_ eq $varname } $elem->variables ) |
|
265
|
|
|
|
|
|
|
{ |
|
266
|
4
|
|
|
|
|
7
|
$declaration = $elem; |
|
267
|
4
|
|
|
|
|
7
|
last; |
|
268
|
|
|
|
|
|
|
} |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# find use vars ... |
|
271
|
|
|
|
|
|
|
elsif ( $elem->isa("PPI::Statement::Include") |
|
272
|
|
|
|
|
|
|
and $elem->module eq 'vars' |
|
273
|
|
|
|
|
|
|
and $elem->type eq 'use' ) |
|
274
|
|
|
|
|
|
|
{ |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# do it the low-tech way |
|
277
|
0
|
|
|
|
|
0
|
my $string = $elem->content(); |
|
278
|
0
|
|
|
|
|
0
|
my @vars = $string =~ /([\%\@\$][\w_:]+)/g; |
|
279
|
0
|
0
|
|
|
|
0
|
if ( grep { $varname eq $_ } @vars ) { |
|
|
0
|
|
|
|
|
0
|
|
|
280
|
0
|
|
|
|
|
0
|
$declaration = $elem; |
|
281
|
0
|
|
|
|
|
0
|
last; |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
} |
|
286
|
6
|
100
|
66
|
|
|
38
|
last if $declaration or $cursor == $document; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# this is for "foreach my $i ..." |
|
290
|
|
|
|
|
|
|
elsif ( $cursor->isa("PPI::Statement::Compound") |
|
291
|
|
|
|
|
|
|
and $cursor->type() =~ /^for/ ) |
|
292
|
|
|
|
|
|
|
{ |
|
293
|
2
|
|
|
|
|
132
|
my @elems = $cursor->elements; |
|
294
|
2
|
|
|
|
|
22
|
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
|
18
|
100
|
|
|
|
236
|
last if $elem == $prev_cursor; |
|
299
|
|
|
|
|
|
|
|
|
300
|
16
|
100
|
100
|
|
|
95
|
if ( $elem->isa("PPI::Token::Word") |
|
301
|
|
|
|
|
|
|
and $elem->content() =~ /^(?:my|our)$/ ) |
|
302
|
|
|
|
|
|
|
{ |
|
303
|
2
|
|
|
|
|
22
|
my $nelem = $elem->snext_sibling(); |
|
304
|
2
|
50
|
33
|
|
|
86
|
if ( defined $nelem |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
305
|
|
|
|
|
|
|
and $nelem->isa("PPI::Token::Symbol") |
|
306
|
|
|
|
|
|
|
and $nelem->symbol() eq $varname || $nelem->content() eq $token_str ) |
|
307
|
|
|
|
|
|
|
{ |
|
308
|
0
|
|
|
|
|
0
|
$declaration = $nelem; |
|
309
|
0
|
|
|
|
|
0
|
last; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
|
|
|
|
|
|
} |
|
312
|
|
|
|
|
|
|
} |
|
313
|
2
|
50
|
33
|
|
|
18
|
last if $declaration or $cursor == $document; |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
} # end while not top level |
|
316
|
|
|
|
|
|
|
|
|
317
|
4
|
|
|
|
|
25
|
return $declaration; |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
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 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, L, L, L, and L. |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head1 AUTHORS |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=over 4 |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=item * |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
Steffen Mueller C |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=item * |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
Mark Grimes C |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=item * |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
Ahmad M. Zawawi |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
=item * |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
Gabor Szabo |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=item * |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
Yanick Champoux |
|
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__ |