line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Frontend; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
198363
|
use 5.006; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
300
|
|
4
|
6
|
|
|
6
|
|
45
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
8430
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.18'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
16
|
|
|
16
|
1
|
31
|
my $class=shift; |
10
|
16
|
|
|
|
|
28
|
my $backend=shift; |
11
|
16
|
|
|
|
|
20
|
my $self; |
12
|
|
|
|
|
|
|
|
13
|
16
|
|
|
|
|
96
|
$self->{"backend"}=$backend; |
14
|
16
|
|
|
|
|
38
|
$self->{"cache_items"}=0; |
15
|
16
|
|
|
|
|
45
|
$self->{"cache"}={}; |
16
|
|
|
|
|
|
|
|
17
|
16
|
|
|
|
|
40
|
bless $self,$class; |
18
|
|
|
|
|
|
|
|
19
|
16
|
|
|
|
|
56
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
##################################################### |
23
|
|
|
|
|
|
|
# Cache |
24
|
|
|
|
|
|
|
##################################################### |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub cache { |
27
|
1
|
|
|
1
|
1
|
6
|
my ($self,$cache_on)=@_; |
28
|
1
|
|
|
|
|
5
|
$self->{"cache_items"}=$cache_on; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub clear_cache { |
32
|
0
|
|
|
0
|
1
|
0
|
my ($self)=@_; |
33
|
0
|
|
|
|
|
0
|
$self->{"cache"}={}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
##################################################### |
37
|
|
|
|
|
|
|
# Variables |
38
|
|
|
|
|
|
|
##################################################### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub set { |
41
|
50
|
|
|
50
|
1
|
130
|
my ($self,$var,$val)=@_; |
42
|
50
|
100
|
|
|
|
130
|
if ($self->{"cache_items"}) { |
43
|
2
|
100
|
|
|
|
7
|
if (exists $self->{"cache"}->{$var}) { |
44
|
1
|
|
|
|
|
2
|
delete $self->{"cache"}->{$var}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
50
|
|
|
|
|
195
|
$self->{"backend"}->set($var,$val); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get { |
51
|
118
|
|
|
118
|
1
|
1704
|
my ($self,$var,$preset)=@_; |
52
|
118
|
100
|
|
|
|
319
|
if ($self->{"cache_items"}) { |
53
|
8
|
100
|
|
|
|
17
|
if (exists $self->{"cache"}->{$var}) { |
54
|
1
|
|
|
|
|
5
|
return $self->{"cache"}->{$var}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
7
|
|
|
|
|
22
|
my $val=$self->{"backend"}->get($var); |
58
|
7
|
100
|
|
|
|
16
|
if (not defined $val) { $val=$preset; } |
|
1
|
|
|
|
|
2
|
|
59
|
7
|
|
|
|
|
625
|
$self->{"cache"}->{$var}=$val; |
60
|
7
|
|
|
|
|
28
|
return $val; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
110
|
|
|
|
|
411
|
my $val=$self->{"backend"}->get($var); |
65
|
110
|
100
|
|
|
|
307
|
if (not defined $val) { $val=$preset; } |
|
32
|
|
|
|
|
50
|
|
66
|
110
|
|
|
|
|
643
|
return $val; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub del { |
71
|
36
|
|
|
36
|
1
|
774
|
my ($self,$var)=@_; |
72
|
36
|
|
|
|
|
125
|
$self->{"backend"}->del($var); |
73
|
36
|
100
|
|
|
|
113
|
if ($self->{"cache_items"}) { |
74
|
1
|
50
|
|
|
|
4
|
if (exists $self->{"cache"}->{$var}) { |
75
|
1
|
|
|
|
|
3
|
delete $self->{"cache"}->{$var}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
36
|
|
|
|
|
99
|
$self->del_props($var); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub exists { |
82
|
47
|
|
|
47
|
1
|
68
|
my ($self,$var)=@_; |
83
|
47
|
100
|
|
|
|
153
|
if ($self->{"cache_items"}) { |
84
|
1
|
50
|
|
|
|
4
|
if (exists $self->{"cache"}->{$var}) { |
85
|
0
|
|
|
|
|
0
|
return defined $self->{"cache"}->{$var}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
1
|
|
|
|
|
3
|
my $val=$self->{"backend"}->get($var); |
89
|
1
|
|
|
|
|
5
|
return defined $val; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
46
|
|
|
|
|
145
|
my $val=$self->{"backend"}->get($var); |
94
|
46
|
|
|
|
|
241
|
return defined $val; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub move { |
99
|
3
|
|
|
3
|
1
|
8
|
my ($self,$fromvar,$tovar)=@_; |
100
|
3
|
|
|
|
|
12
|
for my $prop ( $self->properties($fromvar) ) { |
101
|
6
|
50
|
|
|
|
17
|
if ($self->exists_prop($fromvar,$prop)) { |
102
|
6
|
|
|
|
|
17
|
$self->set_prop($tovar,$prop,$self->get_prop($fromvar,$prop)); |
103
|
6
|
|
|
|
|
21
|
$self->del_prop($fromvar,$prop); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
3
|
50
|
|
|
|
8
|
if ($self->exists($fromvar)) { |
107
|
3
|
|
|
|
|
10
|
$self->set($tovar,$self->get($fromvar)); |
108
|
3
|
|
|
|
|
11
|
$self->del($fromvar); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
##################################################### |
113
|
|
|
|
|
|
|
# Properties |
114
|
|
|
|
|
|
|
##################################################### |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub set_prop { |
117
|
18
|
|
|
18
|
1
|
927
|
my ($self,$var,$prop,$val)=@_; |
118
|
18
|
|
|
|
|
58
|
$self->set("#props_exist#.$var",1); |
119
|
18
|
|
|
|
|
77
|
$self->set("#prop#.$var.$prop",$val); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub get_prop { |
123
|
36
|
|
|
36
|
1
|
104
|
my ($self,$var,$prop,$default)=@_; |
124
|
36
|
|
|
|
|
124
|
return $self->get("#prop#.$var.$prop",$default); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub del_prop { |
128
|
17
|
|
|
17
|
1
|
32
|
my ($self,$var,$prop)=@_; |
129
|
17
|
|
|
|
|
58
|
return $self->del("#prop#.$var.$prop"); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub exists_prop { |
133
|
6
|
|
|
6
|
1
|
14
|
my ($self,$var,$prop)=@_; |
134
|
6
|
|
|
|
|
20
|
return $self->exists("#prop#.$var.$prop"); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub move_prop { |
138
|
2
|
|
|
2
|
1
|
945
|
my ($self,$var,$fromprop,$toprop)=@_; |
139
|
2
|
50
|
|
|
|
8
|
if ($self->exists($var,$fromprop)) { |
140
|
2
|
|
|
|
|
8
|
$self->set_prop($var,$toprop,$self->get_prop($var,$fromprop)); |
141
|
2
|
|
|
|
|
10
|
$self->del_prop($var,$fromprop); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub del_props { |
146
|
36
|
|
|
36
|
0
|
67
|
my ($self,$var)=@_; |
147
|
36
|
100
|
|
|
|
107
|
if ($self->exists("#props_exist#.$var")) { |
148
|
7
|
|
|
|
|
20
|
my @props=$self->properties($var); |
149
|
7
|
|
|
|
|
14
|
for my $v (@props) { |
150
|
6
|
|
|
|
|
48
|
$self->del_prop($var,$v); |
151
|
|
|
|
|
|
|
} |
152
|
7
|
|
|
|
|
28
|
$self->del("#props_exist#.$var"); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
##################################################### |
157
|
|
|
|
|
|
|
# Variables/properties |
158
|
|
|
|
|
|
|
##################################################### |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub properties { |
161
|
13
|
|
|
13
|
1
|
25
|
my ($self,$var)=@_; |
162
|
13
|
|
|
|
|
23
|
my $prefix="#prop#.$var"; |
163
|
13
|
|
|
|
|
25
|
my $N=length($prefix); |
164
|
13
|
|
|
|
|
18
|
my @props; |
165
|
13
|
|
|
|
|
45
|
for my $prop ( grep { (substr($_,0,$N) eq $prefix) } $self->{"backend"}->variables() ) { |
|
117
|
|
|
|
|
244
|
|
166
|
18
|
|
|
|
|
50
|
push @props,substr($prop,$N+1); |
167
|
|
|
|
|
|
|
} |
168
|
13
|
|
|
|
|
63
|
return @props; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub variables { |
172
|
7
|
|
|
7
|
1
|
33
|
my ($self)=@_; |
173
|
7
|
|
|
|
|
14
|
my $prefix="#prop#."; |
174
|
7
|
|
|
|
|
14
|
my $N=length($prefix); |
175
|
7
|
|
|
|
|
33
|
return grep { (substr($_,0,$N) ne $prefix) } $self->{"backend"}->variables(); |
|
29
|
|
|
|
|
94
|
|
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
##################################################### |
179
|
|
|
|
|
|
|
# info |
180
|
|
|
|
|
|
|
##################################################### |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub cached { |
183
|
5
|
|
|
5
|
0
|
6
|
my $self=shift; |
184
|
5
|
|
|
|
|
5
|
my $items=scalar (keys %{$self->{"cache"}}); |
|
5
|
|
|
|
|
8
|
|
185
|
5
|
|
|
|
|
17
|
return $items; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
__END__ |