ConfigCache.pm

filter: Statementstmt 30.0% 12 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 27.2% 3 / 11 Podpod 0.0% 0 / 6 totaltotal 23.8% 15 / 63 CC 4 SCAR 12.5
CC
4
Cov
26%
get_config_by_filename
6.0
pop_configs
6.0
__ANON__
6.0
CRAP 3.5
« App/Prove/Plugin/MultipleConfig.pm ↑ Summary TAP/Formatter/Console/NoRulerParallelSession.pm »
1 package ConfigCache;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Cache::FastMmap;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 my $CACHE = Cache::FastMmap->new(cache_size => '1m', expire_time => '1d');
8 1 my $CONFIGS_KEY = 'CONFIGS';
9  
10 0 ▶sub set_configs {
Subroutine set_configs: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my ($self, $configs) = @_;
12 0 $CACHE->set($CONFIGS_KEY, $configs);
13 }
14  
15 0 ▶sub get_config_by_filename {
Subroutine get_config_by_filename: not called CC=2 SCAR=17.9
Pod undocumented
16 0 my ($self, $filename) = @_;
17 0 my $config = $CACHE->get($filename);
18 0 ▶ die "filename:$filename is not found" if (!$config);
Branch: 1 branch
BranchTrueFalseTotal
unless $config 0 0 0
19 0 return $config;
20 }
21  
22 0 ▶sub set_config_by_pid {
Subroutine set_config_by_pid: not called CC=1 SCAR=6.9
Pod undocumented
23 0 my ($self, $pid, $config) = @_;
24 0 $CACHE->set($pid, $config);
25 }
26  
27 0 ▶sub set_config_by_filename {
Subroutine set_config_by_filename: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my ($self,$filename, $pid) = @_;
29 0 my $config = $CACHE->get($pid);
30 0 $CACHE->set($filename, $config);
31 }
32  
33 0 ▶sub pop_configs {
Subroutine pop_configs: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my $config = '';
35  
36 0 ▶ while (!$config){
Branch: 1 branch
BranchTrueFalseTotal
unless ($config) 0 0 0
37 0 ▶ $CACHE->get_and_set($CONFIGS_KEY, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
38 0 my (undef, $configs) = @_;
39 0 ▶ if (scalar @{$configs} != 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$configs;} != 0) { } 0 0 0
40 0 $config = pop @{$configs};
41 }
42 else {
43 0 sleep 1;
44 }
45 0 return $configs;
46 0 });
47 }
48 0 return $config;
49 }
50  
51 0 ▶sub push_configs {
Subroutine push_configs: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my ($self, $config) = @_;
53 0 ▶ $CACHE->get_and_set($CONFIGS_KEY, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 my (undef, $configs) = @_;
55 0 unshift @{$configs}, $config;
56 0 return $configs;
57 })
58 0 }
59  
60 1 1;
61  
62 =head1 NAME
63  
64 ConfigCache - shared cache for MultipleConfig
65  
66 =head1 DESCRIPTION
67  
68 ConfigCache is shared cache for config files.
69 This module uses L<Cache::FastMmap>
70  
71 =head1 LICENSE
72  
73 Copyright (C) takahito.yamada.
74  
75 This library is free software; you can redistribute it and/or modify
76 it under the same terms as Perl itself.
77  
78 =head1 AUTHOR
79  
80 takahito.yamada
81  
82 =head1 SEE ALSO
83  
84 L<prove>, L<Cache::FastMmap>
85  
86 =cut
« App/Prove/Plugin/MultipleConfig.pm ↑ Summary TAP/Formatter/Console/NoRulerParallelSession.pm »