PLS/Parser/Document.pm

filter: Statementstmt 30.8% 235 / 761 Branchbran 18.3% 83 / 452 Conditioncond 43.1% 166 / 385 MC/DCmcdc 19.2% 37 / 192 Subroutinesub 48.3% 44 / 91 Podpod 90.6% 29 / 32 totaltotal 31.0% 594 / 1913 CC 368 SCAR 62.5
CC
368
Cov
30%
search_elements_for_definition
2352.0
go_to_variable_definition
1190.0
sort_imports
506.0
CRAP 516.6
↑ Summary PLS/Parser/Pod/Subroutine.pm »
1 package PLS::Parser::Document;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use List::Util qw(first any);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use PPI::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use PPR;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Perl::Tidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Time::Seconds;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 ▶use PLS::Parser::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use PLS::Parser::Element::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶use PLS::Parser::Element::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use PLS::Parser::Element::Subroutine;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶use PLS::Parser::Element::VariableStatement;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶use PLS::Parser::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use PLS::Parser::Pod::ClassMethod;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use PLS::Parser::Pod::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶use PLS::Parser::Pod::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 11 ▶use PLS::Parser::Pod::Subroutine;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 11 ▶use PLS::Parser::Pod::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 11 my %FILES;
35 my %VERSIONS;
36  
37 =head1 NAME
38  
39 PLS::Parser::Document
40  
41 =head1 DESCRIPTION
42  
43 This is a class that represents a text document. It has methods
44 for parsing and manipulating the document using L<PPI> and L<PPR>.
45  
46 =head1 METHODS
47  
48 =head2 new
49  
50 This creates a new L<PLS::Parser::Document> object.
51 It takes named parameters.
52  
53 Either C<uri> or C<path> must be passed.
54  
55 C<line> with a line number may be passed, which indicates that only one line
56 of the document should be parsed. This greatly enhances performance for completion items.
57  
58 =cut
59  
60 sub new
61 {
62 33 ▶ my ($class, %args) = @_;
Subroutine new: called CC=6 SCAR=17.9
Pod documented
63  
64 33 my ($path, $uri);
65  
66 33 ▶ if (length $args{uri})
Branch: 2 branches
BranchTrueFalseTotal
if (length $args{'uri'}) { } 30 3 33
elsif (length $args{'path'}) { } 2 1 3
67 {
68 30 $path = URI->new($args{uri})->file;
69 30 $args{path} = $path;
70 30 $uri = $args{uri};
71 } ## end if (length $args{uri})
72 elsif (length $args{path})
73 {
74 2 $path = $args{path};
75 2 $uri = URI::file->new($path)->as_string;
76 2 $args{uri} = $uri;
77 } ## end elsif (length $args{path}...)
78 33 ▶ return unless (length $path and length $uri);
Branch: 1 branch
BranchTrueFalseTotal
unless length $path and length $uri 1 32 33
Condition66%2/3
length $path and length $uri
!ll&&!rl&&r
1032
MC/DC50%1/2
length $path and length $uri
length $path length $uri
Truth table66%2/3
A and B
A= length $pathB= length $uri
ABresult
0X0
100
111
79  
80 32 my $self = bless {
81 path => $path,
82 uri => $uri
83 }, $class;
84  
85 32 $self->{index} = PLS::Parser::Index->new();
86 32 my $document = $self->_get_ppi_document(%args);
87 32 ▶ return unless (ref $document eq 'PPI::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "PPI::Document" 2 30 32
88 30 $self->{document} = $document;
89  
90 30 return $self;
91 } ## end sub new
92  
93 =head2 go_to_definition
94  
95 This finds the definition of a symbol located at a given line and column number.
96  
97 =cut
98  
99 sub go_to_definition
100 {
101 0 ▶ my ($self, $line_number, $column_number) = @_;
Subroutine go_to_definition: not called CC=1 SCAR=6.9
Pod documented
102  
103 0 my @matches = $self->find_elements_at_location($line_number, $column_number);
104  
105 0 return $self->search_elements_for_definition($line_number, $column_number, @matches);
106 } ## end sub go_to_definition
107  
108 =head2 find_current_list
109  
110 This finds the nearest list structure that surrounds the current column on the current line.
111 This is useful for finding which parameter the cursor is on when calling a function.
112  
113 =cut
114  
115 sub find_current_list
116 {
117 0 ▶ my ($self, $line_number, $column_number) = @_;
Subroutine find_current_list: not called CC=1 SCAR=6.9
Pod documented
118  
119 0 my @elements = $self->find_elements_at_location($line_number, $column_number);
120 0 ▶ my $find = PPI::Find->new(sub { $_[0]->isa('PPI::Structure::List') });
Subroutine __ANON__: not called CC=1 SCAR=6.9
121  
122 # Find the nearest list structure that completely surrounds the column.
123 0 ▶ return first { $_->lsp_column_number < $column_number and $column_number < $_->lsp_column_number + length($_->content) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_->lsp_column_number < $column_number and $column_number < $_->lsp_column_number + length($_->content) 0 0 0
124 0 sort { abs($column_number - $a->lsp_column_number) - abs($column_number - $b->lsp_column_number) }
125 0 map { PLS::Parser::Element->new(element => $_, document => $self->{document}, file => $self->{path}) }
126 0 map { $find->in($_->element) } @elements;
127 } ## end sub find_current_list
128  
129 =head2 go_to_definition_of_closest_subroutine
130  
131 Given a list of elements, this finds the closest subroutine call to the current line and column.
132  
133 =cut
134  
135 sub go_to_definition_of_closest_subroutine
136 {
137 0 ▶ my ($self, $list, $line_number, $column_number) = @_;
Subroutine go_to_definition_of_closest_subroutine: not called CC=11 SCAR=48.8
Pod documented
138  
139 0 ▶ return if (not blessed($list) or not $list->isa('PLS::Parser::Element') and $list->type eq 'PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($list) or not $list->isa("PLS::Parser::Element") and $list->type eq "PPI::Structure::List" 0 0 0
Condition0%0/6
not builtin::blessed($list) or not $list->isa("PLS::Parser::Element") and $list->type eq "PPI::Structure::List"
l!l&&r!l&&!r
000
not $list->isa("PLS::Parser::Element") and $list->type eq "PPI::Structure::List"
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($list) or not $list->isa("PLS::Parser::Element") and $list->type eq "PPI::Structure::List"
not builtin::blessed($list) not $list->isa("PLS::Parser::Element") $list->type eq "PPI::Structure::List"
Truth table0%0/4
not(A) or not(B) and C
A= not builtin::blessed($list)B= not $list->isa("PLS::Parser::Element")C= $list->type eq "PPI::Structure::List"
ABCresult
1XX1
0111
00X0
0100
140  
141 # Try to find the closest word before the list - this is the function name.
142 0 my $word = $list;
143  
144 0 ▶ while (blessed($word) and $word->isa('PLS::Parser::Element') and not $word->element->isa('PPI::Token::Word'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($word) and $word->isa("PLS::Parser::Element") and not $word->element->isa("PPI::Token::Word")) 0 0 0
Condition0%0/6
builtin::blessed($word) and $word->isa("PLS::Parser::Element") and not $word->element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
builtin::blessed($word) and $word->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($word) and $word->isa("PLS::Parser::Element") and not $word->element->isa("PPI::Token::Word")
builtin::blessed($word) $word->isa("PLS::Parser::Element") not $word->element->isa("PPI::Token::Word")
Truth table0%0/4
A and B and not(C)
A= builtin::blessed($word)B= $word->isa("PLS::Parser::Element")C= not $word->element->isa("PPI::Token::Word")
ABCresult
0XX0
10X0
1100
1111
145 {
146 0 $word = $word->previous_sibling;
147 }
148  
149 0 ▶ return if (not blessed($word) or not $word->isa('PLS::Parser::Element') or not $word->element->isa('PPI::Token::Word'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($word) and $word->isa("PLS::Parser::Element") and $word->element->isa("PPI::Token::Word") 0 0 0
Condition0%0/6
builtin::blessed($word) and $word->isa("PLS::Parser::Element") and $word->element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
builtin::blessed($word) and $word->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($word) and $word->isa("PLS::Parser::Element") and $word->element->isa("PPI::Token::Word")
builtin::blessed($word) $word->isa("PLS::Parser::Element") $word->element->isa("PPI::Token::Word")
Truth table0%0/4
A and B and C
A= builtin::blessed($word)B= $word->isa("PLS::Parser::Element")C= $word->element->isa("PPI::Token::Word")
ABCresult
0XX0
10X0
1100
1111
150 0 my $definitions = $self->search_elements_for_definition($line_number, $column_number, $word);
151 0 ▶ return $definitions, $word if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
152 0 return $definitions;
153 } ## end sub go_to_definition_of_closest_subroutine
154  
155 =head2 search_elements_for_definition
156  
157 This tries to find the definition in a list of elements, and returns the first definition found.
158  
159 =cut
160  
161 sub search_elements_for_definition
162 {
163 0 ▶ my ($self, $line_number, $column_number, @matches) = @_;
Subroutine search_elements_for_definition: not called CC=48 SCAR=77.6
Pod documented
164  
165 0 my $this_files_package;
166 my @this_files_subroutines;
167  
168 0 ▶ if (ref $self->{index} ne 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"index"} ne "PLS::Parser::Index") 0 0 0
169 {
170 0 ($this_files_package) = @{$self->get_packages()};
171 0 @this_files_subroutines = (@{$self->get_subroutines()}, @{$self->get_constants()});
172 }
173  
174 0 foreach my $match (@matches)
175 {
176 0 ▶ if (my ($package, $subroutine) = $match->subroutine_package_and_name())
Branch: 1 branch
BranchTrueFalseTotal
if (() = $match->subroutine_package_and_name) 0 0 0
177 {
178 0 ▶ if ($match->cursor_on_package($column_number))
Branch: 1 branch
BranchTrueFalseTotal
if ($match->cursor_on_package($column_number)) 0 0 0
179 {
180 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
181 {
182 0 return $self->{index}->find_package($package);
183 }
184 else
185 {
186 0 ▶ return [{uri => $self->{uri}, range => $this_files_package->range}] if (ref $this_files_package eq 'PLS::Parser::Element::Package' and $this_files_package->name eq $package);
Branch: 1 branch
BranchTrueFalseTotal
if ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package 0 0 0
Condition0%0/3
ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package
ref $this_files_package eq "PLS::Parser::Element::Package" $this_files_package->name eq $package
Truth table0%0/3
A and B
A= ref $this_files_package eq "PLS::Parser::Element::Package"B= $this_files_package->name eq $package
ABresult
0X0
100
111
187  
188 0 my $external = $self->find_external_package($package);
189 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
190 } ## end else [ if (ref $self->{index}...)]
191 } ## end if ($match->cursor_on_package...)
192  
193 0 ▶ if (length $package)
Branch: 1 branch
BranchTrueFalseTotal
if (length $package) 0 0 0
194 {
195 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
196 {
197 0 my $results = $self->{index}->find_package_subroutine($package, $subroutine);
198 0 ▶ return $results if (ref $results eq 'ARRAY' and scalar @{$results});
Branch: 1 branch
BranchTrueFalseTotal
if ref $results eq "ARRAY" and scalar @{$results;} 0 0 0
Condition0%0/2
ref $results eq "ARRAY" and scalar @{$results;}
!ll
00
MC/DC0%0/1
ref $results eq "ARRAY" and scalar @{$results;}
ref $results eq "ARRAY"
Truth table0%0/2
A
A= ref $results eq "ARRAY"
Aresult
00
11
199 }
200 else
201 {
202 0 ▶ if (ref $this_files_package eq 'PLS::Parser::Element::Package' and $this_files_package->name eq $package)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package) 0 0 0
Condition0%0/3
ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package
!ll&&!rl&&r
000
MC/DC0%0/2
ref $this_files_package eq "PLS::Parser::Element::Package" and $this_files_package->name eq $package
ref $this_files_package eq "PLS::Parser::Element::Package" $this_files_package->name eq $package
Truth table0%0/3
A and B
A= ref $this_files_package eq "PLS::Parser::Element::Package"B= $this_files_package->name eq $package
ABresult
0X0
100
111
203 {
204 0 ▶ my $found = first { $_->name eq $subroutine } @this_files_subroutines;
Subroutine __ANON__: not called CC=1 SCAR=6.9
205 0 ▶ return {uri => $self->{uri}, range => $found->range} if (blessed($found) and $found->isa('PLS::Parser::Element'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($found) and $found->isa("PLS::Parser::Element") 0 0 0
Condition0%0/3
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
builtin::blessed($found) $found->isa("PLS::Parser::Element")
Truth table0%0/3
A and B
A= builtin::blessed($found)B= $found->isa("PLS::Parser::Element")
ABresult
0X0
100
111
206 }
207 } ## end else [ if (ref $self->{index}...)]
208  
209 0 my $external = $self->find_external_subroutine($package, $subroutine);
210 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
211 } ## end if (length $package)
212  
213 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"index"} eq "PLS::Parser::Index") 0 0 0
214 {
215 0 my $results = $self->{index}->find_subroutine($subroutine);
216 0 ▶ return $results if (ref $results eq 'ARRAY' and scalar @{$results});
Branch: 1 branch
BranchTrueFalseTotal
if ref $results eq "ARRAY" and scalar @{$results;} 0 0 0
Condition0%0/2
ref $results eq "ARRAY" and scalar @{$results;}
!ll
00
MC/DC0%0/1
ref $results eq "ARRAY" and scalar @{$results;}
ref $results eq "ARRAY"
Truth table0%0/2
A
A= ref $results eq "ARRAY"
Aresult
00
11
217  
218 0 @this_files_subroutines = (@{$self->get_subroutines()}, @{$self->get_constants()});
219 } ## end if (ref $self->{index}...)
220  
221 0 ▶ my $found = first { $_->name eq $subroutine } @this_files_subroutines;
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 0 ▶ return {uri => $self->{uri}, range => $found->range} if (blessed($found) and $found->isa('PLS::Parser::Element'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($found) and $found->isa("PLS::Parser::Element") 0 0 0
Condition0%0/3
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
builtin::blessed($found) $found->isa("PLS::Parser::Element")
Truth table0%0/3
A and B
A= builtin::blessed($found)B= $found->isa("PLS::Parser::Element")
ABresult
0X0
100
111
223 } ## end if (my ($package, $subroutine...))
224 0 ▶ if (my ($class, $method) = $match->class_method_package_and_name())
Branch: 1 branch
BranchTrueFalseTotal
if (() = $match->class_method_package_and_name) 0 0 0
225 {
226 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
227 {
228 0 my $results = $self->{index}->find_package_subroutine($class, $method);
229  
230 # fall back to treating as a method instead of class method
231 0 ▶ return $results if (ref $results eq 'ARRAY' and scalar @$results);
Branch: 1 branch
BranchTrueFalseTotal
if ref $results eq "ARRAY" and scalar @$results 0 0 0
Condition0%0/2
ref $results eq "ARRAY" and scalar @$results
!ll
00
MC/DC0%0/1
ref $results eq "ARRAY" and scalar @$results
ref $results eq "ARRAY"
Truth table0%0/2
A
A= ref $results eq "ARRAY"
Aresult
00
11
232 } ## end if (ref $self->{index}...)
233 else
234 {
235 0 ▶ my $found = first { $_->name eq $method } @this_files_subroutines;
Subroutine __ANON__: not called CC=1 SCAR=6.9
236 0 ▶ return {uri => $self->{uri}, range => $found->range} if (blessed($found) and $found->isa('PLS::Parser::Element'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($found) and $found->isa("PLS::Parser::Element") 0 0 0
Condition0%0/3
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
builtin::blessed($found) $found->isa("PLS::Parser::Element")
Truth table0%0/3
A and B
A= builtin::blessed($found)B= $found->isa("PLS::Parser::Element")
ABresult
0X0
100
111
237 }
238  
239 0 my $external = $self->find_external_subroutine($class, $method);
240 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
241 } ## end if (my ($class, $method...))
242 0 ▶ if (my $method = $match->method_name())
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $match->method_name) 0 0 0
243 {
244 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
245 {
246 0 return $self->{index}->find_subroutine($method);
247 }
248 else
249 {
250 0 ▶ my $found = first { $_->name eq $method } @this_files_subroutines;
Subroutine __ANON__: not called CC=1 SCAR=6.9
251 0 ▶ return {uri => $self->{uri}, range => $found->range} if (blessed($found) and $found->isa('PLS::Parser::Element'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($found) and $found->isa("PLS::Parser::Element") 0 0 0
Condition0%0/3
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($found) and $found->isa("PLS::Parser::Element")
builtin::blessed($found) $found->isa("PLS::Parser::Element")
Truth table0%0/3
A and B
A= builtin::blessed($found)B= $found->isa("PLS::Parser::Element")
ABresult
0X0
100
111
252 }
253 } ## end if (my $method = $match...)
254 0 ▶ if (my ($package, $import) = $match->package_name($column_number))
Branch: 1 branch
BranchTrueFalseTotal
if (() = $match->package_name($column_number)) 0 0 0
255 {
256 0 ▶ if (length $import)
Branch: 1 branch
BranchTrueFalseTotal
if (length $import) { } 0 0 0
257 {
258 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
259 {
260 0 return $self->{index}->find_package_subroutine($package, $import);
261 }
262 else
263 {
264 0 my $external = $self->find_external_subroutine($package, $import);
265 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
266 }
267 } ## end if (length $import)
268 else
269 {
270 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
271 {
272 0 return $self->{index}->find_package($package);
273 }
274 else
275 {
276 0 my $external = $self->find_external_package($package);
277 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
278 }
279 } ## end else [ if (length $import) ]
280 } ## end if (my ($package, $import...))
281 0 ▶ if (my $variable = $match->variable_name())
Branch: 1 branch
BranchTrueFalseTotal
if (my $variable = $match->variable_name) 0 0 0
282 {
283 0 return $self->go_to_variable_definition($variable, $match, $line_number, $column_number);
284 }
285 } ## end foreach my $match (@matches...)
286  
287 # If all else fails, see if we're on a POD link.
288 0 ▶ if (my $link = $self->pod_link($line_number, $column_number))
Branch: 1 branch
BranchTrueFalseTotal
if (my $link = $self->pod_link($line_number, $column_number)) 0 0 0
289 {
290 0 my @pieces = split /::/, $link;
291 0 my $subroutine_name = pop @pieces;
292 0 my $package_name = join '::', @pieces;
293  
294 0 ▶ if (ref $self->{index} eq 'PLS::Parser::Index')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'index'} eq 'PLS::Parser::Index') { } 0 0 0
295 {
296 0 my $package = $self->{index}->find_package($link);
297 0 ▶ return $package if (ref $package eq 'ARRAY' and scalar @{$package});
Branch: 1 branch
BranchTrueFalseTotal
if ref $package eq "ARRAY" and scalar @{$package;} 0 0 0
Condition0%0/2
ref $package eq "ARRAY" and scalar @{$package;}
!ll
00
MC/DC0%0/1
ref $package eq "ARRAY" and scalar @{$package;}
ref $package eq "ARRAY"
Truth table0%0/2
A
A= ref $package eq "ARRAY"
Aresult
00
11
298  
299 0 ▶ return $self->{index}->find_package_subroutine($package_name, $subroutine_name) if (length $package_name);
Branch: 1 branch
BranchTrueFalseTotal
if length $package_name 0 0 0
300 0 return $self->{index}->find_subroutine($subroutine_name);
301 } ## end if (ref $self->{index}...)
302 else
303 {
304 0 my $external = $self->find_external_package($link);
305 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
306  
307 0 $external = $self->find_external_subroutine($package_name, $subroutine_name);
308 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
309 } ## end else [ if (ref $self->{index}...)]
310  
311 } ## end if (my $link = $self->...)
312  
313 0 return;
314 } ## end sub search_elements_for_definition
315  
316 =head2 pod_link
317  
318 This determines if the line and column are within a POD LE<lt>E<gt> code,
319 and returns the contents of the link if so.
320  
321 =cut
322  
323 sub pod_link
324 {
325 0 ▶ my ($self, $line_number, $column_number) = @_;
Subroutine pod_link: not called CC=8 SCAR=42.8
Pod documented
326  
327 0 $line_number++;
328  
329 my $find = PPI::Find->new(
330 sub {
331 0 ▶ my ($element) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
332 0 ▶ return 0 unless $element->isa('PPI::Token::Pod');
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("PPI::Token::Pod") 0 0 0
333 0 ▶ return 0 if $element->line_number > $line_number;
Branch: 1 branch
BranchTrueFalseTotal
if $element->line_number > $line_number 0 0 0
334 0 ▶ return 0 if $element->line_number + scalar($element->lines) < $line_number;
Branch: 1 branch
BranchTrueFalseTotal
if $element->line_number + scalar($element->lines) < $line_number 0 0 0
335 0 return 1;
336 }
337 0 );
338  
339 0 ▶ return unless (scalar $find->in($self->{document}));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $find->in($self->{"document"}) 0 0 0
340  
341 0 ▶ open my $fh, '<', $self->get_full_text() or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->get_full_text or return 0 0 0
342  
343 0 ▶ while (my $line = <$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
344 {
345 0 ▶ next unless $. == $line_number;
Branch: 1 branch
BranchTrueFalseTotal
unless $. == $line_number 0 0 0
346 0 chomp $line;
347  
348 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ / L< # starting L< (?: <+ # optional additional < \s+ # spaces required if any additional < )? (.+?) # the actual link content (?: \s+ # spaces required if any additional > +>+ # optional additional > )? > # final closing > /gx) 0 0 0
349 $line =~ m{
350 L< # starting L<
351 (?:
352 <+ # optional additional <
353 \s+ # spaces required if any additional <
354 )?
355 (.+?) # the actual link content
356 (?:
357 \s+ # spaces required if any additional >
358 +>+ # optional additional >
359 )?
360 > # final closing >
361 }gx
362 )
363 {
364 0 my $start = $-[1];
365 0 my $end = $+[1];
366 0 my $link = $1;
367  
368 0 ▶ next if ($start > $column_number or $column_number > $end);
Branch: 1 branch
BranchTrueFalseTotal
if $start > $column_number or $column_number > $end 0 0 0
Condition0%0/3
$start > $column_number or $column_number > $end
l!l&&r!l&&!r
000
MC/DC0%0/2
$start > $column_number or $column_number > $end
$start > $column_number $column_number > $end
Truth table0%0/3
A or B
A= $start > $column_numberB= $column_number > $end
ABresult
1X1
011
000
369  
370 # Get just the name - remove the text and section parts
371 0 $link =~ s/^[^<]*\|//;
372 0 $link =~ s/\/[^>]*$//;
373 0 return $link;
374 } ## end while ($line =~ m{ ) (})
375  
376 0 last;
377 } ## end while (my $line = <$fh>)
378  
379 0 return;
380 } ## end sub pod_link
381  
382 =head2 find_pod
383  
384 This attempts to find POD for the symbol at the given location.
385  
386 =cut
387  
388 sub find_pod
389 {
390 0 ▶ my ($self, $uri, $line_number, $column_number) = @_;
Subroutine find_pod: not called CC=18 SCAR=58.3
Pod documented
391  
392 0 my @elements = $self->find_elements_at_location($line_number, $column_number);
393  
394 0 foreach my $element (@elements)
395 {
396 0 my ($package, $subroutine, $variable, $import);
397  
398 0 ▶ if (($package, $import) = $element->package_name($column_number))
Branch: 1 branch
BranchTrueFalseTotal
if (($package, $import) = $element->package_name($column_number)) 0 0 0
399 {
400 0 my %args = (index => $self->{index}, element => $element, package => $package);
401 0 my $class_name = 'PLS::Parser::Pod::Package';
402  
403 0 ▶ if (length $import)
Branch: 1 branch
BranchTrueFalseTotal
if (length $import) 0 0 0
404 {
405 0 ▶ if ($import =~ /^[\$\@\%]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($import =~ /^[\$\@\%]/) { } 0 0 0
406 {
407 0 $args{variable} = $import;
408 0 $class_name = 'PLS::Parser::Pod::Variable';
409 }
410 else
411 {
412 0 $args{subroutine} = $import;
413 0 $args{packages} = [$package];
414 0 delete $args{package};
415 0 $class_name = 'PLS::Parser::Pod::Subroutine';
416 } ## end else [ if ($import =~ /^[\$\@\%]/...)]
417 } ## end if (length $import)
418  
419 0 my $pod = $class_name->new(%args);
420 0 my $ok = $pod->find();
421 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
422 } ## end if (($package, $import...))
423 0 ▶ if (($package, $subroutine) = $element->class_method_package_and_name())
Branch: 1 branch
BranchTrueFalseTotal
if (() = $element->class_method_package_and_name) 0 0 0
424 {
425 my $pod =
426 PLS::Parser::Pod::ClassMethod->new(
427 index => $self->{index},
428 0 element => $element,
429 packages => [$package],
430 subroutine => $subroutine
431 );
432 0 my $ok = $pod->find();
433 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
434 } ## end if (($package, $subroutine...))
435 0 ▶ if ($subroutine = $element->method_name())
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine = $element->method_name) 0 0 0
436 {
437 my $pod =
438 PLS::Parser::Pod::Method->new(
439 index => $self->{index},
440 0 element => $element,
441 subroutine => $subroutine
442 );
443 0 my $ok = $pod->find();
444 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
445 } ## end if ($subroutine = $element...)
446 0 ▶ if (($package, $subroutine) = $element->subroutine_package_and_name())
Branch: 1 branch
BranchTrueFalseTotal
if (() = $element->subroutine_package_and_name) 0 0 0
447 {
448 0 ▶ my @packages = length $package ? ($package) : ();
Branch: 1 branch
BranchTrueFalseTotal
length $package ? : 0 0 0
449  
450 my $pod =
451 PLS::Parser::Pod::Subroutine->new(
452 uri => $uri,
453 index => $self->{index},
454 0 element => $element,
455 packages => \@packages,
456 subroutine => $subroutine,
457 include_builtins => 1
458 );
459 0 my $ok = $pod->find();
460 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
461 } ## end if (($package, $subroutine...))
462 0 ▶ if ($variable = $element->variable_name())
Branch: 1 branch
BranchTrueFalseTotal
if ($variable = $element->variable_name) 0 0 0
463 {
464 my $pod =
465 PLS::Parser::Pod::Variable->new(
466 index => $self->{index},
467 0 element => $element,
468 variable => $variable
469 );
470 0 my $ok = $pod->find();
471 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
472 } ## end if ($variable = $element...)
473 0 ▶ if ($element->type eq 'PPI::Token::Operator' and $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($element->type eq "PPI::Token::Operator" and $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/) 0 0 0
Condition0%0/3
$element->type eq "PPI::Token::Operator" and $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$element->type eq "PPI::Token::Operator" and $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/
$element->type eq "PPI::Token::Operator" $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/
Truth table0%0/3
A and B
A= $element->type eq "PPI::Token::Operator"B= $element->content =~ /^-[rwxoRWXOezsfdlpSbctugkTBMAC]$/
ABresult
0X0
100
111
474 {
475 my $pod = PLS::Parser::Pod::Subroutine->new(
476 index => $self->{index},
477 0 element => $element,
478 subroutine => '-X',
479 include_builtins => 1
480 );
481 0 my $ok = $pod->find();
482 0 ▶ return (1, $pod) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
483 } ## end if ($element->type eq ...)
484 } ## end foreach my $element (@elements...)
485  
486 0 return 0;
487 } ## end sub find_pod
488  
489 sub find_elements_at_location
490 {
491 27 ▶ my ($self, $line_number, $column_number) = @_;
Subroutine find_elements_at_location: called CC=2 SCAR=6.9
Pod undocumented
492  
493 27 ($line_number, $column_number) = _ppi_location($line_number, $column_number);
494 27 ▶ $line_number = 1 if $self->{one_line};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"one_line"} 27 0 27
495  
496 my $find = PPI::Find->new(
497 sub {
498 137 ▶ my ($element) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
499  
500 137 ▶ return 0 unless $element->line_number == $line_number;
Branch: 1 branch
BranchTrueFalseTotal
unless $element->line_number == $line_number 0 137 137
501 137 ▶ return 0 if $element->column_number > $column_number;
Branch: 1 branch
BranchTrueFalseTotal
if $element->column_number > $column_number 4 133 137
502 133 ▶ return 0 if $element->column_number + (length $element->content) < $column_number;
Branch: 1 branch
BranchTrueFalseTotal
if $element->column_number + length($element->content) < $column_number 32 101 133
503 101 return 1;
504 }
505 27 );
506  
507 27 my @matches = $find->in($self->{document});
508 @matches =
509 27 sort { (abs $column_number - $a->column_number) <=> (abs $column_number - $b->column_number) } @matches;
510 27 @matches = map { PLS::Parser::Element->new(document => $self->{document}, element => $_, file => $self->{path}) } @matches;
511 27 return @matches;
512 } ## end sub find_elements_at_location
513  
514 =head2 find_external_subroutine
515  
516 This attempts to find the location of a subroutine inside an external module,
517 by name.
518  
519 =cut
520  
521 sub find_external_subroutine
522 {
523 0 ▶ my ($self, $package_name, $subroutine_name) = @_;
Subroutine find_external_subroutine: not called CC=5 SCAR=34.0
Pod documented
524  
525 0 my $include = PLS::Parser::Pod->get_clean_inc();
526 0 my $package = Module::Metadata->new_from_module($package_name, inc => $include);
527 0 ▶ return if (ref $package ne 'Module::Metadata');
Branch: 1 branch
BranchTrueFalseTotal
if ref $package ne "Module::Metadata" 0 0 0
528  
529 0 my $doc = PLS::Parser::Document->new(path => $package->filename);
530 0 ▶ return if (ref $doc ne 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
if ref $doc ne "PLS::Parser::Document" 0 0 0
531  
532 0 foreach my $subroutine (@{$doc->get_subroutines()})
533 {
534 0 ▶ next unless ($subroutine->name eq $subroutine_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $subroutine->name eq $subroutine_name 0 0 0
535  
536 return {
537 uri => URI::file->new($package->filename)->as_string,
538 range => $subroutine->range(),
539 signature => $subroutine->location_info->{signature}
540 0 };
541 } ## end foreach my $subroutine (@{$doc...})
542  
543 0 return;
544 } ## end sub find_external_subroutine
545  
546 =head2 find_external_package
547  
548 This attempts to find the location of an external package by name.
549  
550 =cut
551  
552 sub find_external_package
553 {
554 0 ▶ my ($self, $package_name) = @_;
Subroutine find_external_package: not called CC=6 SCAR=37.4
Pod documented
555  
556 0 ▶ return unless (length $package_name);
Branch: 1 branch
BranchTrueFalseTotal
unless length $package_name 0 0 0
557  
558 0 my $include = PLS::Parser::Pod->get_clean_inc();
559 0 my $metadata = Module::Metadata->new_from_module($package_name, inc => $include);
560  
561 0 ▶ return if (ref $metadata ne 'Module::Metadata');
Branch: 1 branch
BranchTrueFalseTotal
if ref $metadata ne "Module::Metadata" 0 0 0
562  
563 0 my $document = PLS::Parser::Document->new(path => $metadata->filename);
564 0 ▶ return if (ref $document ne 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
if ref $document ne "PLS::Parser::Document" 0 0 0
565  
566 0 foreach my $package (@{$document->get_packages()})
567 {
568 0 ▶ next unless ($package->name eq $package_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $package->name eq $package_name 0 0 0
569  
570 return {
571 0 uri => URI::file->new($metadata->filename)->as_string,
572 range => $package->range()
573 };
574 } ## end foreach my $package (@{$document...})
575  
576 0 return;
577 } ## end sub find_external_package
578  
579 =head2 go_to_variable_definition
580  
581 This finds the definition of a variable.
582  
583 This B<probably> only works correctly for C<my>, C<local>, and C<state> variables,
584 but may also work for C<our> variables as long as they are in the same file.
585  
586 =cut
587  
588 sub go_to_variable_definition
589 {
590 0 ▶ my ($self, $variable, $element, $line_number, $column_number) = @_;
Subroutine go_to_variable_definition: not called CC=34 SCAR=70.8
Pod documented
591  
592 0 my $cursor = $element->element;
593 0 my $prev_cursor;
594 0 my $document = $cursor->top;
595  
596 0 my $declaration;
597 0 state $var_rx = qr/((?&PerlVariable))$PPR::GRAMMAR/;
598  
599 0 OUTER: while (1)
600 {
601 0 $prev_cursor = $cursor;
602 0 $cursor = $cursor->parent;
603  
604 0 ▶ next unless blessed($cursor);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($cursor) 0 0 0
605  
606 0 ▶ if ($cursor->isa('PPI::Structure::Block') or $cursor->isa('PPI::Document'))
Branch: 2 branches
BranchTrueFalseTotal
if ($cursor->isa('PPI::Structure::Block') or $cursor->isa('PPI::Document')) { } 0 0 0
elsif ($cursor->isa('PPI::Statement::Compound')) { } 0 0 0
Condition0%0/3
$cursor->isa("PPI::Structure::Block") or $cursor->isa("PPI::Document")
l!l&&r!l&&!r
000
MC/DC0%0/2
$cursor->isa("PPI::Structure::Block") or $cursor->isa("PPI::Document")
$cursor->isa("PPI::Structure::Block") $cursor->isa("PPI::Document")
Truth table0%0/3
A or B
A= $cursor->isa("PPI::Structure::Block")B= $cursor->isa("PPI::Document")
ABresult
1X1
011
000
607 {
608 0 CHILDREN: foreach my $child ($cursor->children)
609 {
610 0 ▶ last CHILDREN if $child == $prev_cursor;
Branch: 1 branch
BranchTrueFalseTotal
if $child == $prev_cursor 0 0 0
611 0 ▶ next unless blessed($child);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($child) 0 0 0
612  
613 0 ▶ if ($child->isa('PPI::Statement::Variable') and any { $_ eq $variable } $child->variables)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa("PPI::Statement::Variable") and &any(sub { $_ eq $variable; } , $child->variables)) 0 0 0
Condition0%0/3
$child->isa("PPI::Statement::Variable") and &any(sub {
!ll&&!rl&&r
000
MC/DC0%0/2
$child->isa("PPI::Statement::Variable") and &any(sub { $_ eq $variable; } , $child->variables)
$child->isa("PPI::Statement::Variable") &any(sub { $_ eq $variable; } , $child->variables)
Truth table0%0/3
A and B
A= $child->isa("PPI::Statement::Variable")B= &any(sub { $_ eq $variable; } , $child->variables)
ABresult
0X0
100
111
614 {
615 0 $declaration = $child;
616 0 last OUTER;
617 }
618 0 ▶ if ($child->isa('PPI::Statement::Include') and $child->type eq 'use' and $child->pragma eq 'vars')
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa("PPI::Statement::Include") and $child->type eq "use" and $child->pragma eq "vars") 0 0 0
Condition0%0/6
$child->isa("PPI::Statement::Include") and $child->type eq "use" and $child->pragma eq "vars"
!ll&&!rl&&r
000
$child->isa("PPI::Statement::Include") and $child->type eq "use"
!ll&&!rl&&r
000
MC/DC0%0/3
$child->isa("PPI::Statement::Include") and $child->type eq "use" and $child->pragma eq "vars"
$child->isa("PPI::Statement::Include") $child->type eq "use" $child->pragma eq "vars"
Truth table0%0/4
A and B and C
A= $child->isa("PPI::Statement::Include")B= $child->type eq "use"C= $child->pragma eq "vars"
ABCresult
0XX0
10X0
1100
1111
619 {
620 0 ▶ while ($child =~ /$var_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($child =~ /$var_rx/g) 0 0 0
621 {
622 0 ▶ next if ($1 ne $variable);
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne $variable 0 0 0
623 0 $declaration = $child;
624 0 last OUTER;
625 } ## end while ($child =~ /$var_rx/g...)
626 } ## end if ($child->isa('PPI::Statement::Include'...))
627 } ## end foreach my $child ($cursor->...)
628 } ## end if ($cursor->isa('PPI::Structure::Block'...))
629 elsif ($cursor->isa('PPI::Statement::Compound'))
630 {
631 0 ▶ if ($cursor->type eq 'foreach')
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor->type eq 'foreach') { } 0 0 0
632 {
633 0 CHILDREN: foreach my $child ($cursor->children)
634 {
635 0 ▶ last CHILDREN if $child == $prev_cursor;
Branch: 1 branch
BranchTrueFalseTotal
if $child == $prev_cursor 0 0 0
636 0 ▶ next unless blessed($child);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($child) 0 0 0
637  
638 0 ▶ if ($child->isa('PPI::Token::Word') and $child =~ /^my|our|local|state$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa("PPI::Token::Word") and $child =~ /^my|our|local|state$/) 0 0 0
Condition0%0/3
$child->isa("PPI::Token::Word") and $child =~ /^my|our|local|state$/
!ll&&!rl&&r
000
MC/DC0%0/2
$child->isa("PPI::Token::Word") and $child =~ /^my|our|local|state$/
$child->isa("PPI::Token::Word") $child =~ /^my|our|local|state$/
Truth table0%0/3
A and B
A= $child->isa("PPI::Token::Word")B= $child =~ /^my|our|local|state$/
ABresult
0X0
100
111
639 {
640 0 ▶ if (blessed($child->snext_sibling) and $child->snext_sibling->isa('PPI::Token::Symbol') and $child->snext_sibling->symbol eq $variable)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($child->snext_sibling) and $child->snext_sibling->isa("PPI::Token::Symbol") and $child->snext_sibling->symbol eq $variable) 0 0 0
Condition0%0/6
builtin::blessed($child->snext_sibling) and $child->snext_sibling->isa("PPI::Token::Symbol") and $child->snext_sibling->symbol eq $variable
!ll&&!rl&&r
000
builtin::blessed($child->snext_sibling) and $child->snext_sibling->isa("PPI::Token::Symbol")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($child->snext_sibling) and $child->snext_sibling->isa("PPI::Token::Symbol") and $child->snext_sibling->symbol eq $variable
builtin::blessed($child->snext_sibling) $child->snext_sibling->isa("PPI::Token::Symbol") $child->snext_sibling->symbol eq $variable
Truth table0%0/4
A and B and C
A= builtin::blessed($child->snext_sibling)B= $child->snext_sibling->isa("PPI::Token::Symbol")C= $child->snext_sibling->symbol eq $variable
ABCresult
0XX0
10X0
1100
1111
641 {
642 #$declaration = $child->snext_sibling;
643 0 $declaration = $cursor;
644 0 last OUTER;
645 } ## end if (blessed($child->snext_sibling...))
646 } ## end if ($child->isa('PPI::Token::Word'...))
647 } ## end foreach my $child ($cursor->...)
648 } ## end if ($cursor->type eq 'foreach'...)
649 else
650 {
651 0 ▶ my $condition = first { $_->isa('PPI::Structure::Condition') } grep { blessed($_) } $cursor->children;
Subroutine __ANON__: not called CC=1 SCAR=6.9
652 0 ▶ next OUTER if (not blessed($condition) or not $condition->isa('PPI::Structure::Condition'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($condition) and $condition->isa("PPI::Structure::Condition") 0 0 0
Condition0%0/3
builtin::blessed($condition) and $condition->isa("PPI::Structure::Condition")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($condition) and $condition->isa("PPI::Structure::Condition")
builtin::blessed($condition) $condition->isa("PPI::Structure::Condition")
Truth table0%0/3
A and B
A= builtin::blessed($condition)B= $condition->isa("PPI::Structure::Condition")
ABresult
0X0
100
111
653  
654 0 CHILDREN: foreach my $child ($condition->children)
655 {
656 0 ▶ last CHILDREN if $child == $prev_cursor;
Branch: 1 branch
BranchTrueFalseTotal
if $child == $prev_cursor 0 0 0
657 0 ▶ next unless blessed($child);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($child) 0 0 0
658  
659 0 ▶ if ($child->isa('PPI::Statement::Variable') and any { $_ eq $variable } $child->variables)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa("PPI::Statement::Variable") and &any(sub { $_ eq $variable; } , $child->variables)) 0 0 0
Condition0%0/3
$child->isa("PPI::Statement::Variable") and &any(sub {
!ll&&!rl&&r
000
MC/DC0%0/2
$child->isa("PPI::Statement::Variable") and &any(sub { $_ eq $variable; } , $child->variables)
$child->isa("PPI::Statement::Variable") &any(sub { $_ eq $variable; } , $child->variables)
Truth table0%0/3
A and B
A= $child->isa("PPI::Statement::Variable")B= &any(sub { $_ eq $variable; } , $child->variables)
ABresult
0X0
100
111
660 {
661 0 $declaration = $child;
662 0 last OUTER;
663 }
664 } ## end foreach my $child ($condition...)
665 } ## end else [ if ($cursor->type eq 'foreach'...)]
666 } ## end elsif ($cursor->isa('PPI::Statement::Compound'...))
667  
668 0 ▶ last if $cursor == $document;
Branch: 1 branch
BranchTrueFalseTotal
if $cursor == $document 0 0 0
669 } ## end while (1)
670  
671 0 ▶ return if (not blessed($declaration) or not $declaration->isa('PPI::Element'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($declaration) and $declaration->isa("PPI::Element") 0 0 0
Condition0%0/3
builtin::blessed($declaration) and $declaration->isa("PPI::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($declaration) and $declaration->isa("PPI::Element")
builtin::blessed($declaration) $declaration->isa("PPI::Element")
Truth table0%0/3
A and B
A= builtin::blessed($declaration)B= $declaration->isa("PPI::Element")
ABresult
0X0
100
111
672  
673 0 $element = PLS::Parser::Element->new(file => $self->{path}, document => $self->{document}, element => $declaration);
674  
675 return [
676 {
677 uri => $self->{uri},
678 0 range => $element->range()
679 }
680 ];
681 } ## end sub go_to_variable_definition
682  
683 =head2 open_file
684  
685 This adds a file and its text to a list of open files.
686  
687 =cut
688  
689 sub open_file
690 {
691 1 ▶ my ($class, %args) = @_;
Subroutine open_file: called CC=2 SCAR=7.0
Pod documented
692  
693 1 ▶ return unless $args{languageId} eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"languageId"} eq "perl" 0 1 1
694  
695 1 $FILES{$args{uri}} = \($args{text});
696 1 $VERSIONS{$args{uri}} = $args{version};
697  
698 1 return;
699 } ## end sub open_file
700  
701 =head2 open_files
702  
703 This provides a list of names of files that are currently open.
704  
705 =cut
706  
707 sub open_files
708 {
709 8 ▶ return [keys %FILES];
Subroutine open_files: called CC=1 SCAR=0.0
Pod documented
710 }
711  
712 =head2 update_file
713  
714 This patches an open file in memory to keep it synched with
715 the actual file in the editor.
716  
717 =cut
718  
719 sub update_file
720 {
721 0 ▶ my ($class, @args) = @_;
Subroutine update_file: not called CC=10 SCAR=47.0
Pod documented
722  
723 0 my %args = @args;
724  
725 0 my $file = $FILES{$args{uri}};
726 0 ▶ return if (ref $file ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $file ne "SCALAR" 0 0 0
727  
728 0 $VERSIONS{$args{uri}} = $args{version};
729  
730 0 foreach my $change (@{$args{changes}})
731 {
732 0 ▶ if (ref $change->{range} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $change->{'range'} eq 'HASH') { } 0 0 0
733 {
734 0 my @lines = _split_lines($$file);
735 0 my @replacement = _split_lines($change->{text});
736  
737 0 my ($starting_text, $ending_text);
738  
739 # get the text that we're not replacing at the start and end of each selection
740 # this needs to be done in UTF-16 according to the LSP specification.
741 # the byte order doesn't matter because we're decoding immediately,
742 # so we are using little endian.
743  
744 0 ▶ if ($#lines >= $change->{range}{start}{line})
Branch: 1 branch
BranchTrueFalseTotal
if ($#lines >= $change->{"range"}{"start"}{"line"}) 0 0 0
745 {
746 0 my $first_line = Encode::encode('UTF-16LE', $lines[$change->{range}{start}{line}]);
747  
748 # each code unit is two bytes long
749 0 my $starting_code_unit = $change->{range}{start}{character} * 2;
750 0 $starting_text = substr $first_line, 0, $starting_code_unit;
751 0 $starting_text = Encode::decode('UTF-16LE', $starting_text);
752 } ## end if ($#lines >= $change...)
753  
754 0 ▶ if ($#lines >= $change->{range}{end}{line})
Branch: 1 branch
BranchTrueFalseTotal
if ($#lines >= $change->{"range"}{"end"}{"line"}) 0 0 0
755 {
756 0 my $last_line = Encode::encode('UTF-16LE', $lines[$change->{range}{end}{line}]);
757  
758 # each code unit is two bytes long
759 0 my $ending_code_unit = $change->{range}{end}{character} * 2;
760 0 $ending_text = substr $last_line, $ending_code_unit;
761 0 $ending_text = Encode::decode('UTF-16LE', $ending_text);
762 } ## end if ($#lines >= $change...)
763  
764 # append the existing text to the replacement
765 0 ▶ if (length $starting_text)
Branch: 1 branch
BranchTrueFalseTotal
if (length $starting_text) 0 0 0
766 {
767 0 ▶ $replacement[0] = length $replacement[0] ? $starting_text . $replacement[0] : $starting_text;
Branch: 1 branch
BranchTrueFalseTotal
length $replacement[0] ? : 0 0 0
768 }
769 0 ▶ if (length $ending_text)
Branch: 1 branch
BranchTrueFalseTotal
if (length $ending_text) 0 0 0
770 {
771 0 ▶ if (scalar @replacement)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @replacement) { } 0 0 0
772 {
773 0 $replacement[-1] .= $ending_text;
774 }
775 else
776 {
777 0 $replacement[0] = $ending_text;
778 }
779 } ## end if (length $ending_text...)
780  
781 # replace the lines in the range (which may not match the number of lines in the replacement)
782 # with the replacement, including the existing text that is not changing, that we appended above
783 0 my $lines_replacing = $change->{range}{end}{line} - $change->{range}{start}{line} + 1;
784 0 splice @lines, $change->{range}{start}{line}, $lines_replacing, @replacement;
785 0 $$file = join '', @lines;
786 } ## end if (ref $change->{range...})
787 else
788 {
789 # no range means we're updating the entire document
790 0 $$file = $change->{text};
791 }
792 } ## end foreach my $change (@{$args...})
793  
794 0 return;
795 } ## end sub update_file
796  
797 =head2 close_file
798  
799 This removes a file from the list of open files.
800  
801 =cut
802  
803 sub close_file
804 {
805 0 ▶ my ($class, @args) = @_;
Subroutine close_file: not called CC=1 SCAR=6.9
Pod documented
806  
807 0 my %args = @args;
808  
809 0 delete $FILES{$args{uri}};
810 0 delete $VERSIONS{$args{uri}};
811  
812 0 return;
813 } ## end sub close_file
814  
815 =head2 get_subroutines
816  
817 This gets a list of all subroutines in a document.
818  
819 =cut
820  
821 sub get_subroutines
822 {
823 0 ▶ my ($self) = @_;
Subroutine get_subroutines: not called CC=1 SCAR=6.9
Pod documented
824  
825 my $find = PPI::Find->new(
826 sub {
827 0 ▶ $_[0]->isa('PPI::Statement::Sub') and not $_[0]->isa('PPI::Statement::Scheduled') and ref $_[0]->block eq 'PPI::Structure::Block';
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("PPI::Statement::Sub") and not $_[0]->isa("PPI::Statement::Scheduled") and ref $_[0]->block eq "PPI::Structure::Block" 0 0 0
Condition0%0/3
$_[0]->isa("PPI::Statement::Sub") and not $_[0]->isa("PPI::Statement::Scheduled")
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]->isa("PPI::Statement::Sub") and not $_[0]->isa("PPI::Statement::Scheduled")
$_[0]->isa("PPI::Statement::Sub") not $_[0]->isa("PPI::Statement::Scheduled")
Truth table0%0/3
A and not(B)
A= $_[0]->isa("PPI::Statement::Sub")B= not $_[0]->isa("PPI::Statement::Scheduled")
ABresult
0X0
100
111
828 }
829 0 );
830 0 return [map { PLS::Parser::Element::Subroutine->new(document => $self->{document}, element => $_, file => $self->{path}) } $find->in($self->{document})];
831 } ## end sub get_subroutines
832  
833 =head2 get_constants
834  
835 This gets a list of all constants in a document.
836  
837 Only constants declared with C<use constant> are found.
838  
839 =cut
840  
841 sub get_constants
842 {
843 0 ▶ my ($self, $element) = @_;
Subroutine get_constants: not called CC=4 SCAR=30.0
Pod documented
844  
845 0 my @matches;
846  
847 0 ▶ if (ref $element eq 'PPI::Statement::Include')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $element eq 'PPI::Statement::Include') { } 0 0 0
848 {
849 0 @matches = ($element);
850 }
851 else
852 {
853 my $find = PPI::Find->new(
854 sub {
855 0 ▶ my ($element) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
856  
857 0 ▶ return 0 unless $element->isa('PPI::Statement::Include');
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("PPI::Statement::Include") 0 0 0
858 0 ▶ return unless $element->type eq 'use';
Branch: 1 branch
BranchTrueFalseTotal
unless $element->type eq "use" 0 0 0
859 0 ▶ return (length $element->module and $element->module eq 'constant');
Condition0%0/3
length $element->module && $element->module eq 'constant'
!ll&&!rl&&r
000
MC/DC0%0/2
length $element->module && $element->module eq 'constant'
length $element->module $element->module eq 'constant'
Truth table0%0/3
A && B
A= length $element->moduleB= $element->module eq 'constant'
ABresult
0X0
100
111
860 }
861 0 );
862  
863 0 @matches = $find->in($self->{document});
864 } ## end else [ if (ref $element eq 'PPI::Statement::Include'...)]
865  
866 0 my @constants;
867  
868 0 foreach my $match (@matches)
869 {
870 0 my ($constructor) = grep { $_->isa('PPI::Structure::Constructor') } $match->children;
871  
872 0 ▶ if (ref $constructor eq 'PPI::Structure::Constructor')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $constructor eq 'PPI::Structure::Constructor') { } 0 0 0
873 {
874 0 push @constants, grep { _is_constant($_) }
875 0 map { $_->children }
876 0 grep { $_->isa('PPI::Statement::Expression') } $constructor->children;
877 } ## end if (ref $constructor eq...)
878 else
879 {
880 0 push @constants, grep { _is_constant($_) } $match->children;
881 }
882 } ## end foreach my $match (@matches...)
883  
884 0 return [map { PLS::Parser::Element::Constant->new(document => $self->{document}, element => $_, file => $self->{path}) } @constants];
885 } ## end sub get_constants
886  
887 =head2 get_packages
888  
889 This gets a list of all packages in a document.
890  
891 =cut
892  
893 sub get_packages
894 {
895 0 ▶ my ($self) = @_;
Subroutine get_packages: not called CC=1 SCAR=6.9
Pod documented
896  
897 0 ▶ my $find = PPI::Find->new(sub { $_[0]->isa('PPI::Statement::Package') });
Subroutine __ANON__: not called CC=1 SCAR=6.9
898 0 return [map { PLS::Parser::Element::Package->new(document => $self->{document}, element => $_, file => $self->{path}) } $find->in($self->{document})];
899 } ## end sub get_packages
900  
901 =head2 get_variable_statements
902  
903 This gets a list of all variable statements in a document.
904 A variable statement is a statement which declares one or more variables.
905  
906 =cut
907  
908 sub get_variable_statements
909 {
910 0 ▶ my ($self, $element) = @_;
Subroutine get_variable_statements: not called CC=3 SCAR=24.8
Pod documented
911  
912 0 my @elements;
913  
914 0 ▶ if (blessed($element) and $element->isa('PPI::Statement::Variable'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element) and $element->isa('PPI::Statement::Variable')) { } 0 0 0
Condition0%0/3
builtin::blessed($element) and $element->isa("PPI::Statement::Variable")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($element) and $element->isa("PPI::Statement::Variable")
builtin::blessed($element) $element->isa("PPI::Statement::Variable")
Truth table0%0/3
A and B
A= builtin::blessed($element)B= $element->isa("PPI::Statement::Variable")
ABresult
0X0
100
111
915 {
916 0 @elements = ($element);
917 }
918 else
919 {
920 0 ▶ my $find = PPI::Find->new(sub { $_[0]->isa('PPI::Statement::Variable') });
Subroutine __ANON__: not called CC=1 SCAR=6.9
921 0 @elements = $find->in($self->{document});
922 }
923  
924 0 return [map { PLS::Parser::Element::VariableStatement->new(document => $self->{document}, element => $_, file => $self->{path}) } @elements];
925 } ## end sub get_variable_statements
926  
927 =head2 get_full_text
928  
929 This returns a SCALAR reference of the in-memory text of the current document.
930  
931 =cut
932  
933 sub get_full_text
934 {
935 0 ▶ my ($self) = @_;
Subroutine get_full_text: not called CC=1 SCAR=6.9
Pod documented
936  
937 0 return $self->text_from_uri($self->{uri});
938 }
939  
940 =head2 get_variables_fast
941  
942 This gets a list of all variables in the current document.
943 It uses L<PPR> to do so, which is faster than L<PPI>, but only provides a list of strings.
944  
945 =cut
946  
947 sub get_variables_fast
948 {
949 0 ▶ my ($self, $text) = @_;
Subroutine get_variables_fast: not called CC=7 SCAR=40.3
Pod documented
950  
951 0 ▶ $text = $self->get_full_text() if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
952 0 ▶ return [] if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
953  
954 0 state $variable_decl_rx = qr/((?&PerlVariableDeclaration))$PPR::GRAMMAR/;
955 0 state $lvalue_rx = qr/((?&PerlLvalue))$PPR::GRAMMAR/;
956 0 state $variable_rx = qr/((?&PerlVariable))$PPR::GRAMMAR/;
957 0 my @variables;
958  
959 0 ▶ while ($$text =~ /$variable_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$variable_rx/g) 0 0 0
960 {
961 0 my $declaration = $1;
962 0 my ($lvalue) = $declaration =~ /$lvalue_rx/;
963  
964 0 ▶ next unless (length $lvalue);
Branch: 1 branch
BranchTrueFalseTotal
unless length $lvalue 0 0 0
965  
966 0 ▶ while ($lvalue =~ /$variable_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($lvalue =~ /$variable_rx/g) 0 0 0
967 {
968 0 my $variable = $1;
969 0 ▶ next unless (length $variable);
Branch: 1 branch
BranchTrueFalseTotal
unless length $variable 0 0 0
970 0 $variable =~ s/^\s+|\s+$//g;
971  
972 0 push @variables, $variable;
973 } ## end while ($lvalue =~ /$variable_rx/g...)
974 } ## end while ($$text =~ /$variable_rx/g...)
975  
976 0 return \@variables;
977 } ## end sub get_variables_fast
978  
979 =head2 get_packages_fast
980  
981 This gets a list of all packages in the current document.
982 It uses L<PPR> to do so, which is faster than L<PPI>, but only provides a list of strings.
983  
984 =cut
985  
986 sub get_packages_fast
987 {
988 0 ▶ my ($self, $text) = @_;
Subroutine get_packages_fast: not called CC=5 SCAR=34.0
Pod documented
989  
990 0 ▶ $text = $self->get_full_text() if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
991 0 ▶ return [] if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
992  
993 0 state $package_rx = qr/((?&PerlPackageDeclaration))$PPR::GRAMMAR/;
994 0 my @packages;
995  
996 0 ▶ while ($$text =~ /$package_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$package_rx/g) 0 0 0
997 {
998 0 my ($package) = $1 =~ /^package\s+(\S+)\s*;\s*$/;
999 0 ▶ next unless (length $package);
Branch: 1 branch
BranchTrueFalseTotal
unless length $package 0 0 0
1000  
1001 0 push @packages, $package;
1002 } ## end while ($$text =~ /$package_rx/g...)
1003  
1004 0 return \@packages;
1005 } ## end sub get_packages_fast
1006  
1007 =head2 get_subroutines_fast
1008  
1009 This gets a list of all subroutines in the current document.
1010 It uses L<PPR> to do so, which is faster than L<PPI>, but only provides a list of strings.
1011  
1012 =cut
1013  
1014 sub get_subroutines_fast
1015 {
1016 0 ▶ my ($self, $text) = @_;
Subroutine get_subroutines_fast: not called CC=4 SCAR=30.0
Pod documented
1017  
1018 0 ▶ $text = $self->get_full_text() if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1019 0 ▶ return [] if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1020  
1021 0 state $sub_rx = qr/sub\b(?&PerlOWS)((?&PerlOldQualifiedIdentifier))$PPR::GRAMMAR/;
1022 0 my @subroutine_declarations;
1023  
1024 0 ▶ while ($$text =~ /$sub_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$sub_rx/g) 0 0 0
1025 {
1026 0 push @subroutine_declarations, $1;
1027 }
1028  
1029 return [
1030 0 map { s/^\s+|\s+$//r }
1031 0 grep { defined } @subroutine_declarations
1032 ];
1033 } ## end sub get_subroutines_fast
1034  
1035 =head2 get_constants_fast
1036  
1037 This gets a list of all constants in the current document.
1038 It uses L<PPR> to do so, which is faster than L<PPI>, but only provides a list of strings.
1039  
1040 This only finds constants declared with C<use constant>.
1041  
1042 =cut
1043  
1044 sub get_constants_fast
1045 {
1046 0 ▶ my ($self, $text) = @_;
Subroutine get_constants_fast: not called CC=8 SCAR=42.8
Pod documented
1047  
1048 0 ▶ $text = $self->get_full_text() if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1049 0 ▶ return [] if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1050  
1051 0 state $block_rx = qr/use\h+constant(?&PerlOWS)((?&PerlBlock))$PPR::GRAMMAR/;
1052 0 state $bareword_rx = qr/((?&PerlBareword))(?&PerlOWS)(?&PerlComma)$PPR::GRAMMAR/;
1053 0 state $one_constant_rx = qr/use\h+constant\h+((?&PerlBareword))(?&PerlOWS)(?&PerlComma)$PPR::GRAMMAR/;
1054 0 my @constants;
1055  
1056 0 ▶ while ($$text =~ /$block_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$block_rx/g) 0 0 0
1057 {
1058 0 my $block = $1;
1059  
1060 0 ▶ while ($block =~ /$bareword_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($block =~ /$bareword_rx/g) 0 0 0
1061 {
1062 0 my $constant = $1;
1063  
1064 0 ▶ next unless (length $constant);
Branch: 1 branch
BranchTrueFalseTotal
unless length $constant 0 0 0
1065 0 $constant =~ s/^\s+|\s+$//g;
1066  
1067 0 push @constants, $constant;
1068 } ## end while ($block =~ /$bareword_rx/g...)
1069 } ## end while ($$text =~ /$block_rx/g...)
1070  
1071 0 ▶ while ($$text =~ /$one_constant_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$one_constant_rx/g) 0 0 0
1072 {
1073 0 my $constant = $1;
1074 0 ▶ next unless (length $constant);
Branch: 1 branch
BranchTrueFalseTotal
unless length $constant 0 0 0
1075 0 $constant =~ s/^\s+|\s+$//g;
1076  
1077 0 push @constants, $constant;
1078 } ## end while ($$text =~ /$one_constant_rx/g...)
1079  
1080 0 return \@constants;
1081 } ## end sub get_constants_fast
1082  
1083 sub get_imports
1084 {
1085 0 ▶ my ($self, $text) = @_;
Subroutine get_imports: not called CC=6 SCAR=37.4
Pod undocumented
1086  
1087 0 ▶ $text = $self->get_full_text() if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1088 0 ▶ return [] if (ref $text ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $text ne "SCALAR" 0 0 0
1089  
1090 0 state $use_rx = qr/((?&PerlUseStatement))$PPR::GRAMMAR/;
1091 0 state $identifier_rx = qr/use\h+((?&PerlQualifiedIdentifier))(?&PerlOWS)(?&PerlList)?$PPR::GRAMMAR/;
1092  
1093 0 my @imports;
1094  
1095 0 ▶ while ($$text =~ /$use_rx/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($$text =~ /$use_rx/g) 0 0 0
1096 {
1097 0 my $use = $1;
1098  
1099 0 ▶ if ($use =~ /$identifier_rx/)
Branch: 1 branch
BranchTrueFalseTotal
if ($use =~ /$identifier_rx/) 0 0 0
1100 {
1101 0 my $module = $1;
1102  
1103 # Assume lowercase modules are pragmas.
1104 0 ▶ next if (lc $module eq $module);
Branch: 1 branch
BranchTrueFalseTotal
if lc $module eq $module 0 0 0
1105  
1106 0 push @imports, {use => $use, module => $module};
1107 } ## end if ($use =~ /$identifier_rx/...)
1108 } ## end while ($$text =~ /$use_rx/g...)
1109  
1110 0 return \@imports;
1111 } ## end sub get_imports
1112  
1113 =head2 format_range
1114  
1115 This formats a range of text in the document using perltidy.
1116  
1117 =cut
1118  
1119 sub format_range
1120 {
1121 0 ▶ my ($class, %args) = @_;
Subroutine format_range: not called CC=18 SCAR=58.3
Pod documented
1122  
1123 0 ▶ $args{formatting_options} = {} unless (ref $args{formatting_options} eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"formatting_options"} eq "HASH" 0 0 0
1124 0 my $range = $args{range};
1125 0 my $text = $args{text};
1126  
1127 0 ▶ if (ref $text ne 'SCALAR')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $text ne "SCALAR") 0 0 0
1128 {
1129 0 return (0, {code => -32700, message => 'Could not get document text.'});
1130 }
1131  
1132 0 my $selection = '';
1133 0 my $whole_file = 0;
1134  
1135 0 ▶ if (ref $range eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $range eq 'HASH') { } 0 0 0
1136 {
1137 # if we've selected up until the first character of the next line,
1138 # just format up to the line before that
1139 0 ▶ $range->{end}{line}-- if ($range->{end}{character} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $range->{"end"}{"character"} == 0 0 0 0
1140  
1141 0 my @lines = _split_lines($$text);
1142 0 @lines = @lines[$range->{start}{line} .. $range->{end}{line}];
1143  
1144 # ignore the column, and just format the entire line.
1145 # the text will likely get messed up if you don't include the entire line, anyway.
1146 0 $range->{start}{character} = 0;
1147 0 $range->{end}{character} = 0;
1148 0 $range->{end}{line}++;
1149 0 $selection = join '', @lines;
1150 } ## end if (ref $range eq 'HASH'...)
1151 else
1152 {
1153 0 $whole_file = 1;
1154 0 $selection = $$text;
1155 0 my $lines = () = $selection =~ m{($/)}g;
1156 0 $lines++;
1157  
1158 0 $range = {
1159 start => {
1160 line => 0,
1161 character => 0
1162 },
1163 end => {
1164 line => $lines,
1165 character => 0
1166 }
1167 };
1168 } ## end else [ if (ref $range eq 'HASH'...)]
1169  
1170 0 my $formatted = '';
1171 0 my $stderr = '';
1172 0 my $argv = '-se';
1173 0 ▶ if (length $args{formatting_options}{tabSize})
Branch: 1 branch
BranchTrueFalseTotal
if (length $args{"formatting_options"}{"tabSize"}) 0 0 0
1174 {
1175 0 ▶ $argv .= $args{formatting_options}{insertSpaces} ? ' -i=' : ' -et=';
Branch: 1 branch
BranchTrueFalseTotal
$args{'formatting_options'}{'insertSpaces'} ? : 0 0 0
1176 0 $argv .= $args{formatting_options}{tabSize};
1177 }
1178 0 my ($perltidyrc) = glob $args{perltidyrc};
1179 0 ▶ undef $perltidyrc if (not length $perltidyrc or not -f $perltidyrc or not -r $perltidyrc);
Branch: 1 branch
BranchTrueFalseTotal
unless length $perltidyrc and -f $perltidyrc and -r $perltidyrc 0 0 0
Condition0%0/6
length $perltidyrc and -f $perltidyrc and -r $perltidyrc
!ll&&!rl&&r
000
length $perltidyrc and -f $perltidyrc
!ll&&!rl&&r
000
MC/DC0%0/3
length $perltidyrc and -f $perltidyrc and -r $perltidyrc
length $perltidyrc -f $perltidyrc -r $perltidyrc
Truth table0%0/4
A and B and C
A= length $perltidyrcB= -f $perltidyrcC= -r $perltidyrc
ABCresult
0XX0
10X0
1100
1111
1180 0 my $error = Perl::Tidy::perltidy(source => \$selection, destination => \$formatted, stderr => \$stderr, perltidyrc => $perltidyrc, argv => $argv);
1181  
1182 # get the number of lines in the formatted result - we need to modify the range if
1183 # any lines were added
1184 0 my $lines = () = $formatted =~ m{($/)}g;
1185 0 $lines++;
1186  
1187 # if the selection length has increased due to formatting, update the end.
1188 0 ▶ $range->{end}{line} = $lines if ($whole_file and $lines > $range->{end}{line});
Branch: 1 branch
BranchTrueFalseTotal
if $whole_file and $lines > $range->{"end"}{"line"} 0 0 0
Condition0%0/3
$whole_file and $lines > $range->{"end"}{"line"}
!ll&&!rl&&r
000
MC/DC0%0/2
$whole_file and $lines > $range->{"end"}{"line"}
$whole_file $lines > $range->{"end"}{"line"}
Truth table0%0/3
A and B
A= $whole_fileB= $lines > $range->{"end"}{"line"}
ABresult
0X0
100
111
1189  
1190 0 ▶ $formatted =~ s/\h+$//gm if ($args{formatting_options}{trimTrailingWhitespace});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"formatting_options"}{"trimTrailingWhitespace"} 0 0 0
1191  
1192 0 ▶ if ($args{formatting_options}{insertFinalNewline})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"formatting_options"}{"insertFinalNewline"}) 0 0 0
1193 {
1194 0 ▶ $formatted .= "\n" unless ($formatted =~ /\n$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $formatted =~ /\n$/ 0 0 0
1195 }
1196 0 ▶ if ($args{formatting_options}{trimFinalNewlines})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"formatting_options"}{"trimFinalNewlines"}) 0 0 0
1197 {
1198 0 $formatted =~ s/\n+$/\n/;
1199 }
1200  
1201 0 $stderr =~ s/^<source_stream>:\s*//gm;
1202 0 $stderr =~ s/^Begin Error Output Stream.*$//m;
1203 0 $stderr =~ s/^.*To save a full \.LOG file.*$//m;
1204 0 $stderr =~ s/^\s*$//gm;
1205  
1206 0 ▶ return (1, undef) if ($error == 1 or length $stderr);
Branch: 1 branch
BranchTrueFalseTotal
if $error == 1 or length $stderr 0 0 0
Condition0%0/3
$error == 1 or length $stderr
l!l&&r!l&&!r
000
MC/DC0%0/2
$error == 1 or length $stderr
$error == 1 length $stderr
Truth table0%0/3
A or B
A= $error == 1B= length $stderr
ABresult
1X1
011
000
1207  
1208 return (
1209 0 1,
1210 [
1211 {
1212 range => $range,
1213 newText => $formatted
1214 }
1215 ]
1216 );
1217 } ## end sub format_range
1218  
1219 =head2 format
1220  
1221 This formats the entire document using perltidy.
1222  
1223 =cut
1224  
1225 sub format
1226 {
1227 0 ▶ my ($class, %args) = @_;
Subroutine format: not called CC=1 SCAR=6.9
Pod documented
1228  
1229 0 return $class->format_range(formatting_options => $args{formatting_options}, text => $args{text}, perltidyrc => $args{perltidyrc});
1230 }
1231  
1232 =head2 _ppi_location
1233  
1234 This converts an LSP 0-indexed location to a PPI 1-indexed location.
1235  
1236 =cut
1237  
1238 sub _ppi_location
1239 {
1240 27 ▶ my ($line_number, $column_number) = @_;
Subroutine _ppi_location: called CC=1 SCAR=0.0
1241  
1242 27 return ++$line_number, ++$column_number;
1243 }
1244  
1245 =head2 text_from_uri
1246  
1247 This returns a SCALAR reference to the text of a particular URI.
1248  
1249 =cut
1250  
1251 sub text_from_uri
1252 {
1253 0 ▶ my (undef, $uri) = @_;
Subroutine text_from_uri: not called CC=3 SCAR=24.8
Pod documented
1254  
1255 0 ▶ if (ref $FILES{$uri} eq 'SCALAR')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $FILES{$uri} eq 'SCALAR') { } 0 0 0
1256 {
1257 0 return $FILES{$uri};
1258 }
1259 else
1260 {
1261 0 my $file = URI->new($uri);
1262 0 ▶ open my $fh, '<', $file->file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file->file or return 0 0 0
1263 0 my $text = do { local $/; <$fh> };
1264 0 return \$text;
1265 } ## end else [ if (ref $FILES{$uri} eq...)]
1266 } ## end sub text_from_uri
1267  
1268 sub uri_version
1269 {
1270 0 ▶ my ($uri) = @_;
Subroutine uri_version: not called CC=1 SCAR=6.9
Pod undocumented
1271  
1272 0 return $VERSIONS{$uri};
1273 }
1274  
1275 =head2 _get_ppi_document
1276  
1277 This creates a L<PPI::Document> object for a document. It will
1278 return an L<PPI::Document> from memory if the file has not changed since it was last parsed.
1279  
1280 =cut
1281  
1282 sub _get_ppi_document
1283 {
1284 32 ▶ my ($self, %args) = @_;
Subroutine _get_ppi_document: called CC=11 SCAR=24.4
1285  
1286 32 my $file;
1287  
1288 32 ▶ if ($args{text})
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'text'}) { } 0 32 32
elsif (length $args{'uri'}) { } 32 0 32
1289 {
1290 0 $file = $args{text};
1291 }
1292 elsif (length $args{uri})
1293 {
1294 32 ▶ if (ref $FILES{$args{uri}} eq 'SCALAR')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $FILES{$args{'uri'}} eq 'SCALAR') { } 27 5 32
1295 {
1296 27 $file = $FILES{$args{uri}};
1297 }
1298 else
1299 {
1300 5 $file = URI->new($args{uri})->file;
1301 }
1302 } ## end elsif (length $args{uri})
1303  
1304 32 ▶ if (length $args{line})
Branch: 1 branch
BranchTrueFalseTotal
if (length $args{"line"}) 28 4 32
1305 {
1306 28 my $fh;
1307 28 ▶ if (ref $file eq 'SCALAR')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $file eq 'SCALAR') { } 27 1 28
elsif (open $fh, '<', $file) { } 1 0 1
1308 {
1309 27 my $line = $args{line};
1310 27 my $new_line = $/;
1311  
1312 27 my ($text) = $$file =~ /(?:[^$new_line]*$new_line){$line}([^$new_line]*)$new_line?/m;
1313  
1314 27 ▶ if (length $text)
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 27 0 27
1315 {
1316 27 $file = \$text;
1317 27 $self->{one_line} = 1;
1318 }
1319 } ## end if (ref $file eq 'SCALAR'...)
1320 elsif (open $fh, '<', $file)
1321 {
1322 1 my @text = <$fh>;
1323  
1324 1 ▶ if (length $text[$args{line}])
Branch: 1 branch
BranchTrueFalseTotal
if (length $text[$args{"line"}]) 1 0 1
1325 {
1326 1 $file = \($text[$args{line}]);
1327 1 $self->{one_line} = 1;
1328 }
1329 } ## end elsif (open $fh, '<', $file...)
1330 } ## end if (length $args{line}...)
1331  
1332 32 my $document = PPI::Document->new($file, readonly => 1);
1333 32 ▶ return if (not blessed($document) or not $document->isa('PPI::Document'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($document) and $document->isa("PPI::Document") 2 30 32
Condition66%2/3
builtin::blessed($document) and $document->isa("PPI::Document")
!ll&&!rl&&r
2030
MC/DC50%1/2
builtin::blessed($document) and $document->isa("PPI::Document")
builtin::blessed($document) $document->isa("PPI::Document")
Truth table66%2/3
A and B
A= builtin::blessed($document)B= $document->isa("PPI::Document")
ABresult
0X0
100
111
1334  
1335 30 $document->index_locations();
1336  
1337 30 return $document;
1338 } ## end sub _get_ppi_document
1339  
1340 =head2 _is_constant
1341  
1342 Determines if a PPI element is a constant.
1343  
1344 =cut
1345  
1346 sub _is_constant
1347 {
1348 0 ▶ my ($element) = @_;
Subroutine _is_constant: not called CC=3 SCAR=24.8
1349  
1350 0 ▶ return unless $element->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("PPI::Token::Word") 0 0 0
1351 0 ▶ return unless ref $_->snext_sibling eq 'PPI::Token::Operator';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_->snext_sibling eq "PPI::Token::Operator" 0 0 0
1352 0 return $_->snext_sibling->content eq '=>';
1353 } ## end sub _is_constant
1354  
1355 =head2 find_word_under_cursor
1356  
1357 Gets information about the current word under the cursor.
1358 Returns a four-element list:
1359  
1360 =over
1361  
1362 =item The range where the word is located
1363  
1364 =item A boolean indicating whether the word is before an arrow (->) or not.
1365  
1366 =item The name of the package where the word is located
1367  
1368 =item The word under the cursor to be used as a filter for searching
1369  
1370 =back
1371  
1372 =cut
1373  
1374 sub find_word_under_cursor
1375 {
1376 27 ▶ my ($self, $line, $character) = @_;
Subroutine find_word_under_cursor: called CC=115 SCAR=61.3
Pod documented
1377  
1378 27 my @elements = $self->find_elements_at_location($line, $character);
1379 27 @elements = map { $_->tokens } @elements;
1380 @elements =
1381 27 sort { (abs $character - $a->lsp_column_number) <=> (abs $character - $b->lsp_column_number) } @elements;
1382 27 ▶ my @in_range = grep { $_->lsp_column_number <= $character and $_->lsp_column_number + length($_->content) >= $character } @elements;
Branch: 1 branch
BranchTrueFalseTotal
$_->lsp_column_number <= $character and $_->lsp_column_number + length($_->content) >= $character 194 11 205
1383 my $element = first
1384 {
1385 49 ▶ $_->type eq 'PPI::Token::Word'
Subroutine __ANON__: called CC=10 SCAR=23.0
Branch: 1 branch
BranchTrueFalseTotal
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double" or $_->type eq "PPI::Token::Quote::Interpolate" or $_->type eq "PPI::Token::QuoteLike::Regexp" or $_->type eq "PPI::Token::QuoteLike::Command" or $_->element->isa("PPI::Token::Regexp") 27 22 49
Condition95%23/24
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double" or $_->type eq "PPI::Token::Quote::Interpolate" or $_->type eq "PPI::Token::QuoteLike::Regexp" or $_->type eq "PPI::Token::QuoteLike::Command"
l!l&&r!l&&!r
21127
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double" or $_->type eq "PPI::Token::Quote::Interpolate" or $_->type eq "PPI::Token::QuoteLike::Regexp"
l!l&&r!l&&!r
20128
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double" or $_->type eq "PPI::Token::Quote::Interpolate"
l!l&&r!l&&!r
19129
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double"
l!l&&r!l&&!r
19030
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator"
l!l&&r!l&&!r
15430
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic"
l!l&&r!l&&!r
11434
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol"
l!l&&r!l&&!r
9238
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label"
l!l&&r!l&&!r
8140
MC/DC88%8/9
$_->type eq "PPI::Token::Word" or $_->type eq "PPI::Token::Label" or $_->type eq "PPI::Token::Symbol" or $_->type eq "PPI::Token::Magic" or $_->type eq "PPI::Token::Operator" or $_->type eq "PPI::Token::Quote::Double" or $_->type eq "PPI::Token::Quote::Interpolate" or $_->type eq "PPI::Token::QuoteLike::Regexp" or $_->type eq "PPI::Token::QuoteLike::Command"
$_->type eq "PPI::Token::Word" $_->type eq "PPI::Token::Label" $_->type eq "PPI::Token::Symbol" $_->type eq "PPI::Token::Magic" $_->type eq "PPI::Token::Operator" $_->type eq "PPI::Token::Quote::Double" $_->type eq "PPI::Token::Quote::Interpolate" $_->type eq "PPI::Token::QuoteLike::Regexp" $_->type eq "PPI::Token::QuoteLike::Command"
Truth table90%9/10
A or B or C or D or E or F or G or H or I
A= $_->type eq "PPI::Token::Word"B= $_->type eq "PPI::Token::Label"C= $_->type eq "PPI::Token::Symbol"D= $_->type eq "PPI::Token::Magic"E= $_->type eq "PPI::Token::Operator"F= $_->type eq "PPI::Token::Quote::Double"G= $_->type eq "PPI::Token::Quote::Interpolate"H= $_->type eq "PPI::Token::QuoteLike::Regexp"I= $_->type eq "PPI::Token::QuoteLike::Command"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
1386 or $_->type eq 'PPI::Token::Label'
1387 or $_->type eq 'PPI::Token::Symbol'
1388 or $_->type eq 'PPI::Token::Magic'
1389 or $_->type eq 'PPI::Token::Operator'
1390 or $_->type eq 'PPI::Token::Quote::Double'
1391 or $_->type eq 'PPI::Token::Quote::Interpolate'
1392 or $_->type eq 'PPI::Token::QuoteLike::Regexp'
1393 or $_->type eq 'PPI::Token::QuoteLike::Command'
1394 or $_->element->isa('PPI::Token::Regexp')
1395 27 } @in_range;
1396 27 ▶ my $closest_operator = first { $_->type eq 'PPI::Token::Operator' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1397  
1398 27 ▶ if (blessed($element) and $element->isa('PLS::Parser::Element') and $element->type eq 'PPI::Token::Operator')
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Operator") 4 23 27
Condition83%5/6
builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Operator"
!ll&&!rl&&r
3204
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
3024
MC/DC66%2/3
builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Operator"
builtin::blessed($element) $element->isa("PLS::Parser::Element") $element->type eq "PPI::Token::Operator"
Truth table75%3/4
A and B and C
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")C= $element->type eq "PPI::Token::Operator"
ABCresult
0XX0
10X0
1100
1111
1399 {
1400 4 ▶ return $element->range(), 0, '', '-' if ((not blessed($element->element->previous_sibling) or $element->element->previous_sibling->isa('PPI::Token::Whitespace')) and $element->content eq '-');
Branch: 1 branch
BranchTrueFalseTotal
if !builtin::blessed($element->element->previous_sibling) || $element->element->previous_sibling->isa("PPI::Token::Whitespace") and $element->content eq "-" 0 4 4
Condition33%2/6
!builtin::blessed($element->element->previous_sibling) || $element->element->previous_sibling->isa("PPI::Token::Whitespace") and $element->content eq "-"
!ll&&!rl&&r
400
not builtin::blessed($element->element->previous_sibling) or $element->element->previous_sibling->isa("PPI::Token::Whitespace")
l!l&&r!l&&!r
004
MC/DC0%0/3
!builtin::blessed($element->element->previous_sibling) || $element->element->previous_sibling->isa("PPI::Token::Whitespace") and $element->content eq "-"
not builtin::blessed($element->element->previous_sibling) $element->element->previous_sibling->isa("PPI::Token::Whitespace") $element->content eq "-"
Truth table20%1/5
not(A) or B and C
A= not builtin::blessed($element->element->previous_sibling)B= $element->element->previous_sibling->isa("PPI::Token::Whitespace")C= $element->content eq "-"
ABCresult
00X0
1X00
0100
1X11
0111
1401 4 undef $element;
1402 }
1403  
1404 27 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Quote::Double" || $element->type eq "PPI::Token::Quote::Interpolate" || $element->type eq "PPI::Token::QuoteLike::Regexp" || $element->type eq "PPI::Token::QuoteLike::Command" || $element->element->isa("PPI::Token::Regexp")) 3 22 25
Condition88%16/18
builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Quote::Double" || $element->type eq "PPI::Token::Quote::Interpolate" || $element->type eq "PPI::Token::QuoteLike::Regexp" || $element->type eq "PPI::Token::QuoteLike::Command" || $element->element->isa("PPI::Token::Regexp")
!ll&&!rl&&r
7182
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
7020
$element->type eq "PPI::Token::Quote::Double" or $element->type eq "PPI::Token::Quote::Interpolate" or $element->type eq "PPI::Token::QuoteLike::Regexp" or $element->type eq "PPI::Token::QuoteLike::Command" or $element->element->isa("PPI::Token::Regexp")
l!l&&r!l&&!r
3215
$element->type eq "PPI::Token::Quote::Double" or $element->type eq "PPI::Token::Quote::Interpolate" or $element->type eq "PPI::Token::QuoteLike::Regexp" or $element->type eq "PPI::Token::QuoteLike::Command"
l!l&&r!l&&!r
2117
$element->type eq "PPI::Token::Quote::Double" or $element->type eq "PPI::Token::Quote::Interpolate" or $element->type eq "PPI::Token::QuoteLike::Regexp"
l!l&&r!l&&!r
1118
$element->type eq "PPI::Token::Quote::Double" or $element->type eq "PPI::Token::Quote::Interpolate"
l!l&&r!l&&!r
0119
MC/DC28%2/7
builtin::blessed($element) and $element->isa("PLS::Parser::Element") and $element->type eq "PPI::Token::Quote::Double" || $element->type eq "PPI::Token::Quote::Interpolate" || $element->type eq "PPI::Token::QuoteLike::Regexp" || $element->type eq "PPI::Token::QuoteLike::Command" || $element->element->isa("PPI::Token::Regexp")
builtin::blessed($element) $element->isa("PLS::Parser::Element") $element->type eq "PPI::Token::Quote::Double" $element->type eq "PPI::Token::Quote::Interpolate" $element->type eq "PPI::Token::QuoteLike::Regexp" $element->type eq "PPI::Token::QuoteLike::Command" $element->element->isa("PPI::Token::Regexp")
Truth table37%3/8
A and B and C or D or E or F or G
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")C= $element->type eq "PPI::Token::Quote::Double"D= $element->type eq "PPI::Token::Quote::Interpolate"E= $element->type eq "PPI::Token::QuoteLike::Regexp"F= $element->type eq "PPI::Token::QuoteLike::Command"G= $element->element->isa("PPI::Token::Regexp")
ABCDEFGresult
0XXXXXX0
10XXXXX0
11000000
111XXXX1
1101XXX1
11001XX1
110001X1
11000011
1405 blessed($element)
1406 and $element->isa('PLS::Parser::Element')
1407 and ( $element->type eq 'PPI::Token::Quote::Double'
1408 or $element->type eq 'PPI::Token::Quote::Interpolate'
1409 or $element->type eq 'PPI::Token::QuoteLike::Regexp'
1410 or $element->type eq 'PPI::Token::QuoteLike::Command'
1411 or $element->element->isa('PPI::Token::Regexp'))
1412 )
1413 {
1414 5 my $string_start = $character - $element->range->{start}{character};
1415 5 my $string_end = $character - $element->range->{end}{character};
1416  
1417 5 ▶ return if ($string_start <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $string_start <= 0 0 5 5
1418  
1419 5 my $string = $element->name;
1420  
1421 5 ▶ if ($string =~ /^"/)
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ /^"/) { } 0 5 5
elsif ($string =~ /^(q[qrx]|[ysm]|tr)(\S)/ or $string =~ m[^()(/)]) { } 0 5 5
1422 {
1423 0 $string = substr $string, 1, -1;
1424 }
1425 ▶ elsif ($string =~ /^(q[qrx]|[ysm]|tr)(\S)/ or $string =~ m{^()(/)})
Condition33%1/3
$string =~ /^(q[qrx]|[ysm]|tr)(\S)/ or $string =~ m[^()(/)]
l!l&&r!l&&!r
005
MC/DC0%0/2
$string =~ /^(q[qrx]|[ysm]|tr)(\S)/ or $string =~ m[^()(/)]
$string =~ /^(q[qrx]|[ysm]|tr)(\S)/ $string =~ m[^()(/)]
Truth table33%1/3
A or B
A= $string =~ /^(q[qrx]|[ysm]|tr)(\S)/B= $string =~ m[^()(/)]
ABresult
1X1
011
000
1426 {
1427 0 ▶ my $operator = $1 // '';
Condition0%0/2
$1 // ""
l!l
00
MC/DC0%0/1
$1 // ""
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
1428 0 my $delimiter = $2;
1429 0 my $end_delimiter = $delimiter;
1430 0 ▶ $end_delimiter = '}' if ($delimiter eq '{');
Branch: 1 branch
BranchTrueFalseTotal
if $delimiter eq "{" 0 0 0
1431 0 ▶ $end_delimiter = ')' if ($delimiter eq '(');
Branch: 1 branch
BranchTrueFalseTotal
if $delimiter eq "(" 0 0 0
1432 0 ▶ $end_delimiter = '>' if ($delimiter eq '>');
Branch: 1 branch
BranchTrueFalseTotal
if $delimiter eq ">" 0 0 0
1433 0 ▶ $end_delimiter = ']' if ($delimiter eq ']');
Branch: 1 branch
BranchTrueFalseTotal
if $delimiter eq "]" 0 0 0
1434  
1435 0 ▶ if ($string =~ /\Q$end_delimiter\E$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\Q$end_delimiter\E$/) { } 0 0 0
1436 {
1437 0 $string = substr $string, length($operator) + 1, -1;
1438 }
1439 else
1440 {
1441 0 $string = substr $string, length($operator) + 1;
1442 }
1443 } ## end elsif ($string =~ /^(q[qrx]|[ysm]|tr)(\S)/...)
1444  
1445 5 state $var_rx = qr/((?&PerlVariable)|[\$\@\%])$PPR::GRAMMAR$/;
1446  
1447 5 ▶ if ($string =~ /$var_rx/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$var_rx/) 0 5 5
1448 {
1449 return {
1450 0 start => {
1451 line => $line,
1452 character => $character - length $1
1453 },
1454 end => {
1455 line => $line,
1456 character => $character
1457 }
1458 },
1459 0, '', $1;
1460 } ## end if ($string =~ /$var_rx/...)
1461  
1462 5 undef $element;
1463 } ## end if (blessed($element) ...)
1464  
1465 27 ▶ if (not blessed($element) or not $element->isa('PLS::Parser::Element'))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($element) and $element->isa("PLS::Parser::Element")) 12 15 27
Condition66%2/3
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
12015
MC/DC50%1/2
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
builtin::blessed($element) $element->isa("PLS::Parser::Element")
Truth table66%2/3
A and B
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")
ABresult
0X0
100
111
1466 {
1467 # Let's see if PPI thinks that we're typing the start of a Regexp operator.
1468 12 ▶ my $regexp = first { $_->element->isa('PPI::Token::Regexp') } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1469 12 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($regexp) and $regexp->type eq "PPI::Token::Regexp::Match" && $regexp->content eq "m" || $regexp->type eq "PPI::Token::Regexp::Substitute" && $regexp->content eq "s" || $regexp->type eq "PPI::Token::Regexp::Transliterate" && ($regexp->content eq "tr" || $regexp->content eq "y")) 1 10 11
Condition38%8/21
builtin::blessed($regexp) and $regexp->type eq "PPI::Token::Regexp::Match" && $regexp->content eq "m" || $regexp->type eq "PPI::Token::Regexp::Substitute" && $regexp->content eq "s" || $regexp->type eq "PPI::Token::Regexp::Transliterate" && ($regexp->content eq "tr" || $regexp->content eq "y")
!ll&&!rl&&r
1020
$regexp->type eq "PPI::Token::Regexp::Match" and $regexp->content eq "m" or $regexp->type eq "PPI::Token::Regexp::Substitute" and $regexp->content eq "s" or $regexp->type eq "PPI::Token::Regexp::Transliterate" and $regexp->content eq "tr" || $regexp->content eq "y"
l!l&&r!l&&!r
200
$regexp->type eq "PPI::Token::Regexp::Match" and $regexp->content eq "m" or $regexp->type eq "PPI::Token::Regexp::Substitute" and $regexp->content eq "s"
l!l&&r!l&&!r
110
$regexp->type eq "PPI::Token::Regexp::Match" and $regexp->content eq "m"
!ll&&!rl&&r
101
$regexp->type eq "PPI::Token::Regexp::Substitute" and $regexp->content eq "s"
!ll&&!rl&&r
001
$regexp->type eq "PPI::Token::Regexp::Transliterate" and $regexp->content eq "tr" || $regexp->content eq "y"
!ll&&!rl&&r
000
$regexp->content eq "tr" or $regexp->content eq "y"
l!l&&r!l&&!r
000
MC/DC0%0/8
builtin::blessed($regexp) and $regexp->type eq "PPI::Token::Regexp::Match" && $regexp->content eq "m" || $regexp->type eq "PPI::Token::Regexp::Substitute" && $regexp->content eq "s" || $regexp->type eq "PPI::Token::Regexp::Transliterate" && ($regexp->content eq "tr" || $regexp->content eq "y")
builtin::blessed($regexp) $regexp->type eq "PPI::Token::Regexp::Match" $regexp->content eq "m" $regexp->type eq "PPI::Token::Regexp::Substitute" $regexp->content eq "s" $regexp->type eq "PPI::Token::Regexp::Transliterate" $regexp->content eq "tr" $regexp->content eq "y"
Truth table5%1/20
A and B and C or D and E or F and G or H
A= builtin::blessed($regexp)B= $regexp->type eq "PPI::Token::Regexp::Match"C= $regexp->content eq "m"D= $regexp->type eq "PPI::Token::Regexp::Substitute"E= $regexp->content eq "s"F= $regexp->type eq "PPI::Token::Regexp::Transliterate"G= $regexp->content eq "tr"H= $regexp->content eq "y"
ABCDEFGHresult
0XXXXXXX0
10X0X0XX0
10X0X1000
10X100XX0
10X101000
1100X0XX0
1100X1000
110100XX0
110101000
111XXXXX1
10X11XXX1
11011XXX1
10X0X11X1
10X0X1011
10X1011X1
10X101011
1100X11X1
1100X1011
1101011X1
110101011
1470 blessed($regexp)
1471 and ( $regexp->type eq 'PPI::Token::Regexp::Match' and $regexp->content eq 'm'
1472 or $regexp->type eq 'PPI::Token::Regexp::Substitute' and $regexp->content eq 's'
1473 or $regexp->type eq 'PPI::Token::Regexp::Transliterate' and ($regexp->content eq 'tr' or $regexp->content eq 'y'))
1474 )
1475 {
1476 2 $element = $regexp;
1477 } ## end if (blessed($regexp) and...)
1478 } ## end if (not blessed($element...))
1479  
1480 27 ▶ if (not blessed($element) or not $element->isa('PLS::Parser::Element'))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($element) and $element->isa("PLS::Parser::Element")) 10 17 27
Condition66%2/3
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
10017
MC/DC50%1/2
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
builtin::blessed($element) $element->isa("PLS::Parser::Element")
Truth table66%2/3
A and B
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")
ABresult
0X0
100
111
1481 {
1482 # Let's see if PPI thinks that we're typing the start of a quote operator.
1483 10 ▶ my $literal = first { $_->type eq 'PPI::Token::Quote::Literal' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1484 10 ▶ my $interpolate = first { $_->type eq 'PPI::Token::Quote::Interpolate' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1485 10 ▶ my $qr = first { $_->type eq 'PPI::Token::QuoteLike::Regexp' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1486 10 ▶ my $qw = first { $_->type eq 'PPI::Token::QuoteLike::Words' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1487 10 ▶ my $qx = first { $_->type eq 'PPI::Token::QuoteLike::Command' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1488  
1489 10 ▶ if (blessed($literal) and $literal->element->content eq 'q')
Branch: 5 branches
BranchTrueFalseTotal
if (builtin::blessed($literal) and $literal->element->content eq 'q') { } 1 9 10
elsif (builtin::blessed($interpolate) and $interpolate->element->content eq 'qq') { } 1 8 9
elsif (builtin::blessed($qr) and $qr->element->content eq 'qr') { } 1 7 8
elsif (builtin::blessed($qw) and $qw->element->content eq 'qw') { } 1 6 7
elsif (builtin::blessed($qx) and $qx->element->content eq 'qx') { } 1 10 11
Condition66%2/3
builtin::blessed($literal) and $literal->element->content eq "q"
!ll&&!rl&&r
901
MC/DC50%1/2
builtin::blessed($literal) and $literal->element->content eq "q"
builtin::blessed($literal) $literal->element->content eq "q"
Truth table66%2/3
A and B
A= builtin::blessed($literal)B= $literal->element->content eq "q"
ABresult
0X0
100
111
1490 {
1491 1 $element = $literal;
1492 }
1493 ▶ elsif (blessed($interpolate) and $interpolate->element->content eq 'qq')
Condition66%2/3
builtin::blessed($interpolate) and $interpolate->element->content eq "qq"
!ll&&!rl&&r
801
MC/DC50%1/2
builtin::blessed($interpolate) and $interpolate->element->content eq "qq"
builtin::blessed($interpolate) $interpolate->element->content eq "qq"
Truth table66%2/3
A and B
A= builtin::blessed($interpolate)B= $interpolate->element->content eq "qq"
ABresult
0X0
100
111
1494 {
1495 1 $element = $interpolate;
1496 }
1497 ▶ elsif (blessed($qr) and $qr->element->content eq 'qr')
Condition66%2/3
builtin::blessed($qr) and $qr->element->content eq "qr"
!ll&&!rl&&r
701
MC/DC50%1/2
builtin::blessed($qr) and $qr->element->content eq "qr"
builtin::blessed($qr) $qr->element->content eq "qr"
Truth table66%2/3
A and B
A= builtin::blessed($qr)B= $qr->element->content eq "qr"
ABresult
0X0
100
111
1498 {
1499 1 $element = $qr;
1500 }
1501 ▶ elsif (blessed($qw) and $qw->element->content eq 'qw')
Condition66%2/3
builtin::blessed($qw) and $qw->element->content eq "qw"
!ll&&!rl&&r
601
MC/DC50%1/2
builtin::blessed($qw) and $qw->element->content eq "qw"
builtin::blessed($qw) $qw->element->content eq "qw"
Truth table66%2/3
A and B
A= builtin::blessed($qw)B= $qw->element->content eq "qw"
ABresult
0X0
100
111
1502 {
1503 1 $element = $qw;
1504 }
1505 ▶ elsif (blessed($qx) and $qx->element->content eq 'qx')
Condition66%2/3
builtin::blessed($qx) and $qx->element->content eq "qx"
!ll&&!rl&&r
501
MC/DC50%1/2
builtin::blessed($qx) and $qx->element->content eq "qx"
builtin::blessed($qx) $qx->element->content eq "qx"
Truth table66%2/3
A and B
A= builtin::blessed($qx)B= $qx->element->content eq "qx"
ABresult
0X0
100
111
1506 {
1507 1 $element = $qx;
1508 }
1509 } ## end if (not blessed($element...))
1510  
1511 27 ▶ if (not blessed($element) or not $element->isa('PLS::Parser::Element'))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($element) and $element->isa("PLS::Parser::Element")) 5 22 27
Condition66%2/3
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
5022
MC/DC50%1/2
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
builtin::blessed($element) $element->isa("PLS::Parser::Element")
Truth table66%2/3
A and B
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")
ABresult
0X0
100
111
1512 {
1513 5 ▶ my $cast = first { $_->type eq 'PPI::Token::Cast' } @elements;
Subroutine __ANON__: called CC=1 SCAR=0.0
1514  
1515 # A cast probably means only a sigil was typed.
1516 5 ▶ if (blessed($cast) and $cast->isa('PLS::Parser::Element'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($cast) and $cast->isa("PLS::Parser::Element")) 1 4 5
Condition66%2/3
builtin::blessed($cast) and $cast->isa("PLS::Parser::Element")
!ll&&!rl&&r
401
MC/DC50%1/2
builtin::blessed($cast) and $cast->isa("PLS::Parser::Element")
builtin::blessed($cast) $cast->isa("PLS::Parser::Element")
Truth table66%2/3
A and B
A= builtin::blessed($cast)B= $cast->isa("PLS::Parser::Element")
ABresult
0X0
100
111
1517 {
1518 1 return $cast->range, 0, '', $cast->name;
1519 }
1520 } ## end if (not blessed($element...))
1521  
1522 26 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $closest_operator->lsp_column_number + length($closest_operator->content) == $character) 4 22 26
Condition66%10/15
not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $closest_operator->lsp_column_number + length($closest_operator->content) == $character
!ll&&!rl&&r
2204
not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->"
!ll&&!rl&&r
2204
not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element")
!ll&&!rl&&r
2204
not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator)
!ll&&!rl&&r
2204
builtin::blessed($element) && $element->isa('PLS::Parser::Element')
!ll&&!rl&&r
4022
MC/DC16%1/6
not builtin::blessed($element) && $element->isa("PLS::Parser::Element") and builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $closest_operator->lsp_column_number + length($closest_operator->content) == $character
builtin::blessed($element) $element->isa('PLS::Parser::Element') builtin::blessed($closest_operator) $closest_operator->isa("PLS::Parser::Element") $closest_operator->name eq "->" $closest_operator->lsp_column_number + length($closest_operator->content) == $character
Truth table18%2/11
not(A && B) and C and D and E and F
A= builtin::blessed($element)B= $element->isa('PLS::Parser::Element')C= builtin::blessed($closest_operator)D= $closest_operator->isa("PLS::Parser::Element")E= $closest_operator->name eq "->"F= $closest_operator->lsp_column_number + length($closest_operator->content) == $character
ABCDEFresult
11XXXX0
0X0XXX0
100XXX0
0X10XX0
1010XX0
0X110X0
10110X0
0X11100
1011100
0X11111
1011111
1523 (
1524 not blessed($element)
1525 or not $element->isa('PLS::Parser::Element')
1526 )
1527 and blessed($closest_operator)
1528 and $closest_operator->isa('PLS::Parser::Element')
1529 and $closest_operator->name eq '->'
1530 and $closest_operator->lsp_column_number + length($closest_operator->content) == $character
1531 )
1532 {
1533 4 my $range = $closest_operator->range;
1534 4 $range->{start}{character} += length $closest_operator->content;
1535 4 $range->{end}{character} = $range->{start}{character};
1536  
1537 # If there is a word before the arrow AND it is not after another arrow, use it as the package name.
1538 # Otherwise, there is no package name, but there is an arrow and a blank filter.
1539 4 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa('PLS::Parser::Element') and $closest_operator->previous_sibling->type eq 'PPI::Token::Word' and not builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) && $closest_operator->previous_sibling->element->previous_sibling->isa('PPI::Token::Operator') && $closest_operator->previous_sibling->element->previous_sibling eq '->') { } 2 2 4
Condition66%10/15
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word" and not builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) && $closest_operator->previous_sibling->element->previous_sibling->isa("PPI::Token::Operator") && $closest_operator->previous_sibling->element->previous_sibling eq "->"
!ll&&!rl&&r
112
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word"
!ll&&!rl&&r
013
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
004
builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) && $closest_operator->previous_sibling->element->previous_sibling->isa('PPI::Token::Operator') && $closest_operator->previous_sibling->element->previous_sibling eq '->'
!ll&&!rl&&r
201
builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) and $closest_operator->previous_sibling->element->previous_sibling->isa("PPI::Token::Operator")
!ll&&!rl&&r
201
MC/DC33%2/6
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word" and not builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) && $closest_operator->previous_sibling->element->previous_sibling->isa("PPI::Token::Operator") && $closest_operator->previous_sibling->element->previous_sibling eq "->"
builtin::blessed($closest_operator->previous_sibling) $closest_operator->previous_sibling->isa("PLS::Parser::Element") $closest_operator->previous_sibling->type eq "PPI::Token::Word" builtin::blessed($closest_operator->previous_sibling->element->previous_sibling) $closest_operator->previous_sibling->element->previous_sibling->isa("PPI::Token::Operator") $closest_operator->previous_sibling->element->previous_sibling eq '->'
Truth table42%3/7
A and B and C and not(D and E && F)
A= builtin::blessed($closest_operator->previous_sibling)B= $closest_operator->previous_sibling->isa("PLS::Parser::Element")C= $closest_operator->previous_sibling->type eq "PPI::Token::Word"D= builtin::blessed($closest_operator->previous_sibling->element->previous_sibling)E= $closest_operator->previous_sibling->element->previous_sibling->isa("PPI::Token::Operator")F= $closest_operator->previous_sibling->element->previous_sibling eq '->'
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1111110
1110XX1
11110X1
1111101
1540 blessed($closest_operator->previous_sibling)
1541 and $closest_operator->previous_sibling->isa('PLS::Parser::Element')
1542 and $closest_operator->previous_sibling->type eq 'PPI::Token::Word'
1543 and ( not blessed($closest_operator->previous_sibling->element->previous_sibling)
1544 or not $closest_operator->previous_sibling->element->previous_sibling->isa('PPI::Token::Operator')
1545 or not $closest_operator->previous_sibling->element->previous_sibling eq '->')
1546 )
1547 {
1548 2 return $range, 1, $closest_operator->previous_sibling->name, '';
1549 } ## end if (blessed($closest_operator...))
1550 else
1551 {
1552 2 return $range, 1, '', '';
1553 }
1554 } ## end if ((not blessed($element...)))
1555  
1556 22 ▶ return if (not blessed($element) or not $element->isa('PLS::Parser::Element'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($element) and $element->isa("PLS::Parser::Element") 0 22 22
Condition33%1/3
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
!ll&&!rl&&r
0022
MC/DC0%0/2
builtin::blessed($element) and $element->isa("PLS::Parser::Element")
builtin::blessed($element) $element->isa("PLS::Parser::Element")
Truth table33%1/3
A and B
A= builtin::blessed($element)B= $element->isa("PLS::Parser::Element")
ABresult
0X0
100
111
1557  
1558 22 ▶ if ($element->type eq 'PPI::Token::Magic')
Branch: 1 branch
BranchTrueFalseTotal
if ($element->type eq "PPI::Token::Magic") 4 18 22
1559 {
1560 4 my $range = $element->range;
1561 4 $range->{end}{character}--;
1562 4 return $range, 0, '', '$';
1563 } ## end if ($element->type eq ...)
1564  
1565 # If we're typing right before a sigil, return the previous element.
1566 18 ▶ if ($element->type eq 'PPI::Token::Symbol' and $element->lsp_column_number == $character and blessed($element->previous_sibling) and $element->previous_sibling->isa('PLS::Parser::Element'))
Branch: 1 branch
BranchTrueFalseTotal
if ($element->type eq "PPI::Token::Symbol" and $element->lsp_column_number == $character and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element")) 1 17 18
Condition77%7/9
$element->type eq "PPI::Token::Symbol" and $element->lsp_column_number == $character and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
1701
$element->type eq "PPI::Token::Symbol" and $element->lsp_column_number == $character and builtin::blessed($element->previous_sibling)
!ll&&!rl&&r
1701
$element->type eq "PPI::Token::Symbol" and $element->lsp_column_number == $character
!ll&&!rl&&r
1611
MC/DC50%2/4
$element->type eq "PPI::Token::Symbol" and $element->lsp_column_number == $character and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element")
$element->type eq "PPI::Token::Symbol" $element->lsp_column_number == $character builtin::blessed($element->previous_sibling) $element->previous_sibling->isa("PLS::Parser::Element")
Truth table60%3/5
A and B and C and D
A= $element->type eq "PPI::Token::Symbol"B= $element->lsp_column_number == $characterC= builtin::blessed($element->previous_sibling)D= $element->previous_sibling->isa("PLS::Parser::Element")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1567 {
1568 1 $element = $element->previous_sibling;
1569 }
1570  
1571 # Short-circuit if this is a HASH reference subscript.
1572 18 my $parent = $element->parent;
1573 18 ▶ $parent = $parent->parent if (blessed($parent) and ref $parent eq 'PLS::Parser::Element');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($parent) and ref $parent eq "PLS::Parser::Element" 18 0 18
Condition33%1/3
builtin::blessed($parent) and ref $parent eq "PLS::Parser::Element"
!ll&&!rl&&r
0018
MC/DC0%0/2
builtin::blessed($parent) and ref $parent eq "PLS::Parser::Element"
builtin::blessed($parent) ref $parent eq "PLS::Parser::Element"
Truth table33%1/3
A and B
A= builtin::blessed($parent)B= ref $parent eq "PLS::Parser::Element"
ABresult
0X0
100
111
1574 18 ▶ return if ($element->type eq 'PPI::Token::Word' and blessed($parent) and $parent->isa('PLS::Parser::Element') and $parent->type eq 'PPI::Structure::Subscript');
Branch: 1 branch
BranchTrueFalseTotal
if $element->type eq "PPI::Token::Word" and builtin::blessed($parent) and $parent->isa("PLS::Parser::Element") and $parent->type eq "PPI::Structure::Subscript" 0 18 18
Condition66%6/9
$element->type eq "PPI::Token::Word" and builtin::blessed($parent) and $parent->isa("PLS::Parser::Element") and $parent->type eq "PPI::Structure::Subscript"
!ll&&!rl&&r
1080
$element->type eq "PPI::Token::Word" and builtin::blessed($parent) and $parent->isa("PLS::Parser::Element")
!ll&&!rl&&r
1008
$element->type eq "PPI::Token::Word" and builtin::blessed($parent)
!ll&&!rl&&r
1008
MC/DC0%0/4
$element->type eq "PPI::Token::Word" and builtin::blessed($parent) and $parent->isa("PLS::Parser::Element") and $parent->type eq "PPI::Structure::Subscript"
$element->type eq "PPI::Token::Word" builtin::blessed($parent) $parent->isa("PLS::Parser::Element") $parent->type eq "PPI::Structure::Subscript"
Truth table40%2/5
A and B and C and D
A= $element->type eq "PPI::Token::Word"B= builtin::blessed($parent)C= $parent->isa("PLS::Parser::Element")D= $parent->type eq "PPI::Structure::Subscript"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1575  
1576 # if the cursor is on the word after an arrow, back up to the arrow so we can use any package information before it.
1577 18 ▶ if ( $element->type eq 'PPI::Token::Word'
Branch: 1 branch
BranchTrueFalseTotal
if ($element->type eq "PPI::Token::Word" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->name eq "->") 4 14 18
Condition77%7/9
$element->type eq "PPI::Token::Word" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->name eq "->"
!ll&&!rl&&r
1404
$element->type eq "PPI::Token::Word" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
1404
$element->type eq "PPI::Token::Word" and builtin::blessed($element->previous_sibling)
!ll&&!rl&&r
1044
MC/DC50%2/4
$element->type eq "PPI::Token::Word" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->name eq "->"
$element->type eq "PPI::Token::Word" builtin::blessed($element->previous_sibling) $element->previous_sibling->isa("PLS::Parser::Element") $element->previous_sibling->name eq "->"
Truth table60%3/5
A and B and C and D
A= $element->type eq "PPI::Token::Word"B= builtin::blessed($element->previous_sibling)C= $element->previous_sibling->isa("PLS::Parser::Element")D= $element->previous_sibling->name eq "->"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1578 and blessed($element->previous_sibling)
1579 and $element->previous_sibling->isa('PLS::Parser::Element')
1580 and $element->previous_sibling->name eq '->')
1581 {
1582 4 $closest_operator = $element->previous_sibling;
1583 } ## end if ($element->type eq ...)
1584  
1585 18 ▶ if ( blessed($closest_operator)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $element->type eq "PPI::Token::Word" and $element->parent->element == $closest_operator->parent->element) 4 14 18
Condition75%9/12
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $element->type eq "PPI::Token::Word" and $element->parent->element == $closest_operator->parent->element
!ll&&!rl&&r
1314
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $element->type eq "PPI::Token::Word"
!ll&&!rl&&r
1305
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->"
!ll&&!rl&&r
1305
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element")
!ll&&!rl&&r
1305
MC/DC40%2/5
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and $element->type eq "PPI::Token::Word" and $element->parent->element == $closest_operator->parent->element
builtin::blessed($closest_operator) $closest_operator->isa("PLS::Parser::Element") $closest_operator->name eq "->" $element->type eq "PPI::Token::Word" $element->parent->element == $closest_operator->parent->element
Truth table50%3/6
A and B and C and D and E
A= builtin::blessed($closest_operator)B= $closest_operator->isa("PLS::Parser::Element")C= $closest_operator->name eq "->"D= $element->type eq "PPI::Token::Word"E= $element->parent->element == $closest_operator->parent->element
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1586 and $closest_operator->isa('PLS::Parser::Element')
1587 and $closest_operator->name eq '->'
1588 and $element->type eq 'PPI::Token::Word'
1589 and $element->parent->element == $closest_operator->parent->element)
1590 {
1591 # default to inserting after the arrow
1592 4 my $arrow_range = $closest_operator->range;
1593 my $range = {
1594 start => $arrow_range->{end},
1595 end => $arrow_range->{end}
1596 4 };
1597  
1598 4 my $filter = '';
1599  
1600 # if the next element is a word, it is likely the start of a method name,
1601 # so we want to return it as a filter. we also want the range to be that
1602 # of the next element so that we replace the word when it is selected.
1603 4 ▶ if ( blessed($closest_operator->next_sibling)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($closest_operator->next_sibling) and $closest_operator->next_sibling->isa("PLS::Parser::Element") and $closest_operator->next_sibling->type eq "PPI::Token::Word" and $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number) 4 0 4
Condition33%3/9
builtin::blessed($closest_operator->next_sibling) and $closest_operator->next_sibling->isa("PLS::Parser::Element") and $closest_operator->next_sibling->type eq "PPI::Token::Word" and $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number
!ll&&!rl&&r
004
builtin::blessed($closest_operator->next_sibling) and $closest_operator->next_sibling->isa("PLS::Parser::Element") and $closest_operator->next_sibling->type eq "PPI::Token::Word"
!ll&&!rl&&r
004
builtin::blessed($closest_operator->next_sibling) and $closest_operator->next_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
004
MC/DC0%0/4
builtin::blessed($closest_operator->next_sibling) and $closest_operator->next_sibling->isa("PLS::Parser::Element") and $closest_operator->next_sibling->type eq "PPI::Token::Word" and $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number
builtin::blessed($closest_operator->next_sibling) $closest_operator->next_sibling->isa("PLS::Parser::Element") $closest_operator->next_sibling->type eq "PPI::Token::Word" $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number
Truth table20%1/5
A and B and C and D
A= builtin::blessed($closest_operator->next_sibling)B= $closest_operator->next_sibling->isa("PLS::Parser::Element")C= $closest_operator->next_sibling->type eq "PPI::Token::Word"D= $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1604 and $closest_operator->next_sibling->isa('PLS::Parser::Element')
1605 and $closest_operator->next_sibling->type eq 'PPI::Token::Word'
1606 and $closest_operator->ppi_line_number == $closest_operator->next_sibling->ppi_line_number)
1607 {
1608 4 $filter = $closest_operator->next_sibling->name;
1609 4 $range = $closest_operator->next_sibling->range;
1610 } ## end if (blessed($closest_operator...))
1611  
1612 # if the previous element is a word, it's possibly a class name,
1613 # so we return that to use for searching for that class's methods.
1614 4 my $package = '';
1615  
1616 4 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word" and !(builtin::blessed($closest_operator->previous_sibling->previous_sibling) && $closest_operator->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $closest_operator->previous_sibling->previous_sibling->name ne "->") 2 2 4
Condition60%9/15
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word" and !(builtin::blessed($closest_operator->previous_sibling->previous_sibling) && $closest_operator->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $closest_operator->previous_sibling->previous_sibling->name ne "->"
!ll&&!rl&&r
130
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word"
!ll&&!rl&&r
013
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
004
not builtin::blessed($closest_operator->previous_sibling->previous_sibling) && $closest_operator->previous_sibling->previous_sibling->isa("PLS::Parser::Element") or $closest_operator->previous_sibling->previous_sibling->name ne "->"
l!l&&r!l&&!r
201
builtin::blessed($closest_operator->previous_sibling->previous_sibling) && $closest_operator->previous_sibling->previous_sibling->isa('PLS::Parser::Element')
!ll&&!rl&&r
201
MC/DC0%0/6
builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->type eq "PPI::Token::Word" and !(builtin::blessed($closest_operator->previous_sibling->previous_sibling) && $closest_operator->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $closest_operator->previous_sibling->previous_sibling->name ne "->"
builtin::blessed($closest_operator->previous_sibling) $closest_operator->previous_sibling->isa("PLS::Parser::Element") $closest_operator->previous_sibling->type eq "PPI::Token::Word" builtin::blessed($closest_operator->previous_sibling->previous_sibling) $closest_operator->previous_sibling->previous_sibling->isa('PLS::Parser::Element') $closest_operator->previous_sibling->previous_sibling->name ne "->"
Truth table28%2/7
A and B and C and not(D && E) or F
A= builtin::blessed($closest_operator->previous_sibling)B= $closest_operator->previous_sibling->isa("PLS::Parser::Element")C= $closest_operator->previous_sibling->type eq "PPI::Token::Word"D= builtin::blessed($closest_operator->previous_sibling->previous_sibling)E= $closest_operator->previous_sibling->previous_sibling->isa('PLS::Parser::Element')F= $closest_operator->previous_sibling->previous_sibling->name ne "->"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1111100
1110XX1
11110X1
1111111
1617 blessed($closest_operator->previous_sibling)
1618 and $closest_operator->previous_sibling->isa('PLS::Parser::Element')
1619 and $closest_operator->previous_sibling->type eq 'PPI::Token::Word'
1620 and ( not blessed($closest_operator->previous_sibling->previous_sibling)
1621 or not $closest_operator->previous_sibling->previous_sibling->isa('PLS::Parser::Element')
1622 or $closest_operator->previous_sibling->previous_sibling->name ne '->')
1623 )
1624 {
1625 2 $package = $closest_operator->previous_sibling->name;
1626 } ## end if (blessed($closest_operator...))
1627  
1628 # the 1 indicates that the current token is an arrow, due to the special logic needed.
1629 4 return $range, 1, $package, $filter;
1630 } ## end if (blessed($closest_operator...))
1631  
1632 # This handles the case for when there is an arrow after a variable name
1633 # but the user has not yet started typing the method name.
1634 14 ▶ if ( blessed($closest_operator)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->element == $element->element) 0 14 14
Condition66%10/15
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->element == $element->element
!ll&&!rl&&r
1310
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
1301
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and builtin::blessed($closest_operator->previous_sibling)
!ll&&!rl&&r
1301
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->"
!ll&&!rl&&r
1301
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element")
!ll&&!rl&&r
1301
MC/DC0%0/6
builtin::blessed($closest_operator) and $closest_operator->isa("PLS::Parser::Element") and $closest_operator->name eq "->" and builtin::blessed($closest_operator->previous_sibling) and $closest_operator->previous_sibling->isa("PLS::Parser::Element") and $closest_operator->previous_sibling->element == $element->element
builtin::blessed($closest_operator) $closest_operator->isa("PLS::Parser::Element") $closest_operator->name eq "->" builtin::blessed($closest_operator->previous_sibling) $closest_operator->previous_sibling->isa("PLS::Parser::Element") $closest_operator->previous_sibling->element == $element->element
Truth table28%2/7
A and B and C and D and E and F
A= builtin::blessed($closest_operator)B= $closest_operator->isa("PLS::Parser::Element")C= $closest_operator->name eq "->"D= builtin::blessed($closest_operator->previous_sibling)E= $closest_operator->previous_sibling->isa("PLS::Parser::Element")F= $closest_operator->previous_sibling->element == $element->element
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1635 and $closest_operator->isa('PLS::Parser::Element')
1636 and $closest_operator->name eq '->'
1637 and blessed($closest_operator->previous_sibling)
1638 and $closest_operator->previous_sibling->isa('PLS::Parser::Element')
1639 and $closest_operator->previous_sibling->element == $element->element)
1640 {
1641 0 my $arrow_range = $closest_operator->range;
1642 my $range = {
1643 start => $arrow_range->{end},
1644 end => $arrow_range->{end}
1645 0 };
1646  
1647 0 return $range, 1, '', '';
1648 } ## end if (blessed($closest_operator...))
1649  
1650 # something like "Package::Name:", we just want Package::Name.
1651 14 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($element->name eq ":" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->type eq "PPI::Token::Word" || $element->previous_sibling->type eq "PPI::Token::Label" and !(builtin::blessed($element->previous_sibling->previous_sibling) && $element->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $element->previous_sibling->previous_sibling->name ne "->") 0 14 14
Condition19%4/21
$element->name eq ":" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->type eq "PPI::Token::Word" || $element->previous_sibling->type eq "PPI::Token::Label" and !(builtin::blessed($element->previous_sibling->previous_sibling) && $element->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $element->previous_sibling->previous_sibling->name ne "->"
!ll&&!rl&&r
1400
$element->name eq ":" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->type eq "PPI::Token::Word" || $element->previous_sibling->type eq "PPI::Token::Label"
!ll&&!rl&&r
1400
$element->name eq ":" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element")
!ll&&!rl&&r
1400
$element->name eq ":" and builtin::blessed($element->previous_sibling)
!ll&&!rl&&r
1400
$element->previous_sibling->type eq "PPI::Token::Word" or $element->previous_sibling->type eq "PPI::Token::Label"
l!l&&r!l&&!r
000
not builtin::blessed($element->previous_sibling->previous_sibling) && $element->previous_sibling->previous_sibling->isa("PLS::Parser::Element") or $element->previous_sibling->previous_sibling->name ne "->"
l!l&&r!l&&!r
000
builtin::blessed($element->previous_sibling->previous_sibling) && $element->previous_sibling->previous_sibling->isa('PLS::Parser::Element')
!ll&&!rl&&r
000
MC/DC0%0/8
$element->name eq ":" and builtin::blessed($element->previous_sibling) and $element->previous_sibling->isa("PLS::Parser::Element") and $element->previous_sibling->type eq "PPI::Token::Word" || $element->previous_sibling->type eq "PPI::Token::Label" and !(builtin::blessed($element->previous_sibling->previous_sibling) && $element->previous_sibling->previous_sibling->isa("PLS::Parser::Element")) || $element->previous_sibling->previous_sibling->name ne "->"
$element->name eq ":" builtin::blessed($element->previous_sibling) $element->previous_sibling->isa("PLS::Parser::Element") $element->previous_sibling->type eq "PPI::Token::Word" $element->previous_sibling->type eq "PPI::Token::Label" builtin::blessed($element->previous_sibling->previous_sibling) $element->previous_sibling->previous_sibling->isa('PLS::Parser::Element') $element->previous_sibling->previous_sibling->name ne "->"
Truth table8%1/12
A and B and C and D or E and not(F && G) or H
A= $element->name eq ":"B= builtin::blessed($element->previous_sibling)C= $element->previous_sibling->isa("PLS::Parser::Element")D= $element->previous_sibling->type eq "PPI::Token::Word"E= $element->previous_sibling->type eq "PPI::Token::Label"F= builtin::blessed($element->previous_sibling->previous_sibling)G= $element->previous_sibling->previous_sibling->isa('PLS::Parser::Element')H= $element->previous_sibling->previous_sibling->name ne "->"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
11100XXX0
1111X1100
111011100
1111X0XX1
1111X10X1
1111X1111
111010XX1
1110110X1
111011111
1652 $element->name eq ':'
1653 and blessed($element->previous_sibling)
1654 and $element->previous_sibling->isa('PLS::Parser::Element')
1655 and ( $element->previous_sibling->type eq 'PPI::Token::Word'
1656 or $element->previous_sibling->type eq 'PPI::Token::Label')
1657  
1658 # Check that there isn't another arrow before the previous word - in this case the previous word is likely NOT a package name.
1659 and ( not blessed($element->previous_sibling->previous_sibling)
1660 or not $element->previous_sibling->previous_sibling->isa('PLS::Parser::Element')
1661 or $element->previous_sibling->previous_sibling->name ne '->')
1662 )
1663 {
1664 0 $element = $element->previous_sibling;
1665 } ## end if ($element->name eq ...)
1666  
1667 14 my $range = $element->range;
1668  
1669 # look at labels as well, because a label looks like a package name before the second colon.
1670 14 my $package = '';
1671  
1672 14 ▶ if ( $element->type eq 'PPI::Token::Word'
Branch: 1 branch
BranchTrueFalseTotal
if ($element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label" or $element->element->isa("PPI::Token::Quote") or $element->element->isa("PPI::Token::QuoteLike") or $element->element->isa("PPI::Token::Regexp")) 5 2 7
Condition100%12/12
$element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label" or $element->element->isa("PPI::Token::Quote") or $element->element->isa("PPI::Token::QuoteLike") or $element->element->isa("PPI::Token::Regexp")
l!l&&r!l&&!r
1022
$element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label" or $element->element->isa("PPI::Token::Quote") or $element->element->isa("PPI::Token::QuoteLike")
l!l&&r!l&&!r
734
$element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label" or $element->element->isa("PPI::Token::Quote")
l!l&&r!l&&!r
527
$element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label"
l!l&&r!l&&!r
419
MC/DC100%5/5
$element->type eq "PPI::Token::Word" or $element->type eq "PPI::Token::Label" or $element->element->isa("PPI::Token::Quote") or $element->element->isa("PPI::Token::QuoteLike") or $element->element->isa("PPI::Token::Regexp")
$element->type eq "PPI::Token::Word" $element->type eq "PPI::Token::Label" $element->element->isa("PPI::Token::Quote") $element->element->isa("PPI::Token::QuoteLike") $element->element->isa("PPI::Token::Regexp")
Truth table100%6/6
A or B or C or D or E
A= $element->type eq "PPI::Token::Word"B= $element->type eq "PPI::Token::Label"C= $element->element->isa("PPI::Token::Quote")D= $element->element->isa("PPI::Token::QuoteLike")E= $element->element->isa("PPI::Token::Regexp")
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1673 or $element->type eq 'PPI::Token::Label'
1674 or $element->element->isa('PPI::Token::Quote')
1675 or $element->element->isa('PPI::Token::QuoteLike')
1676 or $element->element->isa('PPI::Token::Regexp'))
1677 {
1678 12 $package = $element->name;
1679 } ## end if ($element->type eq ...)
1680  
1681 14 my $name = $element->name;
1682 14 $name =~ s/:?:$//;
1683  
1684 14 return $range, 0, $package, $name;
1685 } ## end sub find_word_under_cursor
1686  
1687 =head2 get_list_index
1688  
1689 Gets the index within a list where a cursor is.
1690  
1691 This is useful for determining which function parameter the cursor is on
1692 within a function call.
1693  
1694 =cut
1695  
1696 sub get_list_index
1697 {
1698 0 ▶ my ($self, $list, $line, $character) = @_;
Subroutine get_list_index: not called CC=11 SCAR=48.8
Pod documented
1699  
1700 0 ▶ return 0 if (not blessed($list) or not $list->isa('PLS::Parser::Element') or $list->type ne 'PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($list) && $list->isa("PLS::Parser::Element") or $list->type ne "PPI::Structure::List" 0 0 0
Condition0%0/6
not builtin::blessed($list) && $list->isa("PLS::Parser::Element") or $list->type ne "PPI::Structure::List"
l!l&&r!l&&!r
000
builtin::blessed($list) && $list->isa('PLS::Parser::Element')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($list) && $list->isa("PLS::Parser::Element") or $list->type ne "PPI::Structure::List"
builtin::blessed($list) $list->isa('PLS::Parser::Element') $list->type ne "PPI::Structure::List"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($list)B= $list->isa('PLS::Parser::Element')C= $list->type ne "PPI::Structure::List"
ABCresult
0XX1
10X1
1111
1100
1701  
1702 0 ▶ my $find = PPI::Find->new(sub { $_[0]->isa('PPI::Statement::Expression') });
Subroutine __ANON__: not called CC=1 SCAR=6.9
1703 0 my $expr;
1704 0 ▶ $expr = $find->match() if $find->start($list->element);
Branch: 1 branch
BranchTrueFalseTotal
if $find->start($list->element) 0 0 0
1705  
1706 0 ▶ return 0 if (not blessed($expr) or not $expr->isa('PPI::Statement::Expression'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($expr) and $expr->isa("PPI::Statement::Expression") 0 0 0
Condition0%0/3
builtin::blessed($expr) and $expr->isa("PPI::Statement::Expression")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($expr) and $expr->isa("PPI::Statement::Expression")
builtin::blessed($expr) $expr->isa("PPI::Statement::Expression")
Truth table0%0/3
A and B
A= builtin::blessed($expr)B= $expr->isa("PPI::Statement::Expression")
ABresult
0X0
100
111
1707  
1708 0 ▶ my @commas = grep { $_->isa('PPI::Token::Operator') and $_ eq ',' } $expr->schildren;
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Operator") and $_ eq "," 0 0 0
1709  
1710 0 ▶ return 0 unless (scalar @commas);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @commas 0 0 0
1711  
1712 0 my $param_index = -1;
1713  
1714 0 foreach my $index (reverse 0 .. $#commas)
1715 {
1716 0 my $param = $commas[$index];
1717  
1718 0 ▶ if ($param->column_number <= $character)
Branch: 1 branch
BranchTrueFalseTotal
if ($param->column_number <= $character) 0 0 0
1719 {
1720 0 $param_index = $index;
1721 0 last;
1722 }
1723 } ## end foreach my $index (reverse ...)
1724  
1725 0 return $param_index + 1;
1726 } ## end sub get_list_index
1727  
1728 =head2 sort_imports
1729  
1730 This sorts the imports within a file. The order is:
1731  
1732 =over
1733  
1734 =item C<use strict> and C<use warnings>
1735  
1736 =item C<use parent> and C<use base>
1737  
1738 =item Other pragmas (excluding C<use constant>)
1739  
1740 =item Core and external imports
1741  
1742 =item Internal imports (from the current project)
1743  
1744 =item Constants (C<use constant>)
1745  
1746 =back
1747  
1748 =cut
1749  
1750 sub sort_imports
1751 {
1752 0 ▶ my ($self) = @_;
Subroutine sort_imports: not called CC=22 SCAR=62.3
Pod documented
1753  
1754 0 my $doc = $self->{document}->clone();
1755 0 my @installed = ExtUtils::Installed->new->modules;
1756  
1757 # Just strict and warnings - I like them to be first and in their own group
1758 0 my @special_pragmas;
1759  
1760 # parent and base - I like them to be after strict and warnings and in their own group.
1761 my @isa_pragmas;
1762  
1763 # The rest of the pragmas
1764 0 my @pragmas;
1765  
1766 # Group of any modules that are installed (either core or external)
1767 0 my @installed_modules;
1768  
1769 # Group of modules that are part of this project,
1770 # though it gets tricky if this project is also installed
1771 0 my @internal_modules;
1772  
1773 # Put constant pragmas at the very end of all imports
1774 0 my @constant_pragmas;
1775  
1776 0 my $insert_after;
1777  
1778 0 foreach my $child ($doc->children)
1779 {
1780 0 my $seqno;
1781 0 ▶ next unless ($seqno = ($child->isa('PPI::Statement::Include') .. (not $child->isa('PPI::Statement::Include') and not $child->isa('PPI::Token::Whitespace'))));
Branch: 1 branch
BranchTrueFalseTotal
unless $seqno = $child->isa("PPI::Statement::Include") .. !($child->isa("PPI::Statement::Include") || $child->isa("PPI::Token::Whitespace")) 0 0 0
Condition0%0/3
$child->isa('PPI::Statement::Include') || $child->isa('PPI::Token::Whitespace')
l!l&&r!l&&!r
000
MC/DC0%0/2
$child->isa('PPI::Statement::Include') || $child->isa('PPI::Token::Whitespace')
$child->isa('PPI::Statement::Include') $child->isa('PPI::Token::Whitespace')
Truth table0%0/3
A || B
A= $child->isa('PPI::Statement::Include')B= $child->isa('PPI::Token::Whitespace')
ABresult
1X1
011
000
1782 0 ▶ last if ($seqno =~ /E0/);
Branch: 1 branch
BranchTrueFalseTotal
if $seqno =~ /E0/ 0 0 0
1783 0 ▶ $insert_after = $child->previous_sibling if ($seqno eq '1');
Branch: 1 branch
BranchTrueFalseTotal
if $seqno eq 1 0 0 0
1784  
1785 0 ▶ if ($child->isa('PPI::Token::Whitespace'))
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa("PPI::Token::Whitespace")) 0 0 0
1786 {
1787 0 $child->delete;
1788 0 next;
1789 }
1790  
1791 0 ▶ if ($child->pragma eq 'strict' or $child->pragma eq 'warnings')
Branch: 4 branches
BranchTrueFalseTotal
if ($child->pragma eq 'strict' or $child->pragma eq 'warnings') { } 0 0 0
elsif ($child->pragma eq 'parent' or $child->pragma eq 'base') { } 0 0 0
elsif ($child->pragma eq 'constant') { } 0 0 0
elsif (length $child->pragma) { } 0 0 0
Condition0%0/3
$child->pragma eq "strict" or $child->pragma eq "warnings"
l!l&&r!l&&!r
000
MC/DC0%0/2
$child->pragma eq "strict" or $child->pragma eq "warnings"
$child->pragma eq "strict" $child->pragma eq "warnings"
Truth table0%0/3
A or B
A= $child->pragma eq "strict"B= $child->pragma eq "warnings"
ABresult
1X1
011
000
1792 {
1793 0 push @special_pragmas, $child;
1794 }
1795 ▶ elsif ($child->pragma eq 'parent' or $child->pragma eq 'base')
Condition0%0/3
$child->pragma eq "parent" or $child->pragma eq "base"
l!l&&r!l&&!r
000
MC/DC0%0/2
$child->pragma eq "parent" or $child->pragma eq "base"
$child->pragma eq "parent" $child->pragma eq "base"
Truth table0%0/3
A or B
A= $child->pragma eq "parent"B= $child->pragma eq "base"
ABresult
1X1
011
000
1796 {
1797 0 push @isa_pragmas, $child;
1798 }
1799 elsif ($child->pragma eq 'constant')
1800 {
1801 0 push @constant_pragmas, $child;
1802 }
1803 elsif (length $child->pragma)
1804 {
1805 0 push @pragmas, $child;
1806 }
1807 else
1808 {
1809 0 ▶ if (Module::CoreList::is_core($child->module) or any { $child->module =~ /^\Q$_\E/ } @installed)
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (Module::CoreList::is_core($child->module) or &any(sub { $child->module =~ /^\Q$_\E/; } , @installed)) { } 0 0 0
Condition0%0/3
Module::CoreList::is_core($child->module) or &any(sub {
l!l&&r!l&&!r
000
MC/DC0%0/2
Module::CoreList::is_core($child->module) or &any(sub { $child->module =~ /^\Q$_\E/; } , @installed)
Module::CoreList::is_core($child->module) &any(sub { $child->module =~ /^\Q$_\E/; } , @installed)
Truth table0%0/3
A or B
A= Module::CoreList::is_core($child->module)B= &any(sub { $child->module =~ /^\Q$_\E/; } , @installed)
ABresult
1X1
011
000
1810 {
1811 0 push @installed_modules, $child;
1812 }
1813 else
1814 {
1815 0 push @internal_modules, $child;
1816 }
1817 } ## end else [ if ($child->pragma eq ...)]
1818  
1819 0 $child->remove;
1820 } ## end foreach my $child ($doc->children...)
1821  
1822 0 ▶ @special_pragmas = _pad_imports(sort _sort_imports @special_pragmas) if (scalar @special_pragmas);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @special_pragmas 0 0 0
1823 0 ▶ @isa_pragmas = _pad_imports(sort _sort_imports @isa_pragmas) if (scalar @isa_pragmas);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @isa_pragmas 0 0 0
1824 0 ▶ @pragmas = _pad_imports(sort _sort_imports @pragmas) if (scalar @pragmas);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @pragmas 0 0 0
1825 0 ▶ @installed_modules = _pad_imports(sort _sort_imports @installed_modules) if (scalar @installed_modules);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @installed_modules 0 0 0
1826 0 ▶ @internal_modules = _pad_imports(sort _sort_imports @internal_modules) if (scalar @internal_modules);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @internal_modules 0 0 0
1827 0 ▶ @constant_pragmas = _pad_imports(sort _sort_imports @constant_pragmas) if (scalar @constant_pragmas);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @constant_pragmas 0 0 0
1828  
1829 # There doesn't seem to be a better way to do this other than to use this private method.
1830 0 $insert_after->__insert_after(@special_pragmas, @isa_pragmas, @pragmas, @installed_modules, @internal_modules, @constant_pragmas);
1831  
1832 0 open my $fh, '<', $self->get_full_text();
1833  
1834 0 my $lines;
1835  
1836 0 ▶ while (my $line = <$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
1837 {
1838 0 $lines = $.;
1839 }
1840  
1841 0 return \($doc->serialize), $lines;
1842 } ## end sub sort_imports
1843  
1844 =head2 _sort_imports
1845  
1846 Determines the sorting of two imports within a block of imports.
1847  
1848 =cut
1849  
1850 sub _sort_imports
1851 {
1852 0 ▶ return $b->type cmp $a->type || $a->module cmp $b->module;
Subroutine _sort_imports: not called CC=2 SCAR=17.9
Condition0%0/3
$b->type cmp $a->type || $a->module cmp $b->module
l!l&&r!l&&!r
000
MC/DC0%0/2
$b->type cmp $a->type || $a->module cmp $b->module
$b->type cmp $a->type $a->module cmp $b->module
Truth table0%0/3
A || B
A= $b->type cmp $a->typeB= $a->module cmp $b->module
ABresult
1X1
011
000
1853 }
1854  
1855 =head2 _pad_imports
1856  
1857 Adds newlines to pad the various import sections from each other and from
1858 the rest of the document.
1859  
1860 =cut
1861  
1862 sub _pad_imports
1863 {
1864 0 ▶ my @imports = @_;
Subroutine _pad_imports: not called CC=1 SCAR=6.9
1865  
1866 # Newlines between the imports
1867 0 @imports = map { $_, PPI::Token::Whitespace->new("\n") } @imports;
1868  
1869 # An extra newline at the end of the section
1870 0 push @imports, PPI::Token::Whitespace->new("\n");
1871  
1872 0 return @imports;
1873 } ## end sub _pad_imports
1874  
1875 =head2 _split_lines
1876  
1877 Splits a document into lines using C<$/> as the separator.
1878  
1879 =cut
1880  
1881 sub _split_lines
1882 {
1883 0 ▶ my ($text) = @_;
Subroutine _split_lines: not called CC=1 SCAR=6.9
1884  
1885 0 my $sep = $/;
1886 0 return split /(?<=$sep)/, $text;
1887 } ## end sub _split_lines
1888  
1889 11 1;
↑ Summary PLS/Parser/Pod/Subroutine.pm »