PLS/Parser/Element.pm

filter: Statementstmt 8.2% 13 / 157 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 84 MC/DCmcdc 0.0% 0 / 42 Subroutinesub 12.9% 4 / 31 Podpod 91.3% 21 / 23 totaltotal 9.0% 38 / 419 CC 73 SCAR 45.9
CC
73
Cov
4%
package_name
380.0
_extract_import
90.0
class_method_package_and_name
72.0
CRAP 98.6
« PLS/Parser/Pod/Subroutine.pm ↑ Summary PLS/Server/Request/Diagnostics/PublishDiagnostics.pm »
1 package PLS::Parser::Element;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use List::Util qw(any first);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 PLS::Parser::Element
12  
13 =head1 DESCRIPTION
14  
15 This is an abstraction of a L<PPI::Element> with additional functionality.
16  
17 =head1 METHODS
18  
19 =cut
20  
21 sub new
22 {
23 0 ▶ my ($class, @args) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
24  
25 0 my %args = @args;
26  
27 0 my %self = (ppi_element => $args{element}, file => $args{file}, document => $args{document});
28 0 ▶ return if (not blessed($args{element}) or not $args{element}->isa('PPI::Element'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($args{"element"}) and $args{"element"}->isa("PPI::Element") 0 0 0
Condition0%0/3
builtin::blessed($args{"element"}) and $args{"element"}->isa("PPI::Element")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($args{"element"}) and $args{"element"}->isa("PPI::Element")
builtin::blessed($args{"element"}) $args{"element"}->isa("PPI::Element")
Truth table0%0/3
A and B
A= builtin::blessed($args{"element"})B= $args{"element"}->isa("PPI::Element")
ABresult
0X0
100
111
29 0 return bless \%self, $class;
30 } ## end sub new
31  
32 =head2 ppi_line_number
33  
34 This is the line number of the element according to PPI.
35  
36 =cut
37  
38 sub ppi_line_number
39 {
40 0 ▶ my ($self) = @_;
Subroutine ppi_line_number: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 return $self->element->line_number;
43 }
44  
45 =head2 ppi_column_number
46  
47 This is the column number of the element according to PPI.
48  
49 =cut
50  
51 sub ppi_column_number
52 {
53 0 ▶ my ($self) = @_;
Subroutine ppi_column_number: not called CC=1 SCAR=6.9
Pod documented
54  
55 0 return $self->element->column_number;
56 }
57  
58 =head2 lsp_line_number
59  
60 This is the line number of the element according to the Language Server Protocol.
61  
62 =cut
63  
64 sub lsp_line_number
65 {
66 0 ▶ my ($self) = @_;
Subroutine lsp_line_number: not called CC=1 SCAR=6.9
Pod documented
67  
68 0 return $self->ppi_line_number - 1;
69 }
70  
71 =head2 lsp_column_number
72  
73 This is the column number of the element according to the Language Server Protocol.
74  
75 =cut
76  
77 sub lsp_column_number
78 {
79 0 ▶ my ($self) = @_;
Subroutine lsp_column_number: not called CC=1 SCAR=6.9
Pod documented
80  
81 0 return $self->ppi_column_number - 1;
82 }
83  
84 =head2 location_info
85  
86 This is information about the location of the element, to be stored in the index.
87  
88 =cut
89  
90 sub location_info
91 {
92 0 ▶ my ($self) = @_;
Subroutine location_info: not called CC=1 SCAR=6.9
Pod documented
93  
94 return {
95 file => $self->{file},
96 0 location => {
97 line_number => $self->lsp_line_number,
98 column_number => $self->lsp_column_number
99 }
100 };
101 } ## end sub location_info
102  
103 =head2 content
104  
105 This is the content of the element.
106 This is the same as L<PPI::Element::content>.
107  
108 =cut
109  
110 sub content
111 {
112 0 ▶ my ($self) = @_;
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
113  
114 0 return $self->element->content;
115 }
116  
117 =head2 name
118  
119 This is the name of the element.
120 This is the same as the result of C<content>, in the base class.
121  
122 =cut
123  
124 sub name
125 {
126 0 ▶ my ($self) = @_;
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
127  
128 0 return $self->content;
129 }
130  
131 =head2 package_name
132  
133 This finds a package name at the given column number inside this element.
134  
135 =cut
136  
137 sub package_name
138 {
139 0 ▶ my ($self, $column_number) = @_;
Subroutine package_name: not called CC=19 SCAR=59.4
Pod documented
140  
141 0 my $element = $self->element;
142 0 $column_number++;
143  
144 0 ▶ if ( blessed($element->statement)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use") 0 0 0
Condition0%0/6
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use"
!ll&&!rl&&r
000
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use"
builtin::blessed($element->statement) $element->statement->isa("PPI::Statement::Include") $element->statement->type eq "use"
Truth table0%0/4
A and B and C
A= builtin::blessed($element->statement)B= $element->statement->isa("PPI::Statement::Include")C= $element->statement->type eq "use"
ABCresult
0XX0
10X0
1100
1111
145 and $element->statement->isa('PPI::Statement::Include')
146 and $element->statement->type eq 'use')
147 {
148 # This is a 'use parent/base' statement. The import is a package, not a subroutine.
149 0 ▶ if ($element->statement->module eq 'parent' or $element->statement->module eq 'base')
Branch: 1 branch
BranchTrueFalseTotal
if ($element->statement->module eq "parent" or $element->statement->module eq "base") 0 0 0
Condition0%0/3
$element->statement->module eq "parent" or $element->statement->module eq "base"
l!l&&r!l&&!r
000
MC/DC0%0/2
$element->statement->module eq "parent" or $element->statement->module eq "base"
$element->statement->module eq "parent" $element->statement->module eq "base"
Truth table0%0/3
A or B
A= $element->statement->module eq "parent"B= $element->statement->module eq "base"
ABresult
1X1
011
000
150 {
151 0 my $import = _extract_import($element, $column_number);
152 0 ▶ return $import if (length $import);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $import 0 0 0
153 }
154  
155 # This is likely a 'use' statement with an explicit subroutine import.
156 0 my $package = $element->statement->module;
157 0 my $import = _extract_import($element, $column_number);
158 0 ▶ return $element->statement->module, $import if (length $import);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $import 0 0 0
159 } ## end if (blessed($element->...))
160  
161 # Regular use statement, no explicit imports
162 0 ▶ if (blessed($element->statement) and $element->statement->isa('PPI::Statement::Include') and $element->statement->type eq 'use')
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use") 0 0 0
Condition0%0/6
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use"
!ll&&!rl&&r
000
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Include") and $element->statement->type eq "use"
builtin::blessed($element->statement) $element->statement->isa("PPI::Statement::Include") $element->statement->type eq "use"
Truth table0%0/4
A and B and C
A= builtin::blessed($element->statement)B= $element->statement->isa("PPI::Statement::Include")C= $element->statement->type eq "use"
ABCresult
0XX0
10X0
1100
1111
163 {
164 0 return $element->statement->module;
165 }
166  
167 # Class method call, cursor is over the package name
168 0 ▶ if ( $element->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::Word") and ref $element->snext_sibling eq "PPI::Token::Operator" and $element->snext_sibling eq "->") 0 0 0
Condition0%0/6
$element->isa("PPI::Token::Word") and ref $element->snext_sibling eq "PPI::Token::Operator" and $element->snext_sibling eq "->"
!ll&&!rl&&r
000
$element->isa("PPI::Token::Word") and ref $element->snext_sibling eq "PPI::Token::Operator"
!ll&&!rl&&r
000
MC/DC0%0/3
$element->isa("PPI::Token::Word") and ref $element->snext_sibling eq "PPI::Token::Operator" and $element->snext_sibling eq "->"
$element->isa("PPI::Token::Word") ref $element->snext_sibling eq "PPI::Token::Operator" $element->snext_sibling eq "->"
Truth table0%0/4
A and B and C
A= $element->isa("PPI::Token::Word")B= ref $element->snext_sibling eq "PPI::Token::Operator"C= $element->snext_sibling eq "->"
ABCresult
0XX0
10X0
1100
1111
169 and ref $element->snext_sibling eq 'PPI::Token::Operator'
170 and $element->snext_sibling eq '->')
171 {
172 0 return $element->content;
173 } ## end if ($element->isa('PPI::Token::Word'...))
174  
175 # Declaring parent class using @ISA directly.
176 0 ▶ if ( blessed($element->statement)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Variable") and $element->statement->type eq "our" and &any(sub { $_->symbol eq "\@ISA"; } , $element->statement->symbols)) 0 0 0
Condition0%0/9
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Variable") and $element->statement->type eq "our" and &any(sub {
!ll&&!rl&&r
000
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Variable") and $element->statement->type eq "our"
!ll&&!rl&&r
000
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Variable")
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::blessed($element->statement) and $element->statement->isa("PPI::Statement::Variable") and $element->statement->type eq "our" and &any(sub { $_->symbol eq "\@ISA"; } , $element->statement->symbols)
builtin::blessed($element->statement) $element->statement->isa("PPI::Statement::Variable") $element->statement->type eq "our" &any(sub { $_->symbol eq "\@ISA"; } , $element->statement->symbols)
Truth table0%0/5
A and B and C and D
A= builtin::blessed($element->statement)B= $element->statement->isa("PPI::Statement::Variable")C= $element->statement->type eq "our"D= &any(sub { $_->symbol eq "\@ISA"; } , $element->statement->symbols)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
177 and $element->statement->isa('PPI::Statement::Variable')
178 and $element->statement->type eq 'our'
179 0 ▶ and any { $_->symbol eq '@ISA' } $element->statement->symbols)
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 {
181 0 my $import = _extract_import($element, $column_number);
182 0 ▶ return $import if (length $import);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $import 0 0 0
183 } ## end if (blessed($element->...))
184  
185 0 return;
186 } ## end sub package_name
187  
188 =head2 method_name
189  
190 This finds a method name in the current element.
191  
192 =cut
193  
194 sub method_name
195 {
196 0 ▶ my ($self) = @_;
Subroutine method_name: not called CC=6 SCAR=37.4
Pod documented
197  
198 0 my $element = $self->element;
199  
200 return
201 0 ▶ if ( not blessed($element)
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($element) && $element->isa("PPI::Token::Word") && builtin::blessed($element->sprevious_sibling) && $element->sprevious_sibling->isa("PPI::Token::Operator") or $element->sprevious_sibling ne "->" 0 0 0
Condition0%0/12
not builtin::blessed($element) && $element->isa("PPI::Token::Word") && builtin::blessed($element->sprevious_sibling) && $element->sprevious_sibling->isa("PPI::Token::Operator") or $element->sprevious_sibling ne "->"
l!l&&r!l&&!r
000
builtin::blessed($element) && $element->isa('PPI::Token::Word') && builtin::blessed($element->sprevious_sibling) && $element->sprevious_sibling->isa('PPI::Token::Operator')
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling)
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
MC/DC0%0/5
not builtin::blessed($element) && $element->isa("PPI::Token::Word") && builtin::blessed($element->sprevious_sibling) && $element->sprevious_sibling->isa("PPI::Token::Operator") or $element->sprevious_sibling ne "->"
builtin::blessed($element) $element->isa("PPI::Token::Word") builtin::blessed($element->sprevious_sibling) $element->sprevious_sibling->isa('PPI::Token::Operator') $element->sprevious_sibling ne "->"
Truth table0%0/6
not(A and B and C && D) or E
A= builtin::blessed($element)B= $element->isa("PPI::Token::Word")C= builtin::blessed($element->sprevious_sibling)D= $element->sprevious_sibling->isa('PPI::Token::Operator')E= $element->sprevious_sibling ne "->"
ABCDEresult
0XXXX1
10XXX1
110XX1
1110X1
111111
111100
202 or not $element->isa('PPI::Token::Word')
203 or not blessed($element->sprevious_sibling)
204 or not $element->sprevious_sibling->isa('PPI::Token::Operator')
205 or $element->sprevious_sibling ne '->');
206  
207 0 return $element->content;
208 } ## end sub method_name
209  
210 =head2 class_method_package_and_name
211  
212 This finds a class method within the current element and returns the class and method name.
213  
214 =cut
215  
216 sub class_method_package_and_name
217 {
218 0 ▶ my ($self) = @_;
Subroutine class_method_package_and_name: not called CC=8 SCAR=42.8
Pod documented
219  
220 0 my $element = $self->element;
221  
222 return
223 0 ▶ if ( not blessed($element)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator") and $element->sprevious_sibling eq "->" and builtin::blessed($element->sprevious_sibling->sprevious_sibling) and $element->sprevious_sibling->sprevious_sibling->isa("PPI::Token::Word") 0 0 0
Condition0%0/18
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator") and $element->sprevious_sibling eq "->" and builtin::blessed($element->sprevious_sibling->sprevious_sibling) and $element->sprevious_sibling->sprevious_sibling->isa("PPI::Token::Word")
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator") and $element->sprevious_sibling eq "->" and builtin::blessed($element->sprevious_sibling->sprevious_sibling)
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator") and $element->sprevious_sibling eq "->"
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator")
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling)
!ll&&!rl&&r
000
builtin::blessed($element) and $element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
MC/DC0%0/7
builtin::blessed($element) and $element->isa("PPI::Token::Word") and builtin::blessed($element->sprevious_sibling) and $element->sprevious_sibling->isa("PPI::Token::Operator") and $element->sprevious_sibling eq "->" and builtin::blessed($element->sprevious_sibling->sprevious_sibling) and $element->sprevious_sibling->sprevious_sibling->isa("PPI::Token::Word")
builtin::blessed($element) $element->isa("PPI::Token::Word") builtin::blessed($element->sprevious_sibling) $element->sprevious_sibling->isa("PPI::Token::Operator") $element->sprevious_sibling eq "->" builtin::blessed($element->sprevious_sibling->sprevious_sibling) $element->sprevious_sibling->sprevious_sibling->isa("PPI::Token::Word")
Truth table0%0/8
A and B and C and D and E and F and G
A= builtin::blessed($element)B= $element->isa("PPI::Token::Word")C= builtin::blessed($element->sprevious_sibling)D= $element->sprevious_sibling->isa("PPI::Token::Operator")E= $element->sprevious_sibling eq "->"F= builtin::blessed($element->sprevious_sibling->sprevious_sibling)G= $element->sprevious_sibling->sprevious_sibling->isa("PPI::Token::Word")
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
224 or not $element->isa('PPI::Token::Word')
225 or not blessed($element->sprevious_sibling)
226 or not $element->sprevious_sibling->isa('PPI::Token::Operator')
227 or not $element->sprevious_sibling eq '->'
228 or not blessed($element->sprevious_sibling->sprevious_sibling)
229 or not $element->sprevious_sibling->sprevious_sibling->isa('PPI::Token::Word'));
230  
231 0 return ($element->sprevious_sibling->sprevious_sibling->content, $element->content);
232 } ## end sub class_method_package_and_name
233  
234 =head2 subroutine_package_and_name
235  
236 This finds a fully qualified function call within this element and returns the package
237 and function name.
238  
239 =cut
240  
241 sub subroutine_package_and_name
242 {
243 0 ▶ my ($self) = @_;
Subroutine subroutine_package_and_name: not called CC=4 SCAR=30.0
Pod documented
244  
245 0 my $element = $self->element;
246  
247 0 ▶ return if (not blessed($element) or not $element->isa('PPI::Token::Word'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($element) and $element->isa("PPI::Token::Word") 0 0 0
Condition0%0/3
builtin::blessed($element) and $element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($element) and $element->isa("PPI::Token::Word")
builtin::blessed($element) $element->isa("PPI::Token::Word")
Truth table0%0/3
A and B
A= builtin::blessed($element)B= $element->isa("PPI::Token::Word")
ABresult
0X0
100
111
248  
249 0 ▶ if ($element->content =~ /::/)
Branch: 1 branch
BranchTrueFalseTotal
if ($element->content =~ /::/) { } 0 0 0
250 {
251 0 my @parts = split /::/, $element->content;
252 0 my $subroutine = pop @parts;
253 0 my $package = join '::', @parts;
254 0 return $package, $subroutine;
255 } ## end if ($element->content ...)
256 else
257 {
258 0 return '', $element->content;
259 }
260  
261 0 return;
262 } ## end sub subroutine_package_and_name
263  
264 =head2 variable_name
265  
266 This finds a variable in the current element and returns its name.
267  
268 =cut
269  
270 sub variable_name
271 {
272 0 ▶ my ($self) = @_;
Subroutine variable_name: not called CC=3 SCAR=24.8
Pod documented
273  
274 0 my $element = $self->element;
275 0 ▶ return if (not blessed($element) or not $element->isa('PPI::Token::Symbol'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($element) and $element->isa("PPI::Token::Symbol") 0 0 0
Condition0%0/3
builtin::blessed($element) and $element->isa("PPI::Token::Symbol")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($element) and $element->isa("PPI::Token::Symbol")
builtin::blessed($element) $element->isa("PPI::Token::Symbol")
Truth table0%0/3
A and B
A= builtin::blessed($element)B= $element->isa("PPI::Token::Symbol")
ABresult
0X0
100
111
276  
277 0 return $element->symbol;
278 } ## end sub variable_name
279  
280 =head2 cursor_on_package
281  
282 This determines if the cursor at the given column number is on a package name.
283  
284 =cut
285  
286 sub cursor_on_package
287 {
288 0 ▶ my ($self, $column_number) = @_;
Subroutine cursor_on_package: not called CC=4 SCAR=30.0
Pod documented
289  
290 0 my $element = $self->element;
291  
292 0 my $index = $column_number - $element->column_number;
293 0 my @parts = split /::/, $element->content;
294 0 my $current_index = 1;
295  
296 0 ▶ for (my $i = 0 ; $i <= $#parts ; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#parts) 0 0 0
297 {
298 0 my $part = $parts[$i];
299  
300 0 ▶ if ($index <= $current_index + length $part)
Branch: 1 branch
BranchTrueFalseTotal
if ($index <= $current_index + CORE::length($part)) 0 0 0
301 {
302 0 ▶ return 0 if ($i == $#parts);
Branch: 1 branch
BranchTrueFalseTotal
if $i == $#parts 0 0 0
303 0 pop @parts;
304 0 return 1;
305 } ## end if ($index <= $current_index...)
306  
307 0 $current_index += length $part;
308 } ## end for (my $i = 0 ; $i <= ...)
309  
310 0 return;
311 } ## end sub cursor_on_package
312  
313 =head2 _extract_import
314  
315 This extracts an import within a C<use> statement, which may be a package or function name.
316  
317 =cut
318  
319 sub _extract_import
320 {
321 0 ▶ my ($element, $column_number) = @_;
Subroutine _extract_import: not called CC=9 SCAR=45.0
322  
323 # Single import, single quotes or 'q' string.
324 0 ▶ if ($element->isa('PPI::Token::Quote::Single') or $element->isa('PPI::Token::Quote::Literal'))
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Quote::Literal")) 0 0 0
Condition0%0/3
$element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Quote::Literal")
l!l&&r!l&&!r
000
MC/DC0%0/2
$element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Quote::Literal")
$element->isa("PPI::Token::Quote::Single") $element->isa("PPI::Token::Quote::Literal")
Truth table0%0/3
A or B
A= $element->isa("PPI::Token::Quote::Single")B= $element->isa("PPI::Token::Quote::Literal")
ABresult
1X1
011
000
325 {
326 0 return $element->literal;
327 }
328  
329 # Single import, double quotes or 'qq' string.
330 0 ▶ if ($element->isa('PPI::Token::Quote::Double') or $element->isa('PPI::Token::Quote::Interpolate'))
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Interpolate")) 0 0 0
Condition0%0/3
$element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Interpolate")
l!l&&r!l&&!r
000
MC/DC0%0/2
$element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Interpolate")
$element->isa("PPI::Token::Quote::Double") $element->isa("PPI::Token::Quote::Interpolate")
Truth table0%0/3
A or B
A= $element->isa("PPI::Token::Quote::Double")B= $element->isa("PPI::Token::Quote::Interpolate")
ABresult
1X1
011
000
331 {
332 0 return $element->string;
333 }
334  
335 # Multiple imports, 'qw' list.
336 0 ▶ if ($element->isa('PPI::Token::QuoteLike::Words'))
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::QuoteLike::Words")) 0 0 0
337 {
338 0 my $import = _get_string_from_qw($element, $column_number);
339 0 ▶ return $import if (length $import);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $import 0 0 0
340 }
341  
342 # Multiple imports, using a list.
343 0 ▶ if ($element->isa('PPI::Structure::List'))
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Structure::List")) 0 0 0
344 {
345 0 my $import = _get_string_from_list($element, $column_number);
346 0 ▶ return $import if (length $import);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $import 0 0 0
347 }
348  
349 0 return;
350 } ## end sub _extract_import
351  
352 =head2 _get_string_from_list
353  
354 This finds the string in a list at a given column number.
355  
356 =cut
357  
358 sub _get_string_from_list
359 {
360 0 ▶ my ($element, $column_number) = @_;
Subroutine _get_string_from_list: not called CC=8 SCAR=42.8
361  
362 0 foreach my $expr ($element->children)
363 {
364 0 ▶ next unless $expr->isa('PPI::Statement::Expression');
Branch: 1 branch
BranchTrueFalseTotal
unless $expr->isa("PPI::Statement::Expression") 0 0 0
365  
366 0 foreach my $item ($expr->children)
367 {
368 # Only handle quoted strings. Could be another or list, but that's too complicated.
369 0 ▶ next unless $item->isa('PPI::Token::Quote');
Branch: 1 branch
BranchTrueFalseTotal
unless $item->isa("PPI::Token::Quote") 0 0 0
370  
371 0 ▶ if ($item->column_number <= $column_number and ($item->column_number + length $item->content) >= $column_number)
Branch: 1 branch
BranchTrueFalseTotal
if ($item->column_number <= $column_number and $item->column_number + CORE::length($item->content) >= $column_number) 0 0 0
Condition0%0/3
$item->column_number <= $column_number and $item->column_number + CORE::length($item->content) >= $column_number
!ll&&!rl&&r
000
MC/DC0%0/2
$item->column_number <= $column_number and $item->column_number + CORE::length($item->content) >= $column_number
$item->column_number <= $column_number $item->column_number + CORE::length($item->content) >= $column_number
Truth table0%0/3
A and B
A= $item->column_number <= $column_numberB= $item->column_number + CORE::length($item->content) >= $column_number
ABresult
0X0
100
111
372 {
373 0 ▶ return $item->literal if ($item->can('literal'));
Branch: 1 branch
BranchTrueFalseTotal
if $item->can("literal") 0 0 0
374 0 return $item->string;
375 }
376 } ## end foreach my $item ($expr->children...)
377 } ## end foreach my $expr ($element->...)
378 } ## end sub _get_string_from_list
379  
380 =head2 _get_string_from_qw
381  
382 This gets a string from a C<qw> quoted list at a given column number.
383  
384 =cut
385  
386 sub _get_string_from_qw
387 {
388 0 ▶ my ($element, $column_number) = @_;
Subroutine _get_string_from_qw: not called CC=6 SCAR=37.4
389  
390 0 my ($content) = $element->content =~ /qw[[:graph:]](.+)[[:graph:]]/;
391 0 ▶ return unless (length $content);
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $content 0 0 0
392 0 my @words = split /(\s+)/, $content;
393 0 my $current_column = $element->column_number + 3;
394  
395 # Figure out which word the mouse is hovering on.
396 0 foreach my $word (@words)
397 {
398 0 my $next_start = $current_column + length $word;
399  
400 0 ▶ if ($word !~ /^\s*$/ and $current_column <= $column_number and $next_start > $column_number)
Branch: 1 branch
BranchTrueFalseTotal
if (not $word =~ /^\s*$/ and $current_column <= $column_number and $next_start > $column_number) 0 0 0
Condition0%0/6
not $word =~ /^\s*$/ and $current_column <= $column_number and $next_start > $column_number
!ll&&!rl&&r
000
not $word =~ /^\s*$/ and $current_column <= $column_number
!ll&&!rl&&r
000
MC/DC0%0/3
not $word =~ /^\s*$/ and $current_column <= $column_number and $next_start > $column_number
not $word =~ /^\s*$/ $current_column <= $column_number $next_start > $column_number
Truth table0%0/4
not(A) and B and C
A= not $word =~ /^\s*$/B= $current_column <= $column_numberC= $next_start > $column_number
ABCresult
0XX0
10X0
1100
1111
401 {
402 0 return $word;
403 }
404  
405 0 $current_column = $next_start;
406 } ## end foreach my $word (@words)
407 } ## end sub _get_string_from_qw
408  
409 =head2 range
410  
411 This provides the range where this element is located, in a format the
412 Language Server Protocol can understand.
413  
414 =cut
415  
416 sub range
417 {
418 0 ▶ my ($self) = @_;
Subroutine range: not called CC=3 SCAR=24.8
Pod documented
419  
420 0 my $lines = () = $self->element->content =~ m{($/)}g;
421 0 my ($last_line) = $self->element->content =~ m{(.+)$/$};
422 0 ▶ my $last_line_length = defined $last_line ? length $last_line : length $self->element->content;
Branch: 1 branch
BranchTrueFalseTotal
defined $last_line ? : 0 0 0
423  
424 return {
425 0 ▶ start => {
Branch: 1 branch
BranchTrueFalseTotal
$lines == 0 ? : 0 0 0
426 line => $self->lsp_line_number,
427 character => $self->lsp_column_number
428 },
429 end => {
430 line => $self->lsp_line_number + $lines,
431 character => $lines == 0 ? $self->lsp_column_number + $last_line_length : $last_line_length
432 }
433 };
434 } ## end sub range
435  
436 =head2 length
437  
438 This returns the length of this element.
439  
440 =cut
441  
442 sub length
443 {
444 0 ▶ my ($self) = @_;
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
445  
446 0 return length $self->name;
447 }
448  
449 =head2 parent
450  
451 This returns the parent element of this element, as a L<PLS::Parser::Element> object.
452  
453 =cut
454  
455 sub parent
456 {
457 0 ▶ my ($self) = @_;
Subroutine parent: not called CC=3 SCAR=24.8
Pod documented
458  
459 0 ▶ return $self->{_parent} if (ref $self->{_parent} eq 'PLS::Parser::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_parent"} eq "PLS::Parser::Element" 0 0 0
460 0 ▶ return unless $self->element->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->element->parent 0 0 0
461 0 return PLS::Parser::Element->new(file => $self->{file}, element => $self->element->parent);
462 } ## end sub parent
463  
464 =head2 previous_sibling
465  
466 This returns the previous significant sibling of this element, as a L<PLS::Parser::Element> object.
467  
468 =cut
469  
470 sub previous_sibling
471 {
472 0 ▶ my ($self) = @_;
Subroutine previous_sibling: not called CC=3 SCAR=24.8
Pod documented
473  
474 0 ▶ return $self->{_previous_sibling} if (ref $self->{_previous_sibling} eq 'PLS::Parser::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_previous_sibling"} eq "PLS::Parser::Element" 0 0 0
475 0 ▶ return unless $self->element->sprevious_sibling;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->element->sprevious_sibling 0 0 0
476 0 $self->{_previous_sibling} = PLS::Parser::Element->new(file => $self->{file}, element => $self->element->sprevious_sibling);
477 0 return $self->{_previous_sibling};
478 } ## end sub previous_sibling
479  
480 =head2 previous_sibling
481  
482 This returns the next significant sibling of this element, as a L<PLS::Parser::Element> object.
483  
484 =cut
485  
486 sub next_sibling
487 {
488 0 ▶ my ($self) = @_;
Subroutine next_sibling: not called CC=3 SCAR=24.8
Pod undocumented
489  
490 0 ▶ return $self->{_next_sibling} if (ref $self->{_next_sibling} eq 'PLS::Parser::Element');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_next_sibling"} eq "PLS::Parser::Element" 0 0 0
491 0 ▶ return unless $self->element->snext_sibling;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->element->snext_sibling 0 0 0
492 0 $self->{_next_sibling} = PLS::Parser::Element->new(file => $self->{file}, element => $self->element->snext_sibling);
493 0 return $self->{_next_sibling};
494 } ## end sub next_sibling
495  
496 =head2 children
497  
498 This returns all of this element's children, as L<PLS::Parser::Element> objects.
499  
500 =cut
501  
502 sub children
503 {
504 0 ▶ my ($self) = @_;
Subroutine children: not called CC=3 SCAR=24.8
Pod documented
505  
506 0 ▶ return @{$self->{_children}} if (ref $self->{_children} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_children"} eq "ARRAY" 0 0 0
507 0 ▶ return unless $self->element->can('children');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->element->can("children") 0 0 0
508 0 $self->{_children} = [map { PLS::Parser::Element->new(file => $self->{file}, element => $_) } $self->element->children];
509 0 return @{$self->{_children}};
510 } ## end sub children
511  
512 =head2 tokens
513  
514 This returns all the tokens in the current element, as L<PLS::Parser::Element> objects.
515 Tokens correspond to all of the L<PPI::Token> objects in the current element.
516  
517 =cut
518  
519 sub tokens
520 {
521 0 ▶ my ($self) = @_;
Subroutine tokens: not called CC=3 SCAR=24.8
Pod documented
522  
523 0 ▶ return @{$self->{_tokens}} if (ref $self->{_tokens} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_tokens"} eq "ARRAY" 0 0 0
524 0 ▶ return unless $self->element->can('tokens');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->element->can("tokens") 0 0 0
525 0 $self->{_tokens} = [map { PLS::Parser::Element->new(file => $self->{file}, element => $_) } $self->element->tokens];
526 0 return @{$self->{_tokens}};
527 } ## end sub tokens
528  
529 =head2 element
530  
531 Returns the L<PPI::Element> object for this element.
532  
533 =cut
534  
535 sub element
536 {
537 0 ▶ my ($self) = @_;
Subroutine element: not called CC=1 SCAR=6.9
Pod documented
538  
539 0 return $self->{ppi_element};
540 }
541  
542 =head2 type
543  
544 Returns the type of L<PPI::Element> that this element is associated with.
545  
546 =cut
547  
548 sub type
549 {
550 0 ▶ my ($self) = @_;
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
551  
552 0 return ref $self->element;
553 }
554  
555 1 1;
« PLS/Parser/Pod/Subroutine.pm ↑ Summary PLS/Server/Request/Diagnostics/PublishDiagnostics.pm »