blib/lib/Data/Phrasebook/Loader/ApacheFormat.pm

filter: Statementstmt 100% 38 / 38 Branchbran 75.0% 6 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 93.9% 62 / 66 CC 7 SCAR 10.6
CC
7
Cov
94%
load
5.1
get
3.0
BEGIN
1.0
CRAP 2.9
↑ Summary
1 package Data::Phrasebook::Loader::ApacheFormat;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '1.00';
8  
9 2 ▶use Config::ApacheFormat;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use base qw( Data::Phrasebook::Loader::Base Data::Phrasebook::Debug );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶sub load {
Subroutine load: called CC=5 SCAR=16.2
Pod documented
14 3 my ($self, $file, $dict) = @_;
15 3 ▶ croak "Missing required file option."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 3 3
16 unless defined $file;
17 3 ▶ croak "Specified file '$file' cannot be read."
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 3 3
18 unless -r $file;
19  
20 # load the file, looking in the cache first. Caching is a
21 # necessity here because Data::Phrasebook reloads every time
22 # dict() is changed, which, for my use, is very common
23 3 our %CACHE;
24 3 my $mtime = (stat($file))[9];
25 3 ▶ if ($CACHE{$file} and $CACHE{$file}{mtime} == $mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Data::Phrasebook::Loader::ApacheFormat::CACHE{$file} and $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{'mtime'} == $mtime) { } 2 1 3
Condition66%2/3
$Data::Phrasebook::Loader::ApacheFormat::CACHE{$file} and $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{"mtime"} == $mtime
!ll&&!rl&&r
102
MC/DC50%1/2
$Data::Phrasebook::Loader::ApacheFormat::CACHE{$file} and $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{"mtime"} == $mtime
$Data::Phrasebook::Loader::ApacheFormat::CACHE{$file} $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{"mtime"} == $mtime
Truth table66%2/3
A and B
A= $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}B= $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{"mtime"} == $mtime
ABresult
0X0
100
111
26 # fetch from the cache
27 2 $self->{conf} = $CACHE{$file}{conf};
28  
29 } else {
30 # load a new file
31 1 $self->{conf} = Config::ApacheFormat->new();
32 1 $self->{conf}->read($file);
33 1 $CACHE{$file}{conf} = $self->{conf};
34 1 $CACHE{$file}{mtime} = $mtime;
35 }
36  
37 # store dict for use in get
38  
39 3 $self->{dict} = $dict;
40 }
41  
42 4 ▶sub get {
Subroutine get: called CC=3 SCAR=11.0
Pod documented
43 4 my ($self, $key) = @_;
44 4 my $conf = $self->{conf};
45 4 my $dict = $self->{dict};
46  
47 # look in dict block if set and available in the file
48 4 ▶ if ($dict and my $block = eval { $conf->block($dict) }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dict and my $block = eval { do { $conf->block($dict) } }) 1 3 4
Condition100%3/3
$dict and my $block = eval { do { $conf->block($dict) } }
!ll&&!rl&&r
121
MC/DC100%2/2
$dict and my $block = eval { do { $conf->block($dict) } }
$dict my $block = eval { do { $conf->block($dict) } }
Truth table100%3/3
A and B
A= $dictB= my $block = eval { do { $conf->block($dict) } }
ABresult
0X0
100
111
49 1 $conf = $block;
50 }
51  
52 4 return $conf->get($key);
53 }
54  
55 2 1;
56  
57 __END__
↑ Summary