line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Backend::String; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
61274
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
116
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2565
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
6
|
|
|
6
|
1
|
183
|
my $class=shift; |
8
|
6
|
|
|
|
|
11
|
my $strref=shift; |
9
|
6
|
|
|
|
|
8
|
my $self; |
10
|
|
|
|
|
|
|
|
11
|
6
|
100
|
|
|
|
24
|
if (ref($strref) ne "SCALAR") { |
12
|
1
|
|
|
|
|
15
|
die "Conf::String must be initialized with a reference to a string"; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
11
|
$self->{"ref"}=$strref; |
16
|
5
|
|
|
|
|
7
|
my $str=${$strref}; |
|
5
|
|
|
|
|
10
|
|
17
|
|
|
|
|
|
|
|
18
|
5
|
|
|
|
|
7
|
my @cfgs; |
19
|
5
|
|
|
|
|
7
|
my $k=0; |
20
|
5
|
|
|
|
|
7
|
my $i=0; |
21
|
5
|
|
|
|
|
8
|
my $N=length $str; |
22
|
5
|
|
|
|
|
13
|
while ($i<$N) { |
23
|
204
|
100
|
|
|
|
313
|
if (substr($str,$i,2) eq "\n%") { |
24
|
14
|
100
|
|
|
|
28
|
if (substr($str,$i,3) ne "\n%%") { |
25
|
10
|
|
|
|
|
17
|
my $cfg=substr($str,$k,($i-$k)); |
26
|
10
|
|
|
|
|
18
|
$cfg=~s/\n%%/\n%/g; |
27
|
10
|
|
|
|
|
10
|
$k=$i+2; |
28
|
10
|
|
|
|
|
16
|
push @cfgs,$cfg; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
4
|
|
|
|
|
6
|
$i+=1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
204
|
|
|
|
|
284
|
$i+=1; |
35
|
|
|
|
|
|
|
} |
36
|
5
|
100
|
|
|
|
14
|
if ($str ne "") { |
37
|
4
|
|
|
|
|
7
|
my $cfg=substr($str,$k,$N); |
38
|
4
|
|
|
|
|
15
|
$cfg=~s/\n%%/\n%/g; |
39
|
4
|
|
|
|
|
8
|
push @cfgs,$cfg; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
15
|
for my $cfg (@cfgs) { |
43
|
14
|
|
|
|
|
36
|
my ($var,$val) = split /=/,$cfg,2; |
44
|
14
|
|
|
|
|
39
|
$self->{"cfg"}->{$var}=$val; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
16
|
bless $self,$class; |
48
|
5
|
|
|
|
|
38
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub DESTROY { |
52
|
5
|
|
|
5
|
|
705
|
my $self=shift; |
53
|
5
|
|
|
|
|
10
|
$self->commit(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub commit { |
57
|
26
|
|
|
26
|
0
|
568
|
my $self=shift; |
58
|
|
|
|
|
|
|
|
59
|
26
|
|
|
|
|
47
|
my $str=""; |
60
|
26
|
|
|
|
|
27
|
my $delim=""; |
61
|
26
|
|
|
|
|
30
|
for my $var (keys %{$self->{"cfg"}}) { |
|
26
|
|
|
|
|
86
|
|
62
|
154
|
|
|
|
|
168
|
$var=~s/\n%/\n%%/g; |
63
|
154
|
|
|
|
|
212
|
my $val=$self->{"cfg"}->{$var}; |
64
|
154
|
|
|
|
|
187
|
$val=~s/\n%/\n%%/g; |
65
|
154
|
|
|
|
|
238
|
my $cfg="$var"."=".$val; |
66
|
154
|
|
|
|
|
192
|
$str.=$delim.$cfg; |
67
|
154
|
|
|
|
|
232
|
$delim="\n%"; |
68
|
|
|
|
|
|
|
} |
69
|
26
|
|
|
|
|
45
|
${$self->{"ref"}}=$str; |
|
26
|
|
|
|
|
273
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub set { |
73
|
11
|
|
|
11
|
1
|
17
|
my ($self,$var,$val)=@_; |
74
|
11
|
|
|
|
|
26
|
$self->{"cfg"}->{$var}=$val; |
75
|
11
|
|
|
|
|
22
|
$self->commit(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get { |
79
|
39
|
|
|
39
|
1
|
53
|
my ($self,$var)=@_; |
80
|
39
|
|
|
|
|
108
|
return $self->{"cfg"}->{$var}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub del { |
84
|
10
|
|
|
10
|
1
|
15
|
my ($self,$var)=@_; |
85
|
10
|
|
|
|
|
23
|
delete $self->{"cfg"}->{$var}; |
86
|
10
|
|
|
|
|
22
|
$self->commit(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub variables { |
90
|
6
|
|
|
6
|
1
|
7
|
my $self=shift; |
91
|
6
|
|
|
|
|
6
|
return keys %{$self->{"cfg"}}; |
|
6
|
|
|
|
|
24
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |