blib/lib/YAML/LoadFileCached.pm

filter: Statementstmt 100% 29 / 29 Branchbran 62.5% 5 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 94.0% 47 / 50 CC 6 SCAR 9.9
CC
6
Cov
92%
LoadFileCached
4.0
CacheStatistics
3.2
BEGIN
1.0
CRAP 2.7
↑ Summary
1 package YAML::LoadFileCached;
2  
3 #
4 # $Id: LoadFileCached.pm,v 1.3 2003/02/03 12:10:01 florian Exp $
5 #
6  
7 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use YAML qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 require Exporter;
14  
15 1 our @ISA = qw(Exporter);
16 1 our @EXPORT_OK = qw(
17 CacheStatistics
18 );
19 1 our @EXPORT = qw(
20 LoadFileCached
21 );
22 1 our $VERSION = '0.21';
23  
24 1 my $cache;
25 my $statistic;
26  
27 sub LoadFileCached
28 1001 ▶ {
Subroutine LoadFileCached: called CC=4 SCAR=13.9
Pod documented
29 1001 my($filepath) = @_;
30  
31 1001 ▶ return undef unless defined $filepath;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filepath 0 1001 1001
32  
33 1001 ▶ if(exists($cache->{$filepath}) && ($statistic->{$filepath}->{'lastchanged'} == (stat($filepath))[9]))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache->{$filepath} and $statistic->{$filepath}{'lastchanged'} == (stat $filepath)[9]) { } 999 2 1001
Condition100%3/3
exists $cache->{$filepath} and $statistic->{$filepath}{"lastchanged"} == (stat $filepath)[9]
!ll&&!rl&&r
11999
MC/DC100%2/2
exists $cache->{$filepath} and $statistic->{$filepath}{"lastchanged"} == (stat $filepath)[9]
exists $cache->{$filepath} $statistic->{$filepath}{"lastchanged"} == (stat $filepath)[9]
Truth table100%3/3
A and B
A= exists $cache->{$filepath}B= $statistic->{$filepath}{"lastchanged"} == (stat $filepath)[9]
ABresult
0X0
100
111
34 {
35 999 $statistic->{$filepath}->{'cached'}++;
36 }
37 else
38 {
39 2 $cache->{$filepath} = LoadFile($filepath);
40
41 2 $statistic->{$filepath}->{'lastchanged'} = (stat($filepath))[9];
42 2 $statistic->{$filepath}->{'read'}++;
43 }
44  
45 1001 return $cache->{$filepath};
46 }
47  
48  
49 sub CacheStatistics
50 2 ▶ {
Subroutine CacheStatistics: called CC=3 SCAR=11.7
Pod documented
51 2 my ($filepath) = @_;
52  
53 2 ▶ return $statistic unless defined $filepath;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filepath 0 2 2
54  
55 2 ▶ return exists($statistic->{$filepath}) ? $statistic->{$filepath} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $statistic->{$filepath} ? : 2 0 2
56 }
57  
58  
59 1 1;
60 __END__
↑ Summary