| 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
| |||||||||||||||||||||||||||||
| 16 | unless defined $file; | ||||||||||||||||||||||||||||
| 17 | 3 | ▶ | croak "Specified file '$file' cannot be read." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$Data::Phrasebook::Loader::ApacheFormat::CACHE{$file} and $Data::Phrasebook::Loader::ApacheFormat::CACHE{$file}{"mtime"} == $mtime
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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$dict and my $block = eval {
do {
$conf->block($dict)
}
}
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)
}
}
| |||||||||||||||||||||||||||||
| 49 | 1 | $conf = $block; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | return $conf->get($key); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||