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 9     9   57 use strict;
  9         68  
  9         345  
4 9     9   118 use warnings;
  9         18  
  9         330  
5              
6 9     9   147 use feature 'state';
  9         83  
  9         1901  
7              
8 9     9   112 use ExtUtils::Installed;
  9         17  
  9         519  
9 9     9   52 use Module::CoreList;
  9         19  
  9         296  
10              
11 9     9   386 use PLS::Parser::Pod;
  9         25  
  9         6845  
12              
13             sub warm_up
14             {
15 4     4 0 125 get_builtin_variables();
16 4         114 get_core_modules();
17 4         48 get_ext_modules();
18              
19 4         25 return;
20             } ## end sub warm_up
21              
22             sub get_ext_modules
23             {
24 4     4 0 27 state $include = [];
25 4         50 state $modules = [];
26              
27 4         46 my $curr_include = join ':', @{$include};
  4         39  
28 4         158 my $clean_inc = PLS::Parser::Pod->get_clean_inc();
29 4         26 my $updated_include = join ':', @{$clean_inc};
  4         37  
30              
31 4 50 33     42 if ($curr_include ne $updated_include or not scalar @{$modules})
  0         0  
32             {
33 4         15 $include = $clean_inc;
34 4         239 my $installed = ExtUtils::Installed->new(inc_override => $clean_inc);
35              
36 4         977022 foreach my $module ($installed->modules)
37             {
38 504         2214 my @files = $installed->files($module);
39 504         198761 $module =~ s/::/\//g;
40              
41             # Find all the packages that are part of this module
42 504         708 foreach my $file (@files)
43             {
44 11284 100       21464 next if ($file !~ /\.pm$/);
45 6508         7022 my $valid = 0;
46              
47 6508         6156 foreach my $path (@{$clean_inc})
  6508         7887  
48             {
49 39048 100       322996 $valid = 1 if ($file =~ s/^\Q$path\E\/?(?:auto\/)?//);
50             }
51              
52 6508 50       10869 next unless ($valid);
53 6508 50       8309 next unless (length $file);
54 6508         16183 $file =~ s/\.pm$//;
55 6508         14118 my $mod_package = $file =~ s/\//::/gr;
56              
57             # Skip private packages
58 6508 100 100     22709 next if ($mod_package =~ /^_/ or $mod_package =~ /::_/);
59 6428         6696 push @{$modules}, $mod_package;
  6428         16031  
60             } ## end foreach my $file (@files)
61             } ## end foreach my $module ($installed...)
62             } ## end if ($curr_include ne $updated_include...)
63              
64 4         161 return $modules;
65             } ## end sub get_ext_modules
66              
67             sub get_core_modules
68             {
69 4     4 0 327 state $core_modules = [Module::CoreList->find_modules(qr//, $])];
70 4         29678 return $core_modules;
71             }
72              
73             sub get_builtin_variables
74             {
75 4     4 0 246 my $perldoc = PLS::Parser::Pod->get_perldoc_location();
76 4         82 state $builtin_variables = [];
77              
78 4 50       48 return $builtin_variables if (scalar @{$builtin_variables});
  4         73  
79              
80 4 50       28770 if (open my $fh, '-|', $perldoc, '-Tu', 'perlvar')
81             {
82 4         185955 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 '$<');
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         464 return $builtin_variables;
98             } ## end sub get_builtin_variables
99              
100             1;