| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Register::System; |
|
2
|
1
|
|
|
1
|
|
13604
|
use DBI; |
|
|
1
|
|
|
|
|
31610
|
|
|
|
1
|
|
|
|
|
1130
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
|
6
|
0
|
|
|
0
|
0
|
|
my $type=shift; |
|
7
|
0
|
|
|
|
|
|
my %params=@_; |
|
8
|
0
|
|
|
|
|
|
my $self={}; |
|
9
|
0
|
|
|
|
|
|
my $name="${type}::new"; |
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
$self->{'Type'}=$type; |
|
12
|
0
|
|
|
|
|
|
my $regpath = Register::checkReq ($name, "regpath", $params{'regpath'}); |
|
13
|
0
|
|
|
|
|
|
my $regname = Register::checkReq ($name, "regname", $params{'regname'}); |
|
14
|
0
|
|
|
|
|
|
($self->{'REGISTER_NAME'}=$regname)=~s/(\W)//g; |
|
15
|
0
|
|
|
|
|
|
$self->{'DBH'}=DBI->connect("DBI:CSV:f_dir=".$regpath,"",""); |
|
16
|
0
|
0
|
|
|
|
|
if (!(-d $regpath)) { |
|
17
|
0
|
|
|
|
|
|
printf "ERROR:\n"; |
|
18
|
0
|
|
|
|
|
|
printf "LOCATION: \<".$self->{'Type'}."\>\n"; |
|
19
|
0
|
|
|
|
|
|
printf "CAUSE: directory \<".$regpath."\> not found !!!\n"; |
|
20
|
0
|
|
|
|
|
|
exit(1); |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
0
|
0
|
|
|
|
|
if (!(-f $regpath."/".$self->{'REGISTER_NAME'})) { |
|
23
|
0
|
|
|
|
|
|
my($sql)=qq { |
|
24
|
|
|
|
|
|
|
CREATE TABLE |
|
25
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
26
|
|
|
|
|
|
|
( |
|
27
|
|
|
|
|
|
|
R_APPLICATION CHAR(255), |
|
28
|
|
|
|
|
|
|
R_SECTION CHAR(255), |
|
29
|
|
|
|
|
|
|
R_KEY CHAR(255), |
|
30
|
|
|
|
|
|
|
R_VALUE CHAR(255) |
|
31
|
|
|
|
|
|
|
) |
|
32
|
|
|
|
|
|
|
}; |
|
33
|
0
|
|
|
|
|
|
$self->{DBH}->do($sql); |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
bless $self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub getsettings { |
|
40
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
41
|
0
|
|
|
|
|
|
my ($APP,$SEC,$KEY)=@_; |
|
42
|
0
|
|
|
|
|
|
my ($row)={}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$row->{'R_VALUE'}=""; |
|
45
|
0
|
|
|
|
|
|
my ($sql) = qq { |
|
46
|
|
|
|
|
|
|
SELECT |
|
47
|
|
|
|
|
|
|
* |
|
48
|
|
|
|
|
|
|
FROM |
|
49
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
50
|
|
|
|
|
|
|
WHERE |
|
51
|
|
|
|
|
|
|
R_APPLICATION=? |
|
52
|
|
|
|
|
|
|
AND |
|
53
|
|
|
|
|
|
|
R_SECTION=? |
|
54
|
|
|
|
|
|
|
AND |
|
55
|
|
|
|
|
|
|
R_KEY=? |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
0
|
|
|
|
|
|
my($sth)=$self->{DBH}->prepare($sql); |
|
58
|
0
|
|
|
|
|
|
$sth->execute($APP,$SEC,$KEY); |
|
59
|
0
|
|
|
|
|
|
$row=$sth->fetchrow_hashref; |
|
60
|
0
|
0
|
|
|
|
|
if ($row->{'R_VALUE'} ne "") { |
|
61
|
0
|
|
|
|
|
|
return $row->{'R_VALUE'}; |
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
0
|
|
|
|
|
|
return ""; |
|
64
|
|
|
|
|
|
|
}; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub savesettings { |
|
68
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
69
|
0
|
|
|
|
|
|
my ($APP,$SEC,$KEY,$VAL)=@_; |
|
70
|
0
|
|
|
|
|
|
my ($row)={}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my($sql) = qq { |
|
73
|
|
|
|
|
|
|
SELECT |
|
74
|
|
|
|
|
|
|
* |
|
75
|
|
|
|
|
|
|
FROM |
|
76
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
77
|
|
|
|
|
|
|
WHERE |
|
78
|
|
|
|
|
|
|
R_APPLICATION=? |
|
79
|
|
|
|
|
|
|
AND |
|
80
|
|
|
|
|
|
|
R_SECTION=? |
|
81
|
|
|
|
|
|
|
AND |
|
82
|
|
|
|
|
|
|
R_KEY=? |
|
83
|
|
|
|
|
|
|
}; |
|
84
|
0
|
|
|
|
|
|
my($sth)=$self->{DBH}->prepare($sql); |
|
85
|
0
|
|
|
|
|
|
$sth->execute($APP,$SEC,$KEY); |
|
86
|
0
|
|
|
|
|
|
$row=$sth->fetchrow_hashref; |
|
87
|
0
|
0
|
|
|
|
|
if ($row->{'R_APPLICATION'} ne "") { |
|
88
|
0
|
|
|
|
|
|
$self->updatekey($APP,$SEC,$KEY,$VAL); |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
0
|
|
|
|
|
|
$self->addkey($APP,$SEC,$KEY,$VAL); |
|
91
|
|
|
|
|
|
|
}; |
|
92
|
0
|
|
|
|
|
|
$sth->finish(); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub deletesection { |
|
97
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
98
|
0
|
|
|
|
|
|
my($APP,$SEC)=@_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$sql=qq { |
|
101
|
|
|
|
|
|
|
DELETE FROM |
|
102
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
103
|
|
|
|
|
|
|
WHERE |
|
104
|
|
|
|
|
|
|
R_APPLICATION=? |
|
105
|
|
|
|
|
|
|
AND |
|
106
|
|
|
|
|
|
|
R_SECTION=? |
|
107
|
|
|
|
|
|
|
}; |
|
108
|
0
|
|
|
|
|
|
$self->{DBH}->do($sql,undef,$APP,$SEC); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub deletesettings { |
|
112
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
113
|
0
|
|
|
|
|
|
my($APP,$SEC,$KEY)=@_; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my($sql)=qq { |
|
116
|
|
|
|
|
|
|
DELETE FROM |
|
117
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
118
|
|
|
|
|
|
|
WHERE |
|
119
|
|
|
|
|
|
|
R_APPLICATION=? |
|
120
|
|
|
|
|
|
|
AND |
|
121
|
|
|
|
|
|
|
R_SECTION=? |
|
122
|
|
|
|
|
|
|
AND |
|
123
|
|
|
|
|
|
|
R_KEY=? |
|
124
|
|
|
|
|
|
|
}; |
|
125
|
0
|
|
|
|
|
|
$self->{DBH}->do($sql,undef,$APP,$SEC,$KEY); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub updatekey { |
|
129
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
130
|
0
|
|
|
|
|
|
my ($APP,$SEC,$KEY,$VAL)=@_; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my($sql)=qq { |
|
133
|
|
|
|
|
|
|
UPDATE |
|
134
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
135
|
|
|
|
|
|
|
SET |
|
136
|
|
|
|
|
|
|
R_VALUE=? |
|
137
|
|
|
|
|
|
|
WHERE |
|
138
|
|
|
|
|
|
|
R_APPLICATION=? |
|
139
|
|
|
|
|
|
|
AND |
|
140
|
|
|
|
|
|
|
R_SECTION=? |
|
141
|
|
|
|
|
|
|
AND |
|
142
|
|
|
|
|
|
|
R_KEY=? |
|
143
|
|
|
|
|
|
|
}; |
|
144
|
0
|
|
|
|
|
|
$self->{DBH}->do($sql,undef,$VAL,$APP,$SEC,$KEY); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub addkey { |
|
148
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
149
|
0
|
|
|
|
|
|
my ($APP,$SEC,$KEY,$VAL)=@_; |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my($sql)=qq { |
|
152
|
|
|
|
|
|
|
INSERT INTO |
|
153
|
|
|
|
|
|
|
$self->{'REGISTER_NAME'} |
|
154
|
|
|
|
|
|
|
( |
|
155
|
|
|
|
|
|
|
R_APPLICATION, |
|
156
|
|
|
|
|
|
|
R_SECTION, |
|
157
|
|
|
|
|
|
|
R_KEY, |
|
158
|
|
|
|
|
|
|
R_VALUE |
|
159
|
|
|
|
|
|
|
) |
|
160
|
|
|
|
|
|
|
VALUES ( ?,?,?,? ) |
|
161
|
|
|
|
|
|
|
}; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$self->{DBH}->do($sql,undef,$APP,$SEC,$KEY,$VAL); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 NAME |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Register::System - Implementation of the Win32 registry in Unix |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
use Register; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$sysreg=new Register::System ( |
|
177
|
|
|
|
|
|
|
'regpath' => "/etc", |
|
178
|
|
|
|
|
|
|
'regname' => "SYSREG" |
|
179
|
|
|
|
|
|
|
); |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
$sysreg->savesettings("APPLICATION","SECTION","KEY","VALUE"); |
|
182
|
|
|
|
|
|
|
$value=$sysreg->getsettings("APPLICATION","SECTION","KEY"); |
|
183
|
|
|
|
|
|
|
$sysreg->deletesettings("APPLICATION","SECTION","KEY"); |
|
184
|
|
|
|
|
|
|
$sysreg->deletesection("APPLICATION","SECTION"); |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The Register::System module permit to create a registry file like |
|
189
|
|
|
|
|
|
|
Windows for save global information about your program. |
|
190
|
|
|
|
|
|
|
With the use of CSV dbd , the file created is readable by DBI without |
|
191
|
|
|
|
|
|
|
problem. |
|
192
|
|
|
|
|
|
|
Here CSV table specifics: |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
FIELD_NAME FIELD_TYPE |
|
195
|
|
|
|
|
|
|
---------------------------------- |
|
196
|
|
|
|
|
|
|
R_APPLICATION CHAR |
|
197
|
|
|
|
|
|
|
R_SECTION CHAR |
|
198
|
|
|
|
|
|
|
R_KEY CHAR |
|
199
|
|
|
|
|
|
|
R_VALUE CHAR |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 Function |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The statament create the Register::System object and return the |
|
208
|
|
|
|
|
|
|
reference to him. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$sysreg=new Register::System ( |
|
211
|
|
|
|
|
|
|
'regpath' => "/etc", |
|
212
|
|
|
|
|
|
|
'regname' => "SYSREG" |
|
213
|
|
|
|
|
|
|
); |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Parameter : |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
regpath specify the path where new statament search for |
|
218
|
|
|
|
|
|
|
registers. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
regname specify the name of the register to use. |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Finaly if regpath don't exist the program return an error message at compile |
|
223
|
|
|
|
|
|
|
time, if the register don't exist it is maked. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 Function |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
The savesettings function , save the value argument in the key of the |
|
228
|
|
|
|
|
|
|
section of the program. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
$sysreg->savesettings("APPLICATION","SECTION","KEY","VALUE"); |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
If the key don't exist it make (it make also application and section |
|
233
|
|
|
|
|
|
|
without specify befor), else if key already exist and value is different |
|
234
|
|
|
|
|
|
|
from previous it update value. |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 Function |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
The getsettings function retrieve the value of the specified key. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
$value=$sysreg->getsettings("APPLICATION","SECTION","KEY"); |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 Function |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
The deletesettings function delete the entry key specified. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$sysreg->deletesettings("APPLICATION","SECTION","KEY"); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 Function |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
The deletesection function delete the entry section specified. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$sysreg->deletesection("APPLICATION","SECTION"); |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHOR |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Vecchio Fabrizio |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
L,L,L |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |