line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZConf::DBI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22113
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
1575
|
use ZConf; |
|
1
|
|
|
|
|
163818
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
15
|
use base 'Error::Helper'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1541
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
ZConf::DBI - Stores DBI connection information in ZConf. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.1.0 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.1.0'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use ZConf::DBI; |
23
|
|
|
|
|
|
|
use DBI::Shell; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $foo=ZConf::DBI->new; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $ds=$foo->getDS('tigerline'); |
28
|
|
|
|
|
|
|
my $user=$foo->getDSuser('tigerline'); |
29
|
|
|
|
|
|
|
my $pass=$foo->getDSpass('tigerline'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
DBI::Shell->new($ds, $user, $pass)->run; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This initiates the object. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head3 hash values |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head4 zconf |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
If this is defined, it will be used instead of creating |
44
|
|
|
|
|
|
|
a new ZConf object. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new{ |
49
|
0
|
|
|
0
|
1
|
|
my %args; |
50
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
51
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $self={ |
55
|
|
|
|
|
|
|
error=>undef, |
56
|
|
|
|
|
|
|
perror=>undef, |
57
|
|
|
|
|
|
|
errorString=>undef, |
58
|
|
|
|
|
|
|
zconfconfig=>'DBI', |
59
|
|
|
|
|
|
|
}; |
60
|
0
|
|
|
|
|
|
bless $self; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#get the ZConf object |
63
|
0
|
0
|
|
|
|
|
if (!defined($args{zconf})) { |
64
|
|
|
|
|
|
|
#creates the ZConf object |
65
|
0
|
|
|
|
|
|
$self->{zconf}=ZConf->new(); |
66
|
0
|
0
|
|
|
|
|
if(defined($self->{zconf}->error)){ |
67
|
0
|
|
|
|
|
|
$self->{error}=1; |
68
|
0
|
|
|
|
|
|
$self->{perror}=1; |
69
|
0
|
|
|
|
|
|
$self->{errorString}="Could not initiate ZConf. It failed with '" |
70
|
|
|
|
|
|
|
.$self->{zconf}->error."', '". |
71
|
|
|
|
|
|
|
$self->{zconf}->errorString."'"; |
72
|
0
|
|
|
|
|
|
$self->warn; |
73
|
0
|
|
|
|
|
|
return $self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
}else { |
76
|
0
|
|
|
|
|
|
$self->{zconf}=$args{zconf}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#check if the config exists |
80
|
0
|
|
|
|
|
|
my $returned = $self->{zconf}->configExists($self->{zconfconfig}); |
81
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
82
|
0
|
|
|
|
|
|
$self->{error}=1; |
83
|
0
|
|
|
|
|
|
$self->{perror}=1; |
84
|
0
|
|
|
|
|
|
$self->{errorString}="Checking if '".$self->{zconfconfig}."' exists failed. error='". |
85
|
|
|
|
|
|
|
$self->{zconf}->error."', errorString='". |
86
|
|
|
|
|
|
|
$self->{zconf}->errorString."'"; |
87
|
0
|
|
|
|
|
|
$self->warn; |
88
|
0
|
|
|
|
|
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#initiate the config if it does not exist |
92
|
0
|
0
|
|
|
|
|
if (!$returned) { |
93
|
|
|
|
|
|
|
#create the config |
94
|
0
|
|
|
|
|
|
$self->{zconf}->createConfig($self->{zconfconfig}); |
95
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
96
|
0
|
|
|
|
|
|
$self->{error}=1; |
97
|
0
|
|
|
|
|
|
$self->{perror}=1; |
98
|
0
|
|
|
|
|
|
$self->{errorString}="Checking if '".$self."' exists failed. error='". |
99
|
|
|
|
|
|
|
$self->{zconf}->error."', errorString='". |
100
|
|
|
|
|
|
|
$self->{zconf}->errorString."'"; |
101
|
0
|
|
|
|
|
|
$self->warn; |
102
|
0
|
|
|
|
|
|
return $self; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#init it |
106
|
0
|
|
|
|
|
|
$self->init; |
107
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
108
|
0
|
|
|
|
|
|
$self->{perror}=1; |
109
|
0
|
|
|
|
|
|
$self->{errorString}='Init failed.'; |
110
|
0
|
|
|
|
|
|
$self->warn; |
111
|
0
|
|
|
|
|
|
return $self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
}else { |
114
|
|
|
|
|
|
|
#if we have a set, make sure we also have a set that will be loaded |
115
|
0
|
|
|
|
|
|
$returned=$self->{zconf}->defaultSetExists($self->{zconfconfig}); |
116
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
117
|
0
|
|
|
|
|
|
$self->{error}=1; |
118
|
0
|
|
|
|
|
|
$self->{perror}=1; |
119
|
0
|
|
|
|
|
|
$self->{errorString}="Checking if '".$self."' exists failed. error='". |
120
|
|
|
|
|
|
|
$self->{zconf}->error."', errorString='". |
121
|
|
|
|
|
|
|
$self->{zconf}->errorString."'"; |
122
|
0
|
|
|
|
|
|
$self->warn; |
123
|
0
|
|
|
|
|
|
return $self; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#initiliaze a the default set if needed. |
127
|
0
|
0
|
|
|
|
|
if (!$returned) { |
128
|
|
|
|
|
|
|
#init it |
129
|
0
|
|
|
|
|
|
$self->init; |
130
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
131
|
0
|
|
|
|
|
|
$self->{perror}=1; |
132
|
0
|
|
|
|
|
|
$self->{errorString}='Init failed.'; |
133
|
0
|
|
|
|
|
|
$self->warn; |
134
|
0
|
|
|
|
|
|
return $self; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#read the config |
141
|
0
|
|
|
|
|
|
$self->{zconf}->read({config=>$self->{zconfconfig}}); |
142
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
143
|
0
|
|
|
|
|
|
$self->{error}=1; |
144
|
0
|
|
|
|
|
|
$self->{perror}=1; |
145
|
0
|
|
|
|
|
|
$self->{errorString}="Checking if the default set for '".$self->{zconfconfig}."' exists failed. error='". |
146
|
|
|
|
|
|
|
$self->{zconf}->error."', errorString='". |
147
|
|
|
|
|
|
|
$self->{zconf}->errorString."'"; |
148
|
0
|
|
|
|
|
|
$self->warn; |
149
|
0
|
|
|
|
|
|
return $self |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $self; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 addDS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This adds a new data source. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head3 args hash |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The only required is 'ds'. Any thing else can be undef. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head4 attr |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This hash reference contains any attributes one wishes to pass to the |
166
|
|
|
|
|
|
|
new connections. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head4 ds |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is the data source string. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head4 name |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The name of the new data source. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head4 pass |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This is the password to use. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This can be undefined. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head4 user |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This is the the user to use. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This can be undefined. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$foo->addDS({ds=>$datasource, user=>$user, pass=>$pass, name=>'some name' }); |
189
|
|
|
|
|
|
|
if($foo->error){ |
190
|
|
|
|
|
|
|
print "Error!\n"; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub addDS{ |
196
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
197
|
0
|
|
|
|
|
|
my %args; |
198
|
0
|
|
|
|
|
|
%args=%{$_[1]}; |
|
0
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
#blanks any previous error |
201
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
202
|
0
|
|
|
|
|
|
return undef; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
if (!defined( $args{name} )) { |
206
|
0
|
|
|
|
|
|
$self->{error}=2; |
207
|
0
|
|
|
|
|
|
$self->{errorString}='No name specified'; |
208
|
0
|
|
|
|
|
|
$self->warn; |
209
|
0
|
|
|
|
|
|
return undef; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
0
|
0
|
|
|
|
|
if (!defined( $args{ds} )) { |
213
|
0
|
|
|
|
|
|
$self->{error}=3; |
214
|
0
|
|
|
|
|
|
$self->{errorString}='No data source specified'; |
215
|
0
|
|
|
|
|
|
$self->warn; |
216
|
0
|
|
|
|
|
|
return undef; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#make sure it does not exist already |
220
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $args{name} ); |
221
|
0
|
0
|
|
|
|
|
if ($self->error) { |
222
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
223
|
0
|
|
|
|
|
|
return undef; |
224
|
|
|
|
|
|
|
} |
225
|
0
|
0
|
|
|
|
|
if ($dsExists) { |
226
|
0
|
|
|
|
|
|
$self->{error}=4; |
227
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$args{name}.'" already exists'; |
228
|
0
|
|
|
|
|
|
$self->warn; |
229
|
0
|
|
|
|
|
|
return undef; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
#make sure the name does not have a / in it |
233
|
0
|
0
|
|
|
|
|
if ($args{name} =~ /\//) { |
234
|
0
|
|
|
|
|
|
$self->{error}=5; |
235
|
0
|
|
|
|
|
|
$self->{errorString}='The data source name, "'.$args{name}.'", contains a "/"'; |
236
|
0
|
|
|
|
|
|
$self->warn; |
237
|
0
|
|
|
|
|
|
return undef; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
#adds the datasource |
241
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/ds', $args{ds}); |
242
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
243
|
0
|
|
|
|
|
|
$self->{error}=1; |
244
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
245
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
246
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
247
|
0
|
|
|
|
|
|
$self->warn; |
248
|
0
|
|
|
|
|
|
return undef; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
#Adds the username if needed. |
252
|
|
|
|
|
|
|
#There is no need to error check this as it will work if the last setVar worked |
253
|
0
|
0
|
|
|
|
|
if (defined( $args{user} )) { |
254
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/user', $args{user}); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
#Adds the password if needed. |
257
|
0
|
0
|
|
|
|
|
if (defined( $args{pass} )) { |
258
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/pass', $args{pass}); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
#handles and attributes if specified |
262
|
0
|
0
|
|
|
|
|
if (defined( $args{attr} )) { |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
#adds each key |
265
|
0
|
|
|
|
|
|
my @keys=keys( %{ $args{attr} } ); |
|
0
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
my $int=0; |
267
|
0
|
|
|
|
|
|
while (defined( $keys[$int] )) { |
268
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/attr/'.$keys[$int] , $args{attr}{$keys[$int]} ); |
269
|
0
|
|
|
|
|
|
$int++; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
#saves it |
274
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
275
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
276
|
0
|
|
|
|
|
|
$self->{error}=1; |
277
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
278
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
279
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
280
|
0
|
|
|
|
|
|
$self->warn; |
281
|
0
|
|
|
|
|
|
return $self; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
return 1; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head2 connect |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
This connects and returns the database handle formed by DBI->connect. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This just returns the database handle and does not check if succedded or not. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Only one arguement is required and it is the name of the data source. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
my $dbh=$foo->connect('someDS'); |
296
|
|
|
|
|
|
|
if($foo->error){ |
297
|
|
|
|
|
|
|
print "Error!\n"; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub connect{ |
303
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
304
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
#blanks any previous errors |
307
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
308
|
0
|
|
|
|
|
|
return undef; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
#makes sure a DS name was specified |
312
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
313
|
0
|
|
|
|
|
|
$self->{error}=2; |
314
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
315
|
0
|
|
|
|
|
|
$self->warn; |
316
|
0
|
|
|
|
|
|
return undef; |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
#make sure it does not exist already |
320
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
321
|
0
|
0
|
|
|
|
|
if ($self->error) { |
322
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
323
|
0
|
|
|
|
|
|
return undef; |
324
|
|
|
|
|
|
|
} |
325
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
326
|
0
|
|
|
|
|
|
$self->{error}=7; |
327
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
328
|
0
|
|
|
|
|
|
$self->warn; |
329
|
0
|
|
|
|
|
|
return undef; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
#fetches the data source |
333
|
0
|
|
|
|
|
|
my $ds=$self->getDS($dsName); |
334
|
0
|
0
|
|
|
|
|
if ($self->error) { |
335
|
0
|
|
|
|
|
|
$self->warnString('getDS errored'); |
336
|
0
|
|
|
|
|
|
return undef; |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
#fetches the user for the data source |
340
|
0
|
|
|
|
|
|
my $user=$self->getDSuser($dsName); |
341
|
0
|
0
|
|
|
|
|
if ($self->error) { |
342
|
0
|
|
|
|
|
|
$self->warnString('getDSuser errored'); |
343
|
0
|
|
|
|
|
|
return undef; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
#fetches the user for the data source |
347
|
0
|
|
|
|
|
|
my $pass=$self->getDSpass($dsName); |
348
|
0
|
0
|
|
|
|
|
if ($self->error) { |
349
|
0
|
|
|
|
|
|
$self->warnString('getDSuser errored'); |
350
|
0
|
|
|
|
|
|
return undef; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
#fetches the user for the data source |
354
|
0
|
|
|
|
|
|
my %attrs=$self->getDSattrs($dsName); |
355
|
0
|
0
|
|
|
|
|
if ($self->error) { |
356
|
0
|
|
|
|
|
|
$self->warnString('getDSattrs errored'); |
357
|
0
|
|
|
|
|
|
return undef; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
#connect and return the results |
361
|
1
|
|
|
1
|
|
2448
|
use DBI; |
|
1
|
|
|
|
|
26990
|
|
|
1
|
|
|
|
|
4005
|
|
362
|
0
|
|
|
|
|
|
return DBI->connect($ds, $user, $pass, \%attrs); |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=head2 dataSourceExists |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
This checks if the specified data source exists or not. |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
Only one arguement is taken and it is the name of data source |
370
|
|
|
|
|
|
|
to check for. |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
The returned value is either a Perl boolean value. |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
if(!$foo->dataSourceExists('bar')){ |
375
|
|
|
|
|
|
|
print "The data source 'bar' does not exist\n"; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
=cut |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
sub dataSourceExists{ |
381
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
382
|
0
|
|
|
|
|
|
my $datasource=$_[1]; |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
#blanks any previous errors |
385
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
386
|
0
|
|
|
|
|
|
return undef; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
#makes sure the data source exists |
390
|
0
|
0
|
|
|
|
|
if (!defined( $datasource )) { |
391
|
0
|
|
|
|
|
|
$self->{error}=2; |
392
|
0
|
|
|
|
|
|
$self->{errorString}='No name specified'; |
393
|
0
|
|
|
|
|
|
$self->warn; |
394
|
0
|
|
|
|
|
|
return undef; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
#gets a list of data sources |
398
|
0
|
|
|
|
|
|
my @datasources=$self->listDSs; |
399
|
0
|
0
|
|
|
|
|
if ($self->error) { |
400
|
0
|
|
|
|
|
|
$self->warnString('listDSs errored'); |
401
|
0
|
|
|
|
|
|
return undef; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
#run through checking for a match |
405
|
0
|
|
|
|
|
|
my $int=0; |
406
|
0
|
|
|
|
|
|
while (defined( $datasources[$int] )) { |
407
|
0
|
0
|
|
|
|
|
if ($datasources[$int] eq $datasource) { |
408
|
0
|
|
|
|
|
|
return 1; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
0
|
|
|
|
|
|
$int++; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
0
|
|
|
|
|
|
return undef; |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
=head2 delDS |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
This removes a data source. |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
=cut |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
sub delDS{ |
424
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
425
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
#blanks any previous errors |
428
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
429
|
0
|
|
|
|
|
|
return undef; |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
#makes sure a DS name was specified |
433
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
434
|
0
|
|
|
|
|
|
$self->{error}=2; |
435
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
436
|
0
|
|
|
|
|
|
$self->warn; |
437
|
0
|
|
|
|
|
|
return undef; |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
#make sure it does not exist already |
441
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
442
|
0
|
0
|
|
|
|
|
if ($self->error) { |
443
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
444
|
0
|
|
|
|
|
|
return undef; |
445
|
|
|
|
|
|
|
} |
446
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
447
|
0
|
|
|
|
|
|
$self->{error}=7; |
448
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
449
|
0
|
|
|
|
|
|
$self->warn; |
450
|
0
|
|
|
|
|
|
return undef; |
451
|
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
|
453
|
0
|
|
|
|
|
|
my @deleted=$self->{zconf}->regexVarDel( $self->{zconfconfig}, '^datasources\/'.quotemeta($dsName).'\/' ); |
454
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
455
|
0
|
|
|
|
|
|
$self->{error}=1; |
456
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarDel failed. error="'. |
457
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
458
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
459
|
0
|
|
|
|
|
|
$self->warn; |
460
|
0
|
|
|
|
|
|
return undef; |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
#saves it |
464
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
465
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
466
|
0
|
|
|
|
|
|
$self->{error}=1; |
467
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
468
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
469
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
470
|
0
|
|
|
|
|
|
$self->warn; |
471
|
0
|
|
|
|
|
|
return $self; |
472
|
|
|
|
|
|
|
} |
473
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
|
return 1; |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
=head2 delSet |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
This removes the specified ZConf set. |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
$foo->delSet('someSet'); |
482
|
|
|
|
|
|
|
if($foo->error){ |
483
|
|
|
|
|
|
|
print "Error!\n"; |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=cut |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
sub delSet{ |
489
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
490
|
0
|
|
|
|
|
|
my $set=$_[1]; |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
#blanks any previous errors |
493
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
494
|
0
|
|
|
|
|
|
$self->warn; |
495
|
0
|
|
|
|
|
|
return undef; |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
0
|
|
|
|
|
|
$self->{zconf}->delSet($self->{zconfconfg}, $set); |
499
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
500
|
0
|
|
|
|
|
|
$self->{error}=1; |
501
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf getAvailableSets failed. error="'. |
502
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
503
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
504
|
0
|
|
|
|
|
|
$self->warn; |
505
|
0
|
|
|
|
|
|
return undef; |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
0
|
|
|
|
|
|
return 1; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
=head2 getDS |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
This gets the data source value for a data source. |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
Only one arguement is required and is the name of the data source. |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
my $ds=$foo->getDS("someDS"); |
518
|
|
|
|
|
|
|
if($foo->{error}){ |
519
|
|
|
|
|
|
|
print "Error!\n"; |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=cut |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
sub getDS{ |
525
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
526
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
#blanks any previous error |
529
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
530
|
0
|
|
|
|
|
|
return undef; |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
#makes sure a DS name was specified |
534
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
535
|
0
|
|
|
|
|
|
$self->{error}=2; |
536
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
537
|
0
|
|
|
|
|
|
$self->warn; |
538
|
0
|
|
|
|
|
|
return undef; |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
#fetches them |
542
|
0
|
|
|
|
|
|
my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/ds$' ); |
543
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
544
|
0
|
|
|
|
|
|
$self->{error}=1; |
545
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarGet failed. error="'. |
546
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
547
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
548
|
0
|
|
|
|
|
|
$self->warn; |
549
|
0
|
|
|
|
|
|
return undef; |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
#makes sure it it exists... if it does not it errors |
553
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) { |
554
|
0
|
|
|
|
|
|
$self->{error}=6; |
555
|
0
|
|
|
|
|
|
$self->{errorString}='The data source, "'.$dsName.'", does not exist'; |
556
|
0
|
|
|
|
|
|
$self->warn; |
557
|
0
|
|
|
|
|
|
return undef; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
|
560
|
0
|
|
|
|
|
|
return $vars{ 'datasources/'.$dsName.'/ds' }; |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
=head2 getDSattrs |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
This gets the pass for a data source. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
This can potentially be undef. |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
Only one arguement is required and is the name of the data source. |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
my %attrs=$foo->getDS("someDS"); |
572
|
|
|
|
|
|
|
if($foo->error){ |
573
|
|
|
|
|
|
|
print "Error!\n"; |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
=cut |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
sub getDSattrs{ |
579
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
580
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
#blanks any previous errors |
583
|
0
|
0
|
|
|
|
|
if (!$self->errorblank){ |
584
|
0
|
|
|
|
|
|
return undef; |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
#makes sure a DS name was specified |
588
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
589
|
0
|
|
|
|
|
|
$self->{error}=2; |
590
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
591
|
0
|
|
|
|
|
|
$self->warn; |
592
|
0
|
|
|
|
|
|
return undef; |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
#fetches them |
596
|
0
|
|
|
|
|
|
my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' ); |
597
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
598
|
0
|
|
|
|
|
|
$self->{error}=1; |
599
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarGet failed. error="'. |
600
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
601
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
602
|
0
|
|
|
|
|
|
$self->warn; |
603
|
0
|
|
|
|
|
|
return undef; |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
#makes sure it it exists... if it does not it errors |
607
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) { |
608
|
0
|
|
|
|
|
|
$self->{error}=6; |
609
|
0
|
|
|
|
|
|
$self->{errorString}='The data source, "'.$dsName.'", does not exist'; |
610
|
0
|
|
|
|
|
|
$self->warn; |
611
|
0
|
|
|
|
|
|
return undef; |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
#process each returned key |
615
|
0
|
|
|
|
|
|
my @keys=keys(%vars); |
616
|
0
|
|
|
|
|
|
my $int=0; |
617
|
0
|
|
|
|
|
|
my %toreturn; |
618
|
0
|
|
|
|
|
|
my $base='^datasources/'.$dsName.'/attr/'; |
619
|
0
|
|
|
|
|
|
while (defined( $keys[$int] )) { |
620
|
0
|
0
|
|
|
|
|
if ($keys[$int] =~ /$base/) { |
621
|
0
|
|
|
|
|
|
my $newkey=$keys[$int]; |
622
|
0
|
|
|
|
|
|
$newkey=~s/$base//; |
623
|
0
|
|
|
|
|
|
$toreturn{$newkey}=$vars{$keys[$int]}; |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
|
626
|
0
|
|
|
|
|
|
$int++; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
0
|
|
|
|
|
|
return %toreturn; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=head2 getDSpass |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
This gets the pass for a data source. |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
This can potentially be undef. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
Only one arguement is required and is the name of the data source. |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
my $ds=$foo->getDS("someDS"); |
641
|
|
|
|
|
|
|
if($foo->error){ |
642
|
|
|
|
|
|
|
print "Error!\n"; |
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=cut |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
sub getDSpass{ |
648
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
649
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
#blanks any previous errors |
652
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
653
|
0
|
|
|
|
|
|
return undef; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
#makes sure a DS name was specified |
657
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
658
|
0
|
|
|
|
|
|
$self->{error}=2; |
659
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
660
|
0
|
|
|
|
|
|
$self->warn; |
661
|
0
|
|
|
|
|
|
return undef; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
#fetches them |
665
|
0
|
|
|
|
|
|
my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' ); |
666
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
667
|
0
|
|
|
|
|
|
$self->{error}=1; |
668
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarGet failed. error="'. |
669
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
670
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
671
|
0
|
|
|
|
|
|
$self->warn; |
672
|
0
|
|
|
|
|
|
return undef; |
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
#makes sure it it exists... if it does not it errors |
676
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) { |
677
|
0
|
|
|
|
|
|
$self->{error}=6; |
678
|
0
|
|
|
|
|
|
$self->{errorString}='The data source, "'.$dsName.'", does not exist'; |
679
|
0
|
|
|
|
|
|
$self->warn; |
680
|
0
|
|
|
|
|
|
return undef; |
681
|
|
|
|
|
|
|
} |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
#return undef if it does not exist |
684
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/pass' } )) { |
685
|
0
|
|
|
|
|
|
return undef; |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
|
688
|
0
|
|
|
|
|
|
return $vars{ 'datasources/'.$dsName.'/pass' }; |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
=head2 getDSuser |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
This gets the user for a data source. |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
This can potentially be undef. |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
Only one arguement is required and is the name of the data source. |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
my $ds=$foo->getDS("someDS"); |
700
|
|
|
|
|
|
|
if($foo->error){ |
701
|
|
|
|
|
|
|
print "Error!\n"; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=cut |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
sub getDSuser{ |
707
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
708
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
#blanks any previous error |
711
|
0
|
0
|
|
|
|
|
if ($self->errorblank) { |
712
|
0
|
|
|
|
|
|
return undef; |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
#makes sure a DS name was specified |
716
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
717
|
0
|
|
|
|
|
|
$self->{error}=2; |
718
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
719
|
0
|
|
|
|
|
|
$self->warn; |
720
|
0
|
|
|
|
|
|
return undef; |
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
#fetches them |
724
|
0
|
|
|
|
|
|
my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' ); |
725
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
726
|
0
|
|
|
|
|
|
$self->{error}=1; |
727
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarGet failed. error="'. |
728
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
729
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
730
|
0
|
|
|
|
|
|
$self->warn; |
731
|
0
|
|
|
|
|
|
return undef; |
732
|
|
|
|
|
|
|
} |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
#makes sure it it exists... if it does not it errors |
735
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) { |
736
|
0
|
|
|
|
|
|
$self->{error}=6; |
737
|
0
|
|
|
|
|
|
$self->{errorString}='The data source, "'.$dsName.'", does not exist'; |
738
|
0
|
|
|
|
|
|
$self->warn; |
739
|
0
|
|
|
|
|
|
return undef; |
740
|
|
|
|
|
|
|
} |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
#return undef if it does not exist |
743
|
0
|
0
|
|
|
|
|
if (!defined( $vars{ 'datasources/'.$dsName.'/user' } )) { |
744
|
0
|
|
|
|
|
|
return undef; |
745
|
|
|
|
|
|
|
} |
746
|
|
|
|
|
|
|
|
747
|
0
|
|
|
|
|
|
return $vars{ 'datasources/'.$dsName.'/user' }; |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=head2 init |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
This initiates a new set. If a set already exists, it will be overwritten. |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
If the set specified is undefined, the default will be used. |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
The set is not automatically read. |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
$foo->init($set); |
759
|
|
|
|
|
|
|
if($foo->error){ |
760
|
|
|
|
|
|
|
print "Error!\n"; |
761
|
|
|
|
|
|
|
} |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
=cut |
764
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
sub init{ |
766
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
767
|
0
|
|
|
|
|
|
my $set=$_[1]; |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
#blanks any previous errors |
770
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
771
|
0
|
|
|
|
|
|
return undef; |
772
|
|
|
|
|
|
|
} |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
#the that what will be used for creating the new ZConf config |
775
|
0
|
|
|
|
|
|
my %hash; |
776
|
|
|
|
|
|
|
|
777
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromHash({config=>$self->{zconfconfig}, set=>$set},\%hash); |
778
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
779
|
0
|
|
|
|
|
|
$self->{error}=1; |
780
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
781
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
782
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
783
|
0
|
|
|
|
|
|
$self->warn; |
784
|
0
|
|
|
|
|
|
return $self; |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
|
787
|
0
|
|
|
|
|
|
return 1; |
788
|
|
|
|
|
|
|
} |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
=head2 listDSs |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
This lists the available data sources. |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
No arguements are taken. |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
The returned value is a array of available data sources. |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
my @datasources=$foo->listDSs; |
799
|
|
|
|
|
|
|
if($foo->error){ |
800
|
|
|
|
|
|
|
print "Error!\n"; |
801
|
|
|
|
|
|
|
}else{ |
802
|
|
|
|
|
|
|
use Data::Dumper; |
803
|
|
|
|
|
|
|
print Dumper(\@daasources); |
804
|
|
|
|
|
|
|
} |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
=cut |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
sub listDSs{ |
809
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
#blanks any previous errors |
812
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
813
|
0
|
|
|
|
|
|
return undef; |
814
|
|
|
|
|
|
|
} |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
#searches for datasources |
817
|
0
|
|
|
|
|
|
my @matched=$self->{zconf}->regexVarSearch($self->{zconfconfig}, '^datasources\/'); |
818
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
819
|
0
|
|
|
|
|
|
$self->{error}=1; |
820
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf regexVarSearch failed. error="'. |
821
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
822
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
823
|
0
|
|
|
|
|
|
$self->warn; |
824
|
0
|
|
|
|
|
|
return $self; |
825
|
|
|
|
|
|
|
} |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
#process the found data sources |
828
|
0
|
|
|
|
|
|
my %found; #provides easy holding for ones found to prevent duplicates |
829
|
0
|
|
|
|
|
|
my $int=0; #used for running through each one |
830
|
0
|
|
|
|
|
|
while (defined( $matched[$int] )) { |
831
|
0
|
|
|
|
|
|
my @split=split( /\//, $matched[$int] ); |
832
|
0
|
0
|
|
|
|
|
if (defined( $split[1] )) { |
833
|
0
|
|
|
|
|
|
$found{$split[1]}=1; |
834
|
|
|
|
|
|
|
} |
835
|
|
|
|
|
|
|
|
836
|
0
|
|
|
|
|
|
$int++; |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
#returns the found data sources, the keys in %found |
840
|
0
|
|
|
|
|
|
return keys(%found); |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
=head2 listSets |
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
This lists the available sets for the ZConf config. |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
my @sets=$foo->listSets; |
848
|
|
|
|
|
|
|
if($foo->error){ |
849
|
|
|
|
|
|
|
print "Error!\n"; |
850
|
|
|
|
|
|
|
} |
851
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
=cut |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
sub listSets{ |
855
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
#blanks any previous errors |
858
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
859
|
0
|
|
|
|
|
|
return undef; |
860
|
|
|
|
|
|
|
} |
861
|
|
|
|
|
|
|
|
862
|
0
|
|
|
|
|
|
my @sets=$self->{zconf}->getAvailableSets($self->{zconfconfig}); |
863
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
864
|
0
|
|
|
|
|
|
$self->{error}=1; |
865
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf getAvailableSets failed. error="'. |
866
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
867
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
868
|
0
|
|
|
|
|
|
$self->warn; |
869
|
0
|
|
|
|
|
|
return $self; |
870
|
|
|
|
|
|
|
} |
871
|
|
|
|
|
|
|
|
872
|
0
|
|
|
|
|
|
return @sets; |
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
=head2 readSet |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
This reads a specified ZConf set. |
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
If no set is specified, the default is used. |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
$foo->readSet('someSet'); |
882
|
|
|
|
|
|
|
if($foo->error){ |
883
|
|
|
|
|
|
|
print "Error!\n"; |
884
|
|
|
|
|
|
|
} |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
=cut |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
sub readSet{ |
889
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
890
|
0
|
|
|
|
|
|
my $set=$_[1]; |
891
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
#blanks any previous errors |
893
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
894
|
0
|
|
|
|
|
|
return undef; |
895
|
|
|
|
|
|
|
} |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
#read the config |
898
|
0
|
|
|
|
|
|
$self->{zconf}->read({config=>$self->{zconfconfig}, set=>$set}); |
899
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
900
|
0
|
|
|
|
|
|
$self->{error}=1; |
901
|
0
|
|
|
|
|
|
$self->{errorString}='Failed to read the set. error="'. |
902
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
903
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
904
|
0
|
|
|
|
|
|
$self->warn; |
905
|
0
|
|
|
|
|
|
return $self; |
906
|
|
|
|
|
|
|
} |
907
|
|
|
|
|
|
|
|
908
|
0
|
|
|
|
|
|
return 1; |
909
|
|
|
|
|
|
|
} |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
=head2 setDS |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
This changes the data source value for a already setup data source. |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
Two arguements are required. The first is the data source name and the |
916
|
|
|
|
|
|
|
second is the data source. |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
$foo->setDS('someDS', 'DBI:mysql:databasename'); |
919
|
|
|
|
|
|
|
if($foo->error){ |
920
|
|
|
|
|
|
|
print "Error!\n"; |
921
|
|
|
|
|
|
|
} |
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
=cut |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
sub setDS{ |
926
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
927
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
928
|
0
|
|
|
|
|
|
my $ds=$_[2]; |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
#blanks any previous errors |
931
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
932
|
0
|
|
|
|
|
|
return undef; |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
#makes sure a DS name was specified |
936
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
937
|
0
|
|
|
|
|
|
$self->{error}=2; |
938
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
939
|
0
|
|
|
|
|
|
$self->warn; |
940
|
0
|
|
|
|
|
|
return undef; |
941
|
|
|
|
|
|
|
} |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
#makes sure a DS name was specified |
944
|
0
|
0
|
|
|
|
|
if (!defined( $ds )) { |
945
|
0
|
|
|
|
|
|
$self->{error}=3; |
946
|
0
|
|
|
|
|
|
$self->{errorString}='No data source specified'; |
947
|
0
|
|
|
|
|
|
$self->warn; |
948
|
0
|
|
|
|
|
|
return undef; |
949
|
|
|
|
|
|
|
} |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
#make sure it does not exist already |
952
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
953
|
0
|
0
|
|
|
|
|
if ($self->error) { |
954
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
955
|
0
|
|
|
|
|
|
return undef; |
956
|
|
|
|
|
|
|
} |
957
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
958
|
0
|
|
|
|
|
|
$self->{error}=7; |
959
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
960
|
0
|
|
|
|
|
|
$self->warn; |
961
|
0
|
|
|
|
|
|
return undef; |
962
|
|
|
|
|
|
|
} |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
#set the variable |
965
|
0
|
|
|
|
|
|
my $var='datasources/'.$dsName.'/ds'; |
966
|
0
|
|
|
|
|
|
$self->{zconf}->setVar($self->{zconfconfig}, $var, $ds); |
967
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
968
|
0
|
|
|
|
|
|
$self->{error}=1; |
969
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
970
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
971
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
972
|
0
|
|
|
|
|
|
$self->warn; |
973
|
0
|
|
|
|
|
|
return undef; |
974
|
|
|
|
|
|
|
} |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
#saves it |
977
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
978
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
979
|
0
|
|
|
|
|
|
$self->{error}=1; |
980
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
981
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
982
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
983
|
0
|
|
|
|
|
|
$self->warn; |
984
|
0
|
|
|
|
|
|
return $self; |
985
|
|
|
|
|
|
|
} |
986
|
|
|
|
|
|
|
|
987
|
0
|
|
|
|
|
|
return 1; |
988
|
|
|
|
|
|
|
} |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
=head2 setDSattr |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
This changes the data source value for a already setup data source. |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
Three arguements are required. The first is the data source name, second |
995
|
|
|
|
|
|
|
is the data source, and the third is the value. |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
If the value is undefined, the attribute is removed. |
998
|
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
$foo->setDS('someDS', 'someAttr', 'someValue'); |
1000
|
|
|
|
|
|
|
if($foo->error){ |
1001
|
|
|
|
|
|
|
print "Error!\n"; |
1002
|
|
|
|
|
|
|
} |
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
=cut |
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
sub setDSattr{ |
1007
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
1008
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
1009
|
0
|
|
|
|
|
|
my $attr=$_[2]; |
1010
|
0
|
|
|
|
|
|
my $value=$_[3]; |
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
#blanks any previous errors |
1013
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
1014
|
0
|
|
|
|
|
|
return undef; |
1015
|
|
|
|
|
|
|
} |
1016
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
#makes sure a DS name was specified |
1018
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
1019
|
0
|
|
|
|
|
|
$self->{error}=2; |
1020
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
1021
|
0
|
|
|
|
|
|
$self->warn; |
1022
|
0
|
|
|
|
|
|
return undef; |
1023
|
|
|
|
|
|
|
} |
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
#makes sure a DS name was specified |
1026
|
0
|
0
|
|
|
|
|
if (!defined( $attr )) { |
1027
|
0
|
|
|
|
|
|
$self->{error}=8; |
1028
|
0
|
|
|
|
|
|
$self->{errorString}='No attribute specified'; |
1029
|
0
|
|
|
|
|
|
$self->warn; |
1030
|
0
|
|
|
|
|
|
return undef; |
1031
|
|
|
|
|
|
|
} |
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
#make sure it does not exist already |
1034
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
1035
|
0
|
0
|
|
|
|
|
if ($self->error) { |
1036
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
1037
|
0
|
|
|
|
|
|
return undef; |
1038
|
|
|
|
|
|
|
} |
1039
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
1040
|
0
|
|
|
|
|
|
$self->{error}=7; |
1041
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
1042
|
0
|
|
|
|
|
|
$self->warn; |
1043
|
0
|
|
|
|
|
|
return undef; |
1044
|
|
|
|
|
|
|
} |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
#removes it if the value is not defined... |
1047
|
0
|
0
|
|
|
|
|
if (!defined( $value )) { |
1048
|
0
|
|
|
|
|
|
my $rm='^datasources/'.$dsName.'/attr/'.$attr.'$'; |
1049
|
0
|
|
|
|
|
|
$self->{zconf}->regexVarDel($self->{zconfconfig}, $rm); |
1050
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1051
|
0
|
|
|
|
|
|
$self->{error}=1; |
1052
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
1053
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1054
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1055
|
0
|
|
|
|
|
|
$self->warn; |
1056
|
0
|
|
|
|
|
|
return undef; |
1057
|
|
|
|
|
|
|
} |
1058
|
|
|
|
|
|
|
|
1059
|
0
|
|
|
|
|
|
return 1; |
1060
|
|
|
|
|
|
|
} |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
#set the variable |
1063
|
0
|
|
|
|
|
|
my $var='datasources/'.$dsName.'/attr/'.$attr; |
1064
|
0
|
|
|
|
|
|
$self->{zconf}->setVar($self->{zconfconfig}, $var, $value); |
1065
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1066
|
0
|
|
|
|
|
|
$self->{error}=1; |
1067
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
1068
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1069
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1070
|
0
|
|
|
|
|
|
$self->warn; |
1071
|
0
|
|
|
|
|
|
return undef; |
1072
|
|
|
|
|
|
|
} |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
#saves it |
1075
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
1076
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1077
|
0
|
|
|
|
|
|
$self->{error}=1; |
1078
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
1079
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1080
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1081
|
0
|
|
|
|
|
|
$self->warn; |
1082
|
0
|
|
|
|
|
|
return $self; |
1083
|
|
|
|
|
|
|
} |
1084
|
|
|
|
|
|
|
|
1085
|
0
|
|
|
|
|
|
return 1; |
1086
|
|
|
|
|
|
|
} |
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
=head2 setDSpass |
1089
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
This changes the password value for a already setup data source. |
1091
|
|
|
|
|
|
|
|
1092
|
|
|
|
|
|
|
Two arguements are required. The first is the data source name and the |
1093
|
|
|
|
|
|
|
second is the password. |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
$foo->setDS('someDS', 'somePass'); |
1096
|
|
|
|
|
|
|
if($foo->error){ |
1097
|
|
|
|
|
|
|
print "Error!\n"; |
1098
|
|
|
|
|
|
|
} |
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
=cut |
1101
|
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
|
sub setDSpass{ |
1103
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
1104
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
1105
|
0
|
|
|
|
|
|
my $pass=$_[2]; |
1106
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
#blanks any previous errors |
1108
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
1109
|
0
|
|
|
|
|
|
return undef; |
1110
|
|
|
|
|
|
|
} |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
#makes sure a DS name was specified |
1113
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
1114
|
0
|
|
|
|
|
|
$self->{error}=2; |
1115
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
1116
|
0
|
|
|
|
|
|
$self->warn; |
1117
|
0
|
|
|
|
|
|
return undef; |
1118
|
|
|
|
|
|
|
} |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
#makes sure a user name is specified |
1121
|
0
|
0
|
|
|
|
|
if (!defined( $pass )) { |
1122
|
0
|
|
|
|
|
|
$self->{error}=11; |
1123
|
0
|
|
|
|
|
|
$self->{errorString}='No pass specified'; |
1124
|
0
|
|
|
|
|
|
$self->warn; |
1125
|
0
|
|
|
|
|
|
return undef; |
1126
|
|
|
|
|
|
|
} |
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
#make sure it does not exist already |
1129
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
1130
|
0
|
0
|
|
|
|
|
if ($self->error) { |
1131
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
1132
|
0
|
|
|
|
|
|
return undef; |
1133
|
|
|
|
|
|
|
} |
1134
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
1135
|
0
|
|
|
|
|
|
$self->{error}=7; |
1136
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
1137
|
0
|
|
|
|
|
|
$self->warn; |
1138
|
0
|
|
|
|
|
|
return undef; |
1139
|
|
|
|
|
|
|
} |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
#set the variable |
1142
|
0
|
|
|
|
|
|
my $var='datasources/'.$dsName.'/pass'; |
1143
|
0
|
|
|
|
|
|
$self->{zconf}->setVar($self->{zconfconfig}, $var, $pass); |
1144
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1145
|
0
|
|
|
|
|
|
$self->{error}=1; |
1146
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
1147
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1148
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1149
|
0
|
|
|
|
|
|
$self->warn; |
1150
|
0
|
|
|
|
|
|
return undef; |
1151
|
|
|
|
|
|
|
} |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
#saves it |
1154
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
1155
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1156
|
0
|
|
|
|
|
|
$self->{error}=1; |
1157
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
1158
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1159
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1160
|
0
|
|
|
|
|
|
$self->warn; |
1161
|
0
|
|
|
|
|
|
return $self; |
1162
|
|
|
|
|
|
|
} |
1163
|
|
|
|
|
|
|
|
1164
|
0
|
|
|
|
|
|
return 1; |
1165
|
|
|
|
|
|
|
} |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
=head2 setDSuser |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
This changes the user value for a already setup data source. |
1170
|
|
|
|
|
|
|
|
1171
|
|
|
|
|
|
|
Two arguements are required. The first is the data source name and the |
1172
|
|
|
|
|
|
|
second is the user. |
1173
|
|
|
|
|
|
|
|
1174
|
|
|
|
|
|
|
$foo->setDS('someDS', 'someUser'); |
1175
|
|
|
|
|
|
|
if($foo->error){ |
1176
|
|
|
|
|
|
|
print "Error!\n"; |
1177
|
|
|
|
|
|
|
} |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
=cut |
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
sub setDSuser{ |
1182
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
1183
|
0
|
|
|
|
|
|
my $dsName=$_[1]; |
1184
|
0
|
|
|
|
|
|
my $user=$_[2]; |
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
#blanks any previous errors |
1187
|
0
|
0
|
|
|
|
|
if (!$self->errorblank) { |
1188
|
0
|
|
|
|
|
|
return undef; |
1189
|
|
|
|
|
|
|
} |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
#makes sure a DS name was specified |
1192
|
0
|
0
|
|
|
|
|
if (!defined( $dsName )) { |
1193
|
0
|
|
|
|
|
|
$self->{error}=2; |
1194
|
0
|
|
|
|
|
|
$self->{errorString}='No DS name specified'; |
1195
|
0
|
|
|
|
|
|
$self->warn; |
1196
|
0
|
|
|
|
|
|
return undef; |
1197
|
|
|
|
|
|
|
} |
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
#make sure it does not exist already |
1200
|
0
|
|
|
|
|
|
my $dsExists=$self->dataSourceExists( $dsName ); |
1201
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
1202
|
0
|
|
|
|
|
|
$self->warnString('dataSourceExists errored'); |
1203
|
0
|
|
|
|
|
|
return undef; |
1204
|
|
|
|
|
|
|
} |
1205
|
0
|
0
|
|
|
|
|
if (!$dsExists) { |
1206
|
0
|
|
|
|
|
|
$self->{error}=7; |
1207
|
0
|
|
|
|
|
|
$self->{errorString}='The data source "'.$dsName.'" does not exist'; |
1208
|
0
|
|
|
|
|
|
$self->warn; |
1209
|
0
|
|
|
|
|
|
return undef; |
1210
|
|
|
|
|
|
|
} |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
#set the variable |
1213
|
0
|
|
|
|
|
|
my $var='datasources/'.$dsName.'/user'; |
1214
|
0
|
|
|
|
|
|
$self->{zconf}->setVar($self->{zconfconfig}, $var, $user); |
1215
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1216
|
0
|
|
|
|
|
|
$self->{error}=1; |
1217
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf setVar failed. error="'. |
1218
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1219
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1220
|
0
|
|
|
|
|
|
$self->warn; |
1221
|
0
|
|
|
|
|
|
return undef; |
1222
|
|
|
|
|
|
|
} |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
#saves it |
1225
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}}); |
1226
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->error) { |
1227
|
0
|
|
|
|
|
|
$self->{error}=1; |
1228
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf writeSetFromHash failed. error="'. |
1229
|
|
|
|
|
|
|
$self->{zconf}->error.'", errorString="'. |
1230
|
|
|
|
|
|
|
$self->{zconf}->errorString.'"'; |
1231
|
0
|
|
|
|
|
|
$self->warn; |
1232
|
0
|
|
|
|
|
|
return $self; |
1233
|
|
|
|
|
|
|
} |
1234
|
|
|
|
|
|
|
|
1235
|
0
|
|
|
|
|
|
return 1; |
1236
|
|
|
|
|
|
|
} |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
=head1 ERROR CODES/HANDLING |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
Error handling is provided by L. The error |
1241
|
|
|
|
|
|
|
codes are as below. |
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
=head2 1 |
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
ZConf errored. |
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
=head2 2 |
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
Data source name not specified. |
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
=head2 3 |
1252
|
|
|
|
|
|
|
|
1253
|
|
|
|
|
|
|
Data source not defined. |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
=head2 4 |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
The data source already exists. |
1258
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
=head2 5 |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
The data source name contains a '/'. |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
=head2 6 |
1264
|
|
|
|
|
|
|
|
1265
|
|
|
|
|
|
|
The data source does not exist. |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
=head2 7 |
1268
|
|
|
|
|
|
|
|
1269
|
|
|
|
|
|
|
Data source does not exist. |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
=head2 8 |
1272
|
|
|
|
|
|
|
|
1273
|
|
|
|
|
|
|
No attribute specified. |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
=head2 9 |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
No value specified. |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
=head2 10 |
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
No user specified. |
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
=head2 11 |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
No password specified. |
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
=head1 ZCONF KEYS |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
=head2 datasources//ds |
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
This is the data source string for a data source. |
1292
|
|
|
|
|
|
|
|
1293
|
|
|
|
|
|
|
This is required. |
1294
|
|
|
|
|
|
|
|
1295
|
|
|
|
|
|
|
=head2 datasources//user |
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
This is the user for a data source. |
1298
|
|
|
|
|
|
|
|
1299
|
|
|
|
|
|
|
This may not be defined. |
1300
|
|
|
|
|
|
|
|
1301
|
|
|
|
|
|
|
=head2 datasources//pass |
1302
|
|
|
|
|
|
|
|
1303
|
|
|
|
|
|
|
This is the password for a data source. |
1304
|
|
|
|
|
|
|
|
1305
|
|
|
|
|
|
|
This may not be defined. |
1306
|
|
|
|
|
|
|
|
1307
|
|
|
|
|
|
|
=head2 datasources//attr/ |
1308
|
|
|
|
|
|
|
|
1309
|
|
|
|
|
|
|
This contains any attributes for a data source. |
1310
|
|
|
|
|
|
|
|
1311
|
|
|
|
|
|
|
=head1 AUTHOR |
1312
|
|
|
|
|
|
|
|
1313
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
1314
|
|
|
|
|
|
|
|
1315
|
|
|
|
|
|
|
=head1 BUGS |
1316
|
|
|
|
|
|
|
|
1317
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
1318
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
1319
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
1320
|
|
|
|
|
|
|
|
1321
|
|
|
|
|
|
|
=head1 SUPPORT |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
perldoc ZConf::DBI |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
You can also look for information at: |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
=over 4 |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
L |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
L |
1339
|
|
|
|
|
|
|
|
1340
|
|
|
|
|
|
|
=item * CPAN Ratings |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
L |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
=item * Search CPAN |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
L |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
=back |
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
|
1351
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
1355
|
|
|
|
|
|
|
|
1356
|
|
|
|
|
|
|
Copyright 2012 Zane C. Bowers-Hadley, all rights reserved. |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
1359
|
|
|
|
|
|
|
under the same terms as Perl itself. |
1360
|
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
|
|
1362
|
|
|
|
|
|
|
=cut |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
1; # End of ZConf::DBI |