File Coverage

blib/lib/PLS/Server/Cache.pm
Criterion Covered Total %
statement 58 65 89.2
branch 11 22 50.0
condition 4 9 44.4
subroutine 10 10 100.0
pod 0 4 0.0
total 83 110 75.4


line stmt bran cond sub pod time code
1             package PLS::Server::Cache;
2              
3 11     11   203 use strict;
  11         79  
  11         447  
4 11     11   201 use warnings;
  11         25  
  11         1070  
5              
6 11     11   148 use feature 'state';
  11         72  
  11         4633  
7              
8 11     11   99 use ExtUtils::Installed;
  11         226  
  11         989  
9 11     11   184 use Module::CoreList;
  11         56  
  11         1877  
10              
11 11     11   742 use PLS::Parser::Pod;
  11         134  
  11         14766  
12              
13             sub warm_up
14             {
15 4     4 0 367 get_builtin_variables();
16 4         153 get_core_modules();
17 4         120 get_ext_modules();
18              
19 4         23 return;
20             } ## end sub warm_up
21              
22             sub get_ext_modules
23             {
24 4     4 0 58 state $include = [];
25 4         20 state $modules = [];
26              
27 4         80 my $curr_include = join ':', @{$include};
  4         45  
28 4         252 my $clean_inc = PLS::Parser::Pod->get_clean_inc();
29 4         19 my $updated_include = join ':', @{$clean_inc};
  4         34  
30              
31 4 50 33     65 if ($curr_include ne $updated_include or not scalar @{$modules})
  0         0  
32             {
33 4         14 $include = $clean_inc;
34 4         414 my $installed = ExtUtils::Installed->new(inc_override => $clean_inc);
35              
36 4         4282964 foreach my $module ($installed->modules)
37             {
38 764         6523 my @files = $installed->files($module);
39 764         1386032 $module =~ s/::/\//g;
40              
41             # Find all the packages that are part of this module
42 764         1585 foreach my $file (@files)
43             {
44 46196 100       136753 next if ($file !~ /\.pm$/);
45 8556         17521 my $valid = 0;
46              
47 8556         11332 foreach my $path (@{$clean_inc})
  8556         16543  
48             {
49 68448 100       1029061 $valid = 1 if ($file =~ s/^\Q$path\E\/?(?:auto\/)?//);
50             }
51              
52 8556 50       24041 next unless ($valid);
53 8556 50       20123 next unless (length $file);
54 8556         35173 $file =~ s/\.pm$//;
55 8556         30117 my $mod_package = $file =~ s/\//::/gr;
56              
57             # Skip private packages
58 8556 100 100     40886 next if ($mod_package =~ /^_/ or $mod_package =~ /::_/);
59 8460         13217 push @{$modules}, $mod_package;
  8460         54244  
60             } ## end foreach my $file (@files)
61             } ## end foreach my $module ($installed...)
62             } ## end if ($curr_include ne $updated_include...)
63              
64 4         435 return $modules;
65             } ## end sub get_ext_modules
66              
67             sub get_core_modules
68             {
69 4     4 0 695 state $core_modules = [Module::CoreList->find_modules(qr//, $])];
70 4         59245 return $core_modules;
71             }
72              
73             sub get_builtin_variables
74             {
75 4     4 0 525 my $perldoc = PLS::Parser::Pod->get_perldoc_location();
76 4         163 state $builtin_variables = [];
77              
78 4 50       51 return $builtin_variables if (scalar @{$builtin_variables});
  4         125  
79              
80 4 50       104076 if (open my $fh, '-|', $perldoc, '-Tu', 'perlvar')
81             {
82 4         2195911 while (my $line = <$fh>)
83             {
84 0 0       0 if ($line =~ /=item\s*(C<)?([\$\@\%]\S+)\s*/)
85             {
86             # If variable started with pod sequence "C<" remove ">" from the end
87 0         0 my $variable = $2;
88 0 0       0 $variable = substr $variable, 0, -1 if (length $1);
89              
90             # Remove variables indicated by pod sequences
91 0 0 0     0 next if ($variable =~ /^\$</ and $variable ne '$<'); ## no critic (RequireInterpolationOfMetachars)
92 0         0 push @{$builtin_variables}, $variable;
  0         0  
93             } ## end if ($line =~ /=item\s*(C<)?([\$\@\%]\S+)\s*/...)
94             } ## end while (my $line = <$fh>)
95             } ## end if (open my $fh, '-|',...)
96              
97 4         743 return $builtin_variables;
98             } ## end sub get_builtin_variables
99              
100             1;