Scan/Cache.pm

filter: Statementstmt 58.7% 27 / 46 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 5 totaltotal 47.9% 35 / 73 CC 5 SCAR 12.3
CC
5
Cov
50%
init
6.0
get
6.0
set
6.0
CRAP 3.4
« Scan/Matches.pm ↑ Summary Scan/Constant.pm »
1 =head1 NAME
2  
3 File::OSS::Scan::Cache - simple wrapper on L<Cache::FileCache>
4  
5 =head1 VERSION
6  
7 version 0.04
8  
9 =head1 SYNOPSIS
10  
11 use File::OSS::Scan::Cache;
12  
13 File::OSS::Scan::Cache->init($base_dir);
14  
15 File::OSS::Scan::Cache->set( $file_path => $h_file );
16 my $cached_file = File::OSS::Scan::Cache->get($file_path);
17  
18 File::OSS::Scan::Cache->clear();
19  
20 =head1 DESCRIPTION
21  
22 This is an internal module used by L<File::OSS::Scan> to cache scan results into
23 files, and should not be called directly.
24  
25 =head1 SEE ALSO
26  
27 =over 4
28  
29 =item * L<File::OSS::Scan>
30  
31 =back
32  
33 =head1 AUTHOR
34  
35 Harry Wang <harry.wang@outlook.com>
36  
37 =head1 COPYRIGHT AND LICENSE
38  
39 This software is Copyright (c) 2014 by Harry Wang.
40  
41 This is free software, licensed under:
42  
43 Artistic License 1.0
44  
45 =cut
46  
47 package File::OSS::Scan::Cache;
48  
49 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 ▶use Fatal qw( open close );
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Data::Dumper; # for debug
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Cache::FileCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 1 ▶use File::OSS::Scan::Constant qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 1 our $VERSION = '0.04';
61  
62 1 our $cache = undef;
63  
64 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
65 0 my $self = shift;
66 0 ▶ my $dir = shift || return SUCCESS;
Condition0%0/2
shift() || (return 0)
l!l
00
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
67  
68 0 my $hash = {
69 'namespace' => $dir,
70 'default_expires_in' => 'never',
71 };
72  
73 0 $cache = new Cache::FileCache($hash);
74  
75 0 return SUCCESS;
76 }
77  
78 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my ( $self, $key ) = @_;
80 0 my $val = undef;
81  
82 0 ▶ ( defined $cache ) &&
Branch: 1 branch
BranchTrueFalseTotal
defined $File::OSS::Scan::Cache::cache and $val = $File::OSS::Scan::Cache::cache->get($key) 0 0 0
83 ( $val = $cache->get($key) );
84  
85 0 return $val;
86 }
87  
88 0 ▶sub set {
Subroutine set: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my ( $self, $key, $val ) = @_;
90  
91 0 ▶ ( defined $cache ) &&
Branch: 1 branch
BranchTrueFalseTotal
defined $File::OSS::Scan::Cache::cache and $File::OSS::Scan::Cache::cache->set($key, $val) 0 0 0
92 ( $cache->set($key, $val) );
93  
94 0 return SUCCESS;
95 }
96  
97 0 ▶sub clear {
Subroutine clear: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my $self = shift;
99  
100 0 ▶ ( defined $cache ) &&
Branch: 1 branch
BranchTrueFalseTotal
defined $File::OSS::Scan::Cache::cache and $File::OSS::Scan::Cache::cache->clear 0 0 0
101 ( $cache->clear() );
102  
103 0 return SUCCESS;
104 }
105  
106 0 ▶sub clear_all {
Subroutine clear_all: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my $self = shift;
108  
109 0 my $pseudo_cache = new Cache::FileCache();
110 0 $pseudo_cache->Clear();
111  
112 0 return SUCCESS;
113 }
114  
115  
116  
117 1 1;
« Scan/Matches.pm ↑ Summary Scan/Constant.pm »