line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Phrasebook::Loader::ApacheFormat; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
27754
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
80
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
83
|
|
|
2
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1957
|
use Config::ApacheFormat; |
|
2
|
|
|
|
|
209177
|
|
|
2
|
|
|
|
|
91
|
|
10
|
2
|
|
|
2
|
|
25
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
353
|
|
11
|
2
|
|
|
2
|
|
11
|
use base qw( Data::Phrasebook::Loader::Base Data::Phrasebook::Debug ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2368
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub load { |
14
|
3
|
|
|
3
|
1
|
21194
|
my ($self, $file, $dict) = @_; |
15
|
3
|
50
|
|
|
|
15
|
croak "Missing required file option." |
16
|
|
|
|
|
|
|
unless defined $file; |
17
|
3
|
50
|
|
|
|
69
|
croak "Specified file '$file' cannot be read." |
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
|
|
|
|
|
7
|
our %CACHE; |
24
|
3
|
|
|
|
|
38
|
my $mtime = (stat($file))[9]; |
25
|
3
|
100
|
66
|
|
|
31
|
if ($CACHE{$file} and $CACHE{$file}{mtime} == $mtime) { |
26
|
|
|
|
|
|
|
# fetch from the cache |
27
|
2
|
|
|
|
|
9
|
$self->{conf} = $CACHE{$file}{conf}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} else { |
30
|
|
|
|
|
|
|
# load a new file |
31
|
1
|
|
|
|
|
41
|
$self->{conf} = Config::ApacheFormat->new(); |
32
|
1
|
|
|
|
|
1574
|
$self->{conf}->read($file); |
33
|
1
|
|
|
|
|
4567
|
$CACHE{$file}{conf} = $self->{conf}; |
34
|
1
|
|
|
|
|
3
|
$CACHE{$file}{mtime} = $mtime; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# store dict for use in get |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
14
|
$self->{dict} = $dict; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get { |
43
|
4
|
|
|
4
|
1
|
1582
|
my ($self, $key) = @_; |
44
|
4
|
|
|
|
|
12
|
my $conf = $self->{conf}; |
45
|
4
|
|
|
|
|
7
|
my $dict = $self->{dict}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# look in dict block if set and available in the file |
48
|
4
|
100
|
100
|
|
|
16
|
if ($dict and my $block = eval { $conf->block($dict) }) { |
|
3
|
|
|
|
|
18
|
|
49
|
1
|
|
|
|
|
38
|
$conf = $block; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
525
|
return $conf->get($key); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |