PLS/Parser/Index.pm

filter: Statementstmt 16.8% 50 / 297 Branchbran 0.0% 0 / 102 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 37.2% 16 / 43 Podpod 0.0% 0 / 19 totaltotal 13.6% 66 / 485 CC 67 SCAR 42.5
CC
67
Cov
12%
_cleanup_old_files
306.0
__ANON__
72.0
is_perl_file
72.0
CRAP 70.2
« PLS/Server/Method/TextDocument.pm ↑ Summary PLS/Server/Request/Workspace/Configuration.pm »
1 package PLS::Parser::Index;
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 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Coro;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Coro::AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use List::Util qw(all any);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use PLS::Trie;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use constant {INDEX_LOCATION => File::Spec->catfile('.pls_cache', 'index')};
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 my $indexing_semaphore = Coro::Semaphore->new();
24  
25 sub new
26 {
27 0 ▶ my ($class, @args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 0 my %args = @args;
30  
31 my %self = (
32 root => $args{root},
33 0 location => File::Spec->catfile($args{root}, INDEX_LOCATION),
34 cache => {},
35 subs_trie => PLS::Trie->new(),
36 packages_trie => PLS::Trie->new(),
37 last_mtime => 0,
38 retrieve_index_semaphore => Coro::Semaphore->new()
39 );
40  
41 0 return bless \%self, $class;
42 } ## end sub new
43  
44 sub load_trie
45 {
46 0 ▶ my ($self) = @_;
Subroutine load_trie: not called CC=3 SCAR=24.8
Pod undocumented
47  
48 0 my $index = $self->index();
49  
50 0 foreach my $sub (keys %{$index->{subs}})
51 {
52 0 my $count = scalar @{$index->{subs}{$sub}};
53 0 $self->{subs_trie}->insert($sub, 1);
54 }
55  
56 0 foreach my $package (keys %{$index->{packages}})
57 {
58 0 my $count = scalar @{$index->{packages}{$package}};
59 0 $self->{packages_trie}->insert($package, 1);
60 }
61 } ## end sub load_trie
62  
63 sub index_files
64 {
65 0 ▶ my ($self, @files) = @_;
Subroutine index_files: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 async
68 {
69 0 ▶ my ($self, @files) = @_;
Subroutine __ANON__: not called CC=8 SCAR=42.8
70  
71 0 my $lock = $self->lock();
72 0 my $index = $self->index();
73  
74 0 ▶ unless (scalar @files)
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @files) 0 0 0
75 {
76 0 @files = @{$self->get_all_perl_files()};
77 0 $self->_cleanup_old_files($index);
78 0 ▶ @files = grep { not exists $index->{files}{$_}{last_mtime} or not length $index->{files}{$_}{last_mtime} and $index->{files}{$_}{last_mtime} < stat($_)->mtime } @files;
Branch: 1 branch
BranchTrueFalseTotal
not exists $index->{"files"}{$_}{"last_mtime"} or not length $index->{"files"}{$_}{"last_mtime"} and $index->{"files"}{$_}{"last_mtime"} < &PLS::Parser::Index::stat($_)->mtime 0 0 0
Condition0%0/6
!exists $index->{'files'}{$_}{'last_mtime'} || !length($index->{'files'}{$_}{'last_mtime'}) && $index->{'files'}{$_}{'last_mtime'} < &PLS::Parser::Index::stat($_)->mtime
l!l&&r!l&&!r
000
not length $index->{"files"}{$_}{"last_mtime"} and $index->{"files"}{$_}{"last_mtime"} < &PLS::Parser::Index::stat($_)->mtime
!ll&&!rl&&r
000
MC/DC0%0/3
!exists $index->{'files'}{$_}{'last_mtime'} || !length($index->{'files'}{$_}{'last_mtime'}) && $index->{'files'}{$_}{'last_mtime'} < &PLS::Parser::Index::stat($_)->mtime
!exists $index->{'files'}{$_}{'last_mtime'} not length $index->{"files"}{$_}{"last_mtime"} $index->{"files"}{$_}{"last_mtime"} < &PLS::Parser::Index::stat($_)->mtime
Truth table0%0/4
not(A) || not(B) and C
A= !exists $index->{'files'}{$_}{'last_mtime'}B= not length $index->{"files"}{$_}{"last_mtime"}C= $index->{"files"}{$_}{"last_mtime"} < &PLS::Parser::Index::stat($_)->mtime
ABCresult
1XX1
0111
00X0
0100
79 } ## end unless (scalar @files)
80  
81 0 my $total = scalar @files;
82 0 my $current = 0;
83  
84 0 foreach my $file (@files)
85 {
86 0 $current++;
87  
88 0 ▶ open my $fh, '<', $file or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or next 0 0 0
89 0 my $text = do { local $/; <$fh> };
90 0 my $document = PLS::Parser::Document->new(path => $file, text => \$text, no_cache => 1);
91 0 ▶ next unless (ref $document eq 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "PLS::Parser::Document" 0 0 0
92  
93 0 Coro::AnyEvent::sleep 0.01;
94  
95 0 my $log_message = "Indexing $file";
96 0 ▶ $log_message .= " ($current/$total)" if (scalar @files > 1);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @files > 1 0 0 0
97 0 $log_message .= '...';
98  
99 0 $self->log($log_message);
100  
101 0 $self->update_subroutines($index, $document);
102 0 Coro::AnyEvent::sleep 0.01;
103 0 $self->update_packages($index, $document);
104 0 Coro::AnyEvent::sleep 0.01;
105 } ## end foreach my $file (@files)
106  
107 0 $self->save($index);
108 } ## end async
109 0 $self, @files;
110 } ## end sub index_files
111  
112 sub lock
113 {
114 0 ▶ return $indexing_semaphore->guard();
Subroutine lock: not called CC=1 SCAR=6.9
Pod undocumented
115 }
116  
117 sub save
118 {
119 0 ▶ my ($self, $index) = @_;
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
120  
121 0 my (undef, $parent_dir) = File::Spec->splitpath($self->{location});
122 0 File::Path::make_path($parent_dir);
123  
124 0 Storable::nstore($index, $self->{location});
125 0 $self->{cache} = $index;
126 0 $self->{last_mtime} = (stat $self->{location})->mtime;
127 } ## end sub save
128  
129 sub index
130 {
131 0 ▶ my ($self) = @_;
Subroutine index: not called CC=3 SCAR=24.8
Pod undocumented
132  
133 0 ▶ return {} unless -f $self->{location};
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->{"location"} 0 0 0
134  
135 # Don't have two coroutines retrieving the index at the same time
136 0 my $guard = $self->{retrieve_index_semaphore}->guard();
137 0 my $mtime = (stat $self->{location})->mtime;
138 0 ▶ return $self->{cache} if ($mtime <= $self->{last_mtime});
Branch: 1 branch
BranchTrueFalseTotal
if $mtime <= $self->{"last_mtime"} 0 0 0
139  
140 0 $self->{last_mtime} = $mtime;
141 0 $self->{cache} = Storable::retrieve($self->{location});
142  
143 0 return $self->{cache};
144 } ## end sub index
145  
146 sub update_subroutines
147 {
148 0 ▶ my ($self, $index, $document) = @_;
Subroutine update_subroutines: not called CC=1 SCAR=6.9
Pod undocumented
149  
150 0 my $subroutines = $document->get_subroutines();
151 0 my $constants = $document->get_constants();
152  
153 0 $self->cleanup_index($index, 'subs', $document->{path});
154 0 $self->update_index($index, 'subs', $document->{path}, @$subroutines, @$constants);
155 } ## end sub update_subroutines
156  
157 sub update_packages
158 {
159 0 ▶ my ($self, $index, $document) = @_;
Subroutine update_packages: not called CC=2 SCAR=17.9
Pod undocumented
160  
161 0 my $packages = $document->get_packages();
162  
163 0 $self->cleanup_index($index, 'packages', $document->{path});
164 0 ▶ return unless (ref $packages eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $packages eq "ARRAY" 0 0 0
165 0 $self->update_index($index, 'packages', $document->{path}, @$packages);
166 } ## end sub update_packages
167  
168 sub cleanup_index
169 {
170 0 ▶ my ($self, $index, $type, $file) = @_;
Subroutine cleanup_index: not called CC=6 SCAR=37.4
Pod undocumented
171  
172 0 my $trie = $self->{"${type}_trie"};
173  
174 0 ▶ if (ref $index->{files}{$file}{$type} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $index->{'files'}{$file}{$type} eq 'ARRAY') { } 0 0 0
175 {
176 0 foreach my $ref (@{$index->{files}{$file}{$type}})
177 {
178 0 @{$index->{$type}{$ref}} = grep { $_->{file} ne $file } @{$index->{$type}{$ref}};
179 0 ▶ delete $index->{$type}{$ref} unless (scalar @{$index->{$type}{$ref}});
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$index->{$type}{$ref};} 0 0 0
180  
181 0 my $node = $trie->find_node($ref);
182 0 ▶ if (ref $node eq 'Node')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "Node") 0 0 0
183 {
184 0 $node->{value}--;
185 0 ▶ $trie->delete($ref) unless ($node->{value});
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"value"} 0 0 0
186 }
187 } ## end foreach my $ref (@{$index->...})
188  
189 0 @{$index->{files}{$file}{$type}} = ();
190 } ## end if (ref $index->{files...})
191 else
192 {
193 0 $index->{files}{$file}{$type} = [];
194 }
195 } ## end sub cleanup_index
196  
197 sub update_index
198 {
199 0 ▶ my ($self, $index, $type, $file, @references) = @_;
Subroutine update_index: not called CC=5 SCAR=34.0
Pod undocumented
200  
201 0 my $stat = stat $file;
202 0 ▶ return unless (ref $stat eq 'File::stat');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $stat eq "File::stat" 0 0 0
203  
204 0 my $trie = $self->{"${type}_trie"};
205  
206 0 foreach my $reference (@references)
207 {
208 0 my $info = $reference->location_info();
209  
210 0 ▶ if (ref $index->{$type}{$reference->name} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $index->{$type}{$reference->name} eq 'ARRAY') { } 0 0 0
211 {
212 0 push @{$index->{$type}{$reference->name}}, $info;
213  
214 0 my $node = $trie->find_node($reference->name);
215  
216 0 ▶ if (ref $node eq 'Node')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq 'Node') { } 0 0 0
217 {
218 0 $node->{value}++;
219 }
220 else
221 {
222 0 $trie->insert($reference->name, 1);
223 }
224 } ## end if (ref $index->{$type...})
225 else
226 {
227 0 $index->{$type}{$reference->name} = [$info];
228 0 $trie->insert($reference->name, 1);
229 }
230  
231 0 push @{$index->{files}{$file}{$type}}, $reference->name;
232 } ## end foreach my $reference (@references...)
233  
234 0 $index->{files}{$file}{last_mtime} = $stat->mtime;
235 } ## end sub update_index
236  
237 sub cleanup_old_files
238 {
239 0 ▶ my ($self) = @_;
Subroutine cleanup_old_files: not called CC=1 SCAR=6.9
Pod undocumented
240  
241 async
242 {
243 0 ▶ my $lock = $self->lock();
Subroutine __ANON__: not called CC=1 SCAR=6.9
244 0 my $index = $self->index();
245 0 $self->_cleanup_old_files($index);
246 0 $self->save($index);
247 } ## end async
248 0 } ## end sub cleanup_old_files
249  
250 sub _cleanup_old_files
251 {
252 0 ▶ my ($self, $index) = @_;
Subroutine _cleanup_old_files: not called CC=17 SCAR=57.2
253  
254 0 ▶ if (ref $index->{files} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $index->{"files"} eq "HASH") 0 0 0
255 {
256 0 foreach my $file (keys %{$index->{files}})
257 {
258 0 ▶ next if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
259 0 $self->log("Cleaning up $file from index...");
260  
261 0 ▶ if (ref $index->{subs} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $index->{"subs"} eq "HASH") 0 0 0
262 {
263 0 foreach my $sub (@{$index->{files}{$file}{subs}})
264 {
265 0 ▶ next unless (ref $index->{subs}{$sub} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $index->{"subs"}{$sub} eq "ARRAY" 0 0 0
266 0 @{$index->{subs}{$sub}} = grep { $_->{file} eq $file } @{$index->{subs}{$sub}};
267 0 ▶ delete $index->{subs}{$sub} unless (scalar @{$index->{subs}{$sub}});
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$index->{"subs"}{$sub};} 0 0 0
268 } ## end foreach my $sub (@{$index->...})
269 } ## end if (ref $index->{subs}...)
270  
271 0 ▶ if (ref $index->{packages} eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $index->{"packages"} eq "HASH") 0 0 0
272 {
273 0 foreach my $package (@{$index->{files}{$file}{packages}})
274 {
275 0 ▶ next unless (ref $index->{packages}{$package} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $index->{"packages"}{$package} eq "ARRAY" 0 0 0
276 0 @{$index->{packages}{$package}} = grep { $_->{file} eq $file } @{$index->{packages}{$package}};
277 0 ▶ delete $index->{packages}{$package} unless (scalar @{$index->{packages}{$package}});
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$index->{"packages"}{$package};} 0 0 0
278 } ## end foreach my $package (@{$index...})
279 } ## end if (ref $index->{packages...})
280  
281 0 delete $index->{files}{$file};
282 } ## end foreach my $file (keys %{$index...})
283 } ## end if (ref $index->{files...})
284  
285 0 foreach my $type (keys %{$index})
286 {
287 0 my $refs_cleaned = 0;
288  
289 0 foreach my $ref (keys %{$index->{$type}})
290 {
291 0 ▶ next unless (ref $index->{$type}{$ref} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $index->{$type}{$ref} eq "ARRAY" 0 0 0
292 0 my $count_before = scalar @{$index->{$type}{$ref}};
293 0 @{$index->{$type}{$ref}} = grep { -e $_->{file} } @{$index->{$type}{$ref}};
294 0 my $count_after = scalar @{$index->{$type}{$ref}};
295 0 ▶ $refs_cleaned++ if ($count_after < $count_before);
Branch: 1 branch
BranchTrueFalseTotal
if $count_after < $count_before 0 0 0
296 }
297  
298 0 ▶ $self->log("Cleaning up $type references from index...") if ($refs_cleaned);
Branch: 1 branch
BranchTrueFalseTotal
if $refs_cleaned 0 0 0
299 }
300 } ## end sub _cleanup_old_files
301  
302 sub find_package_subroutine
303 {
304 0 ▶ my ($self, $package, $subroutine) = @_;
Subroutine find_package_subroutine: not called CC=4 SCAR=30.0
Pod undocumented
305  
306 0 my $index = $self->index();
307 0 my $locations = $index->{packages}{$package};
308  
309 0 ▶ if (ref $locations ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $locations ne "ARRAY") 0 0 0
310 {
311 0 my $external = PLS::Parser::Document->find_external_subroutine($package, $subroutine);
312 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
313 0 return [];
314 } ## end if (ref $locations ne ...)
315  
316 0 foreach my $file (@$locations)
317 {
318 0 return $self->find_subroutine($subroutine, $file->{file});
319 }
320  
321 0 return;
322 } ## end sub find_package_subroutine
323  
324 sub find_subroutine
325 {
326 0 ▶ my ($self, $subroutine, @files) = @_;
Subroutine find_subroutine: not called CC=4 SCAR=30.0
Pod undocumented
327  
328 0 my $index = $self->index;
329 0 my $found = $index->{subs}{$subroutine};
330 0 ▶ return [] unless (ref $found eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $found eq "ARRAY" 0 0 0
331  
332 0 my @locations = @$found;
333  
334 0 ▶ if (scalar @files)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @files) 0 0 0
335 {
336 @locations = grep {
337 0 my $location = $_;
338 0 scalar grep { $location->{file} eq $_ } @files;
339 } @locations;
340 } ## end if (scalar @files)
341  
342 return [
343 map {
344 0 {
345 uri => URI::file->new($_->{file})->as_string,
346 range => {
347 start => {
348 line => $_->{location}{line_number},
349 character => $_->{location}{column_number}
350 },
351 end => {
352 line => $_->{location}{line_number},
353 character => $_->{location}{column_number} + (length $subroutine) + ($_->{constant} ? 0 : (length 'sub '))
354 }
355 },
356 signature => $_->{signature}
357 }
358 0 ▶ } @locations
Branch: 1 branch
BranchTrueFalseTotal
$_->{'constant'} ? : 0 0 0
359 ];
360 } ## end sub find_subroutine
361  
362 sub find_package
363 {
364 0 ▶ my ($self, $package, @files) = @_;
Subroutine find_package: not called CC=4 SCAR=30.0
Pod undocumented
365  
366 0 my $index = $self->index;
367 0 my $found = $index->{packages}{$package};
368  
369 0 ▶ if (ref $found ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $found ne "ARRAY") 0 0 0
370 {
371 0 my $external = PLS::Parser::Document->find_external_package($package);
372 0 ▶ return [$external] if (ref $external eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $external eq "HASH" 0 0 0
373 0 return [];
374 } ## end if (ref $found ne 'ARRAY'...)
375  
376 0 my @locations = @$found;
377  
378 0 ▶ if (scalar @files)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @files) 0 0 0
379 {
380 @locations = grep {
381 0 my $location = $_;
382 0 grep { $location->{file} eq $_ } @files
383 } @locations;
384 } ## end if (scalar @files)
385  
386 return [
387 map {
388 0 {
389 uri => URI::file->new($_->{file})->as_string,
390 range => {
391 start => {
392 line => $_->{location}{line_number},
393 character => $_->{location}{column_number}
394 },
395 end => {
396 line => $_->{location}{line_number},
397 0 character => $_->{location}{column_number} + length("package $package;")
398 }
399 }
400 }
401 } @locations
402 ];
403 } ## end sub find_package
404  
405 sub get_ignored_files
406 {
407 0 ▶ my ($self) = @_;
Subroutine get_ignored_files: not called CC=7 SCAR=40.3
Pod undocumented
408  
409 0 my @ignore_files;
410 0 my $plsignore = File::Spec->catfile($self->{root}, '.plsignore');
411  
412 0 ▶ return [] unless (-f $plsignore and -r $plsignore);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $plsignore and -r $plsignore 0 0 0
Condition0%0/3
-f $plsignore and -r $plsignore
!ll&&!rl&&r
000
MC/DC0%0/2
-f $plsignore and -r $plsignore
-f $plsignore -r $plsignore
Truth table0%0/3
A and B
A= -f $plsignoreB= -r $plsignore
ABresult
0X0
100
111
413  
414 0 my $mtime = stat($plsignore)->mtime;
415 0 ▶ return $self->{ignored_files} if (length $self->{ignore_file_last_mtime} and $self->{ignore_file_last_mtime} >= $mtime);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"ignore_file_last_mtime"} and $self->{"ignore_file_last_mtime"} >= $mtime 0 0 0
Condition0%0/3
length $self->{"ignore_file_last_mtime"} and $self->{"ignore_file_last_mtime"} >= $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
length $self->{"ignore_file_last_mtime"} and $self->{"ignore_file_last_mtime"} >= $mtime
length $self->{"ignore_file_last_mtime"} $self->{"ignore_file_last_mtime"} >= $mtime
Truth table0%0/3
A and B
A= length $self->{"ignore_file_last_mtime"}B= $self->{"ignore_file_last_mtime"} >= $mtime
ABresult
0X0
100
111
416  
417 0 ▶ if (open my $fh, '<', File::Spec->catfile($self->{root}, '.plsignore'))
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "File::Spec"->catfile($self->{"root"}, ".plsignore")) 0 0 0
418 {
419 0 ▶ while (my $line = <$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
420 {
421 0 chomp $line;
422 0 push @ignore_files, glob File::Spec->catfile($self->{root}, $line);
423 }
424 } ## end if (open my $fh, '<', ...)
425  
426 0 @ignore_files = map { path($_)->realpath } @ignore_files;
427 0 $self->{ignored_files} = \@ignore_files;
428 0 $self->{ignore_file_last_mtime} = $mtime;
429  
430 0 return $self->{ignored_files};
431 } ## end sub get_ignored_files
432  
433 sub is_ignored
434 {
435 0 ▶ my ($self, $file) = @_;
Subroutine is_ignored: not called CC=4 SCAR=30.0
Pod undocumented
436  
437 0 my @ignore_files = @{$self->get_ignored_files()};
438 0 ▶ return if not scalar @ignore_files;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @ignore_files 0 0 0
439  
440 0 my $real_path = path($file)->realpath;
441  
442 0 ▶ return 1 if any { $_ eq $real_path } @ignore_files;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $real_path; } , @ignore_files) 0 0 0
443 0 ▶ return 1 if any { $_->subsumes($real_path) } @ignore_files;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_->subsumes($real_path); } , @ignore_files) 0 0 0
444  
445 0 return;
446 } ## end sub is_ignored
447  
448 sub get_all_perl_files
449 {
450 0 ▶ my ($self) = @_;
Subroutine get_all_perl_files: not called CC=2 SCAR=17.9
Pod undocumented
451  
452 0 ▶ return unless (length $self->{root});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"root"} 0 0 0
453  
454 0 my @perl_files;
455  
456 File::Find::find(
457 {
458 preprocess => sub {
459 0 ▶ return () if $self->is_ignored($File::Find::dir);
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_ignored($File::Find::dir) 0 0 0
460 0 return grep { not $self->is_ignored($_) } @_;
461 },
462 wanted => sub {
463 0 ▶ return unless $self->is_perl_file($File::Find::name);
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_perl_file($File::Find::name) 0 0 0
464 0 my @pieces = File::Spec->splitdir($File::Find::name);
465  
466 # exclude hidden files and files in hidden directories
467 0 ▶ return if any { /^\./ } @pieces;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /^\./; } , @pieces) 0 0 0
468  
469 0 push @perl_files, $File::Find::name;
470 }
471 },
472 $self->{root}
473 0 );
474  
475 0 return \@perl_files;
476 } ## end sub get_all_perl_files
477  
478 sub is_perl_file
479 {
480 0 ▶ my ($class, $file) = @_;
Subroutine is_perl_file: not called CC=8 SCAR=42.8
Pod undocumented
481  
482 0 ▶ return if -l $file;
Branch: 1 branch
BranchTrueFalseTotal
if -l $file 0 0 0
483 0 ▶ return unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
484 0 ▶ return if $file =~ /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.t$/ 0 0 0
485  
486 0 ▶ return 1 if $file =~ /\.p[lm]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.p[lm]$/ 0 0 0
487 0 ▶ open my $fh, '<', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return 0 0 0
488 0 my $first_line = <$fh>;
489 0 close $fh;
490 0 ▶ return 1 if (length $first_line and $first_line =~ /^\s*#!.*perl$/);
Branch: 1 branch
BranchTrueFalseTotal
if length $first_line and $first_line =~ /^\s*#!.*perl$/ 0 0 0
Condition0%0/3
length $first_line and $first_line =~ /^\s*#!.*perl$/
!ll&&!rl&&r
000
MC/DC0%0/2
length $first_line and $first_line =~ /^\s*#!.*perl$/
length $first_line $first_line =~ /^\s*#!.*perl$/
Truth table0%0/3
A and B
A= length $first_lineB= $first_line =~ /^\s*#!.*perl$/
ABresult
0X0
100
111
491 0 return;
492 } ## end sub is_perl_file
493  
494 sub log
495 {
496 0 ▶ my (undef, $message) = @_;
Subroutine log: not called CC=1 SCAR=6.9
Pod undocumented
497  
498 0 my $time = Time::Piece->new;
499 0 $time = $time->ymd . ' ' . $time->hms;
500 0 print {\*STDERR} "[$time] $message\n";
501 } ## end sub log
502  
503 1 1;
« PLS/Server/Method/TextDocument.pm ↑ Summary PLS/Server/Request/Workspace/Configuration.pm »