blib/lib/PLS/Parser/Document.pm

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