line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Brackup::ConfigSection; |
2
|
14
|
|
|
14
|
|
71
|
use strict; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
417
|
|
3
|
14
|
|
|
14
|
|
71
|
use warnings; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
13778
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
33
|
|
|
33
|
0
|
414
|
my ($class, $name) = @_; |
7
|
33
|
|
|
|
|
314
|
return bless { |
8
|
|
|
|
|
|
|
_name => $name, |
9
|
|
|
|
|
|
|
_accessed => {}, # key => 1 |
10
|
|
|
|
|
|
|
}, $class; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub name { |
14
|
35
|
|
|
35
|
0
|
771
|
my $self = shift; |
15
|
35
|
|
|
|
|
520
|
return $self->{_name}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub add { |
19
|
84
|
|
|
84
|
0
|
518
|
my ($self, $key, $val) = @_; |
20
|
84
|
|
100
|
|
|
107
|
push @{ $self->{$key} ||= [] }, $val; |
|
84
|
|
|
|
|
733
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub unused_config { |
24
|
15
|
|
|
15
|
0
|
44
|
my $self = shift; |
25
|
15
|
100
|
100
|
|
|
104
|
return sort grep { $_ ne "_name" && $_ ne "_accessed" && ! $self->{_accessed}{$_} } keys %$self; |
|
82
|
|
|
|
|
703
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub path_value { |
29
|
15
|
|
|
15
|
0
|
56
|
my ($self, $key) = @_; |
30
|
15
|
|
50
|
|
|
214
|
my $val = $self->value($key) || ""; |
31
|
15
|
50
|
33
|
|
|
648
|
die "Path '$key' of '$val' isn't a valid directory\n" |
32
|
|
|
|
|
|
|
unless $val && -d $val; |
33
|
15
|
|
|
|
|
226
|
return $val; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub byte_value { |
37
|
24
|
|
|
24
|
0
|
67
|
my ($self, $key) = @_; |
38
|
24
|
|
|
|
|
56
|
my $val = $self->value($key); |
39
|
24
|
100
|
|
|
|
156
|
return 0 unless $val; |
40
|
10
|
50
|
|
|
|
219
|
return $1 if $val =~ /^(\d+)b?$/i; |
41
|
10
|
50
|
|
|
|
318
|
return $1 * 1024 if $val =~ /^(\d+)kb?$/i; |
42
|
0
|
0
|
|
|
|
0
|
return $1 * 1024 * 1024 if $val =~ /^(\d+)mb?$/i; |
43
|
0
|
|
|
|
|
0
|
die "Unrecognized size format for $key: '$val'\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub bool_value { |
47
|
8
|
|
|
8
|
0
|
88
|
my ($self, $key) = @_; |
48
|
8
|
|
|
|
|
172
|
my $val = $self->value($key); |
49
|
8
|
50
|
|
|
|
67
|
return 0 if ! $val; |
50
|
0
|
0
|
|
|
|
0
|
return 1 if $val =~ /^(1|true|yes|on)$/i; |
51
|
0
|
0
|
|
|
|
0
|
return 0 if $val =~ /^(0|false|no|off)$/i; |
52
|
0
|
|
|
|
|
0
|
die "Unrecognized boolean value for $key: '$val'\n"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub value { |
56
|
145
|
|
|
145
|
0
|
10505
|
my ($self, $key) = @_; |
57
|
145
|
|
|
|
|
1020
|
$self->{_accessed}{$key} = 1; |
58
|
145
|
|
|
|
|
250
|
my $vals = $self->{$key}; |
59
|
145
|
100
|
|
|
|
813
|
return undef unless $vals; |
60
|
76
|
50
|
|
|
|
242
|
die "Configuration section '$self->{_name}' has multiple values of key '$key' where only one is expected.\n" |
61
|
|
|
|
|
|
|
if @$vals > 1; |
62
|
76
|
|
|
|
|
859
|
return $vals->[0]; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub values { |
66
|
53
|
|
|
53
|
0
|
1482
|
my ($self, $key) = @_; |
67
|
53
|
|
|
|
|
118
|
$self->{_accessed}{$key} = 1; |
68
|
53
|
|
|
|
|
93
|
my $vals = $self->{$key}; |
69
|
53
|
100
|
|
|
|
210
|
return () unless $vals; |
70
|
24
|
|
|
|
|
116
|
return @$vals; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub keys { |
74
|
5
|
|
|
5
|
0
|
4
|
my $self = shift; |
75
|
5
|
|
|
|
|
33
|
return grep !/^_/, keys %$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |