line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Reload; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Config::Reload::VERSION = '0.21'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
#ABSTRACT: Load config files, reload when files changed. |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
99286
|
use v5.10; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
131
|
|
8
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
121
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
2522
|
use Config::ZOMG '1.000000'; |
|
3
|
|
|
|
|
214053
|
|
|
3
|
|
|
|
|
144
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
29
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
15
|
|
13
|
3
|
|
|
3
|
|
917
|
use Sub::Quote 'quote_sub'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
155
|
|
14
|
3
|
|
|
3
|
|
28
|
use Digest::MD5 qw(md5_hex); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
167
|
|
15
|
3
|
|
|
3
|
|
3129
|
use Try::Tiny; |
|
3
|
|
|
|
|
5149
|
|
|
3
|
|
|
|
|
183
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
1778
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
625
|
|
|
3
|
|
|
|
|
22
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw(files_hash); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has wait => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
default => quote_sub q{ 60 }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has checked => ( is => 'rw' ); |
28
|
|
|
|
|
|
|
has loaded => ( is => 'rw' ); |
29
|
|
|
|
|
|
|
has error => ( is => 'rw' ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has _md5 => ( is => 'rw' ); # caches $self->md5($self->found) |
32
|
|
|
|
|
|
|
has _zomg => ( is => 'rw', handles => [qw(find found)] ); |
33
|
|
|
|
|
|
|
has _config => ( is => 'rw' ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub BUILD { |
36
|
3
|
|
|
3
|
0
|
7335
|
my ($self, $given) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# don't pass to Config::ZOMG |
39
|
3
|
|
|
|
|
18
|
delete $given->{$_} for qw(wait error checked); |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
45
|
$self->_zomg( Config::ZOMG->new($given) ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load { |
45
|
5
|
|
|
5
|
1
|
9730
|
my $self = shift; |
46
|
5
|
|
|
|
|
14
|
my $zomg = $self->_zomg; |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
30
|
if ($self->_config) { |
49
|
2
|
100
|
|
|
|
11
|
if (time < $self->checked + $self->wait) { |
50
|
1
|
|
|
|
|
9
|
return $self->_config; |
51
|
|
|
|
|
|
|
} |
52
|
1
|
50
|
|
|
|
6
|
if ($self->_md5 eq files_hash( $zomg->find )) { |
53
|
0
|
|
|
|
|
0
|
$self->checked(time); |
54
|
0
|
|
|
|
|
0
|
return $self->_config; |
55
|
|
|
|
|
|
|
} else { |
56
|
1
|
|
|
|
|
6
|
$self->_config(undef); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
26
|
$self->checked(time); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
try { |
63
|
4
|
|
|
4
|
|
174
|
$self->error(undef); |
64
|
4
|
|
|
|
|
18
|
$self->_config( $zomg->reload ); # may die on error |
65
|
3
|
|
|
|
|
15511
|
$self->loaded(time); |
66
|
3
|
|
|
|
|
43
|
$self->_md5( files_hash( $self->found ) ); |
67
|
|
|
|
|
|
|
} catch { |
68
|
1
|
|
|
1
|
|
5562
|
$self->error($_); |
69
|
1
|
|
|
|
|
4
|
$self->loaded(undef); |
70
|
1
|
|
|
|
|
3
|
$self->_md5( files_hash() ); |
71
|
1
|
|
|
|
|
8
|
$self->_config( { } ); |
72
|
4
|
|
|
|
|
47
|
}; |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
132
|
return $self->_config; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub files_hash { |
79
|
5
|
|
|
5
|
1
|
3327
|
md5_hex( map { my @s = stat($_); ($_, $s[9], $s[7]) } sort @_ ); |
|
4
|
|
|
|
|
77
|
|
|
4
|
|
|
|
|
49
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |