line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
5
|
|
|
5
|
|
26521
|
use base qw(Exporter); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
489
|
|
5
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
89
|
|
6
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
128
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
5
|
|
|
5
|
|
3542
|
use Error::Pure qw(err); |
|
5
|
|
|
|
|
56159
|
|
|
5
|
|
|
|
|
115
|
|
10
|
5
|
|
|
5
|
|
262
|
use Readonly; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
2848
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(conflict hash hash_array); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Version. |
16
|
|
|
|
|
|
|
our $VERSION = 0.06; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Check conflits. |
19
|
|
|
|
|
|
|
sub conflict { |
20
|
13
|
|
|
13
|
1
|
746
|
my ($self, $config_hr, $key) = @_; |
21
|
13
|
100
|
66
|
|
|
56
|
if ($self->{'set_conflicts'} && exists $config_hr->{$key}) { |
22
|
4
|
|
|
|
|
9
|
err 'Conflict in \''.join('.', @{$self->{'stack'}}, $key). |
|
4
|
|
|
|
|
35
|
|
23
|
|
|
|
|
|
|
'\'.'; |
24
|
|
|
|
|
|
|
} |
25
|
9
|
|
|
|
|
16
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Create record to hash. |
29
|
|
|
|
|
|
|
sub hash { |
30
|
8
|
|
|
8
|
1
|
18624
|
my ($self, $key_ar, $val) = @_; |
31
|
8
|
|
|
|
|
14
|
my $config_hr = $self->{'config'}; |
32
|
8
|
|
|
|
|
11
|
my $num = 0; |
33
|
8
|
|
|
|
|
9
|
foreach my $key (@{$key_ar}) { |
|
8
|
|
|
|
|
17
|
|
34
|
11
|
100
|
|
|
|
13
|
if ($num != $#{$key_ar}) { |
|
11
|
|
|
|
|
25
|
|
35
|
4
|
100
|
|
|
|
21
|
if (! exists $config_hr->{$key}) { |
|
|
100
|
|
|
|
|
|
36
|
1
|
|
|
|
|
3
|
$config_hr->{$key} = {}; |
37
|
|
|
|
|
|
|
} elsif (ref $config_hr->{$key} ne 'HASH') { |
38
|
2
|
|
|
|
|
5
|
conflict($self, $config_hr, $key); |
39
|
1
|
|
|
|
|
2
|
$config_hr->{$key} = {}; |
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
5
|
$config_hr = $config_hr->{$key}; |
42
|
3
|
|
|
|
|
3
|
push @{$self->{'stack'}}, $key; |
|
3
|
|
|
|
|
7
|
|
43
|
|
|
|
|
|
|
} else { |
44
|
7
|
|
|
|
|
14
|
conflict($self, $config_hr, $key); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Process callback. |
47
|
6
|
100
|
|
|
|
14
|
if (defined $self->{'callback'}) { |
48
|
|
|
|
|
|
|
$val = $self->{'callback'}->( |
49
|
1
|
|
|
|
|
2
|
[@{$self->{'stack'}}, $key], |
|
1
|
|
|
|
|
4
|
|
50
|
|
|
|
|
|
|
$val, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Add value. |
55
|
6
|
|
|
|
|
14
|
$config_hr->{$key} = $val; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Clean. |
58
|
6
|
|
|
|
|
11
|
$self->{'stack'} = []; |
59
|
|
|
|
|
|
|
} |
60
|
9
|
|
|
|
|
17
|
$num++; |
61
|
|
|
|
|
|
|
} |
62
|
6
|
|
|
|
|
13
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Create record to hash. |
66
|
|
|
|
|
|
|
sub hash_array { |
67
|
10
|
|
|
10
|
1
|
19467
|
my ($self, $key_ar, $val) = @_; |
68
|
10
|
|
|
|
|
21
|
my $config_hr = $self->{'config'}; |
69
|
10
|
|
|
|
|
12
|
my $num = 0; |
70
|
10
|
|
|
|
|
13
|
foreach my $key (@{$key_ar}) { |
|
10
|
|
|
|
|
17
|
|
71
|
13
|
100
|
|
|
|
14
|
if ($num != $#{$key_ar}) { |
|
13
|
|
|
|
|
28
|
|
72
|
4
|
100
|
|
|
|
16
|
if (! exists $config_hr->{$key}) { |
|
|
100
|
|
|
|
|
|
73
|
1
|
|
|
|
|
3
|
$config_hr->{$key} = {}; |
74
|
|
|
|
|
|
|
} elsif (ref $config_hr->{$key} ne 'HASH') { |
75
|
2
|
|
|
|
|
6
|
conflict($self, $config_hr, $key); |
76
|
1
|
|
|
|
|
2
|
$config_hr->{$key} = {}; |
77
|
|
|
|
|
|
|
} |
78
|
3
|
|
|
|
|
6
|
$config_hr = $config_hr->{$key}; |
79
|
3
|
|
|
|
|
4
|
push @{$self->{'stack'}}, $key; |
|
3
|
|
|
|
|
7
|
|
80
|
|
|
|
|
|
|
} else { |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Process callback. |
83
|
9
|
100
|
|
|
|
30
|
if (defined $self->{'callback'}) { |
84
|
|
|
|
|
|
|
$val = $self->{'callback'}->( |
85
|
3
|
|
|
|
|
4
|
[@{$self->{'stack'}}, $key], |
|
3
|
|
|
|
|
12
|
|
86
|
|
|
|
|
|
|
$val, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Add value. |
91
|
9
|
100
|
|
|
|
32
|
if (ref $config_hr->{$key} eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
92
|
1
|
|
|
|
|
2
|
push @{$config_hr->{$key}}, $val; |
|
1
|
|
|
|
|
4
|
|
93
|
|
|
|
|
|
|
} elsif ($config_hr->{$key}) { |
94
|
2
|
|
|
|
|
4
|
my $foo = $config_hr->{$key}; |
95
|
2
|
|
|
|
|
5
|
$config_hr->{$key} = [$foo, $val]; |
96
|
|
|
|
|
|
|
} else { |
97
|
6
|
|
|
|
|
15
|
$config_hr->{$key} = $val; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Clean. |
101
|
9
|
|
|
|
|
15
|
$self->{'stack'} = []; |
102
|
|
|
|
|
|
|
} |
103
|
12
|
|
|
|
|
26
|
$num++; |
104
|
|
|
|
|
|
|
} |
105
|
9
|
|
|
|
|
22
|
return; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |