lib/Cache/AgainstFile.pm

filter: Statementstmt 100% 44 / 44 Branchbran 85.7% 12 / 14 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 12 / 12 Podpod 75.0% 6 / 8 totaltotal 90.7% 78 / 86 CC 11 SCAR 16.5
CC
11
Cov
94%
new
10.0
get
2.0
BEGIN
1.0
CRAP 5.2
« lib/Cache/AgainstFile/Storable.pm ↑ Summary lib/Cache/AgainstFile/Base.pm »
1 ###############################################################################
2 # Purpose : Cache data structures against a file
3 # Author : John Alden
4 # Created : 22 Apr 2005 (based on IFL::FileCache)
5 # CVS : $Id: AgainstFile.pm,v 1.16 2006/05/09 09:04:29 mattheww Exp $
6 ###############################################################################
7  
8 package Cache::AgainstFile;
9  
10 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 $VERSION = sprintf"%d.%03d", q$Revision: 1.16 $ =~ /: (\d+)\.(\d+)/;
15  
16 #
17 # API
18 #
19 sub new
20 15 ▶{
Subroutine new: called CC=10 SCAR=23.1
Pod documented
21 15 my ($class, $loader, $options) = @_;
22 15 my $usage = "USAGE: $class->new(\&loader, \%options)";
23 15 ▶ croak($usage) unless $loader && $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $loader and $options 0 15 15
Condition33%1/3
$loader and $options
!ll&&!rl&&r
0015
MC/DC0%0/2
$loader and $options
$loader $options
Truth table33%1/3
A and B
A= $loaderB= $options
ABresult
0X0
100
111
24 15 ▶ croak($usage . ". Supplied loader is not a code reference") unless ref $loader eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $loader eq "CODE" 1 14 15
25 14 ▶ croak($usage . ". Supplied options is not a hash reference") unless ref $options eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 1 13 14
26
27 #Select backend
28 13 ▶ my $method = $options->{Method} || croak("No cache 'Method' option");
Condition100%2/2
$options->{'Method'} || croak(q[No cache 'Method' option])
l!l
121
MC/DC100%1/1
$options->{'Method'} || croak(q[No cache 'Method' option])
$options->{'Method'}
Truth table100%2/2
A
A= $options->{'Method'}
Aresult
11
00
29 12 TRACE("Cache: method = $method");
30  
31 #Load appropriate backend class on demand
32 12 ▶ my $backend_name = (scalar $method =~ /::/? $method : "$class\::$method"); #If no namespace, assume in the Cache::AgainstFile::Backend namespace
Branch: 1 branch
BranchTrueFalseTotal
scalar $method =~ /::/ ? : 3 9 12
33 12 ▶ die("Package name '$backend_name' doesn't look valid") unless($backend_name =~ /^[\w:]+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $backend_name =~ /^[\w:]+$/ 1 11 12
34 11 eval "require $backend_name";
35 11 ▶ die("Unable to load $backend_name - $@") if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 10 11
36  
37 #Wire up tracing stubs
38 10 foreach my $stub (qw(TRACE DUMP)) {
39 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 20 local $^W = undef;
41 20 *{$backend_name."::".$stub} = \&{$stub};
42 }
43  
44 10 my $backend = $backend_name->new($loader, $options);
45 10 my $self = {
46 'loader' => $loader,
47 'options' => $options,
48 'method' => $method,
49 'backend' => $backend,
50 };
51 10 bless $self, $class;
52 }
53  
54 # Forward the methods to the backend
55 sub get
56 73 ▶{
Subroutine get: called CC=2 SCAR=7.1
Pod documented
57 73 my $self = shift;
58 73 ▶ croak("File '$_[0]' does not exist") unless(-e $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_[0] 0 73 73
59 73 return $self->{backend}->get(@_);
60 }
61  
62 sub purge
63 8 ▶{
Subroutine purge: called CC=1 SCAR=0.0
Pod documented
64 8 my $self = shift;
65 8 return $self->{backend}->purge();
66 }
67  
68 sub clear
69 15 ▶{
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
70 15 my $self = shift;
71 15 return $self->{backend}->clear();
72 }
73  
74 sub count
75 16 ▶{
Subroutine count: called CC=1 SCAR=0.0
Pod documented
76 16 my $self = shift;
77 16 return $self->{backend}->count();
78 }
79  
80 sub size
81 8 ▶{
Subroutine size: called CC=1 SCAR=0.0
Pod documented
82 8 my $self = shift;
83 8 return $self->{backend}->size();
84 }
85  
86 #Log::Trace stubs
87 557 ▶sub TRACE {}
Subroutine TRACE: called CC=1 SCAR=0.0
Pod undocumented
88 24 ▶sub DUMP {}
Subroutine DUMP: called CC=1 SCAR=0.0
Pod undocumented
89  
90 5 1;
91  
92 __END__
« lib/Cache/AgainstFile/Storable.pm ↑ Summary lib/Cache/AgainstFile/Base.pm »