| 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
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1001 | ▶ | if(exists($cache->{$filepath}) && ($statistic->{$filepath}->{'lastchanged'} == (stat($filepath))[9])) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $cache->{$filepath} and $statistic->{$filepath}{"lastchanged"} == (stat $filepath)[9]
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]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return exists($statistic->{$filepath}) ? $statistic->{$filepath} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||