line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Backend::File; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
19105
|
use 5.006; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
173
|
|
4
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4789
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
11
|
|
|
11
|
1
|
1022
|
my $class=shift; |
8
|
11
|
|
|
|
|
24
|
my $filename=shift; |
9
|
11
|
|
|
|
|
16
|
my $self; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Read in config |
12
|
|
|
|
|
|
|
|
13
|
11
|
|
|
|
|
21
|
my $str=""; |
14
|
11
|
|
|
|
|
20
|
my @order; |
15
|
|
|
|
|
|
|
my %conf; |
16
|
11
|
|
|
|
|
18
|
my $invar=0; |
17
|
11
|
|
|
|
|
19
|
my $open=1; |
18
|
11
|
|
|
|
|
20
|
my @vars_and_comments; |
19
|
|
|
|
|
|
|
|
20
|
11
|
100
|
|
|
|
417
|
open my $in,"<$filename" or $open=0;; |
21
|
11
|
100
|
|
|
|
40
|
if ($open) { |
22
|
10
|
|
|
|
|
284
|
while (my $line=<$in>) { |
23
|
63
|
|
|
|
|
202
|
$str.=$line; |
24
|
|
|
|
|
|
|
} |
25
|
10
|
|
|
|
|
103
|
close $in; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Process Comments and %% |
29
|
|
|
|
|
|
|
|
30
|
11
|
|
|
|
|
21
|
my $i=0; |
31
|
11
|
|
|
|
|
18
|
my $k=0; |
32
|
11
|
|
|
|
|
19
|
my $N=length($str); |
33
|
|
|
|
|
|
|
|
34
|
11
|
|
|
|
|
34
|
while ($i<$N) { |
35
|
753
|
100
|
|
|
|
2238
|
if (substr($str,$i,3) eq "\n%#") { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
36
|
8
|
50
|
|
|
|
19
|
if ($k!=$i) { |
37
|
8
|
|
|
|
|
16
|
push @vars_and_comments,substr($str,$k,($i-$k)); |
38
|
8
|
|
|
|
|
9
|
$k=$i+1; |
39
|
8
|
|
|
|
|
11
|
$i+=2; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} elsif (substr($str,$i,3) eq "\n%%") { |
42
|
10
|
|
|
|
|
16
|
$i+=2; |
43
|
|
|
|
|
|
|
} elsif (substr($str,$i,2) eq "\n%") { |
44
|
33
|
50
|
|
|
|
66
|
if ($k!=$i) { |
45
|
33
|
|
|
|
|
82
|
push @vars_and_comments,substr($str,$k,($i-$k)); |
46
|
33
|
|
|
|
|
36
|
$k=$i+2; |
47
|
33
|
|
|
|
|
44
|
$i+=2; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
753
|
|
|
|
|
1410
|
$i+=1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
11
|
100
|
|
|
|
35
|
if ($k!=$i) { |
54
|
10
|
|
|
|
|
31
|
push @vars_and_comments,substr($str,$k,($N-$k)); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
11
|
|
|
|
|
20
|
my $comment=0; |
58
|
11
|
|
|
|
|
23
|
for my $item (@vars_and_comments) { |
59
|
51
|
100
|
|
|
|
131
|
if ($item=~/^%#/) { |
60
|
12
|
|
|
|
|
33
|
push @order,"%#$comment,$item"; |
61
|
12
|
|
|
|
|
19
|
$comment+=1; |
62
|
|
|
|
|
|
|
} else { |
63
|
39
|
|
|
|
|
123
|
my ($var,$val)=split /=/,$item,2; |
64
|
39
|
|
|
|
|
82
|
$var=~s/^%//; |
65
|
39
|
|
|
|
|
65
|
push @order,$var; |
66
|
39
|
|
|
|
|
79
|
$val=~s/\n%%/\n%/; |
67
|
39
|
|
|
|
|
117
|
$conf{$var}=$val; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Set config to string |
72
|
|
|
|
|
|
|
|
73
|
11
|
|
|
|
|
38
|
$self->{"filename"}=$filename; |
74
|
11
|
|
|
|
|
28
|
$self->{"order"}=\@order; |
75
|
11
|
|
|
|
|
30
|
$self->{"conf"}=\%conf; |
76
|
11
|
|
|
|
|
22
|
$self->{"changed"}=0; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# bless |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
31
|
bless $self,$class; |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
|
|
149
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub DESTROY { |
86
|
11
|
|
|
11
|
|
2962
|
my $self=shift; |
87
|
11
|
|
|
|
|
505
|
$self->commit(); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub commit { |
91
|
76
|
|
|
76
|
0
|
101
|
my $self=shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Only commit on changes |
94
|
|
|
|
|
|
|
|
95
|
76
|
100
|
|
|
|
177
|
if (not $self->{"changed"}) { |
96
|
4
|
|
|
|
|
121
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Commit to file |
100
|
|
|
|
|
|
|
|
101
|
72
|
|
|
|
|
103
|
my $filename=$self->{"filename"}; |
102
|
72
|
|
|
|
|
88
|
my $firstvar=1; |
103
|
72
|
|
|
|
|
5405
|
open my $out,">$filename"; |
104
|
72
|
|
|
|
|
145
|
my $delim=""; |
105
|
72
|
|
|
|
|
91
|
my $cdelim=""; |
106
|
72
|
|
|
|
|
97
|
for my $var (@{$self->{"order"}}) { |
|
72
|
|
|
|
|
183
|
|
107
|
597
|
100
|
|
|
|
1261
|
if ($var=~/^%#/) { |
108
|
21
|
|
|
|
|
54
|
my ($cm,$val)=split /,/,$var,2; |
109
|
21
|
|
|
|
|
99
|
print $out "$cdelim$val"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
576
|
|
|
|
|
1113
|
my $val=$self->{"conf"}->{"$var"}; |
113
|
576
|
|
|
|
|
989
|
$val=~s/\n%/\n%%/g; |
114
|
576
|
|
|
|
|
1399
|
print $out "$delim$var=$val"; |
115
|
|
|
|
|
|
|
} |
116
|
597
|
|
|
|
|
736
|
$delim="\n%"; |
117
|
597
|
|
|
|
|
906
|
$cdelim="\n"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
72
|
|
|
|
|
4121
|
close $out; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub set { |
124
|
39
|
|
|
39
|
1
|
61
|
my $self=shift; |
125
|
39
|
|
|
|
|
57
|
my $var=shift; |
126
|
39
|
|
|
|
|
57
|
my $val=shift; |
127
|
|
|
|
|
|
|
|
128
|
39
|
|
|
|
|
64
|
$self->{"changed"}=1; |
129
|
|
|
|
|
|
|
|
130
|
39
|
|
|
|
|
82
|
my $oldval=$self->get($var); |
131
|
39
|
100
|
|
|
|
127
|
if (not exists $self->{"conf"}->{$var}) { |
132
|
29
|
|
|
|
|
40
|
push @{$self->{"order"}},$var; |
|
29
|
|
|
|
|
73
|
|
133
|
|
|
|
|
|
|
} |
134
|
39
|
|
|
|
|
105
|
$self->{"conf"}->{$var}=$val; |
135
|
|
|
|
|
|
|
|
136
|
39
|
|
|
|
|
87
|
$self->commit(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub get { |
140
|
164
|
|
|
164
|
1
|
227
|
my $self=shift; |
141
|
164
|
|
|
|
|
200
|
my $var=shift; |
142
|
164
|
|
|
|
|
535
|
return $self->{"conf"}->{$var}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub del { |
146
|
26
|
|
|
26
|
1
|
39
|
my ($self,$var)=@_; |
147
|
|
|
|
|
|
|
|
148
|
26
|
|
|
|
|
43
|
$self->{"changed"}=1; |
149
|
|
|
|
|
|
|
|
150
|
26
|
|
|
|
|
57
|
delete $self->{"conf"}->{$var}; |
151
|
|
|
|
|
|
|
|
152
|
26
|
|
|
|
|
41
|
my @neworder; |
153
|
26
|
|
|
|
|
34
|
for my $elem (@{$self->{"order"}}) { |
|
26
|
|
|
|
|
55
|
|
154
|
241
|
100
|
|
|
|
478
|
if ($elem ne $var) { |
155
|
217
|
|
|
|
|
378
|
push @neworder,$elem; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
26
|
|
|
|
|
58
|
$self->{"order"}=\@neworder; |
159
|
|
|
|
|
|
|
|
160
|
26
|
|
|
|
|
94
|
$self->commit(); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub variables { |
164
|
14
|
|
|
14
|
1
|
22
|
my $self=shift; |
165
|
14
|
|
|
|
|
20
|
return keys %{$self->{"conf"}}; |
|
14
|
|
|
|
|
73
|
|
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
__END__ |