line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::SqlObject::Config;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
20
|
use strict;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
171
|
|
4
|
3
|
|
|
3
|
|
291
|
use warnings;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
5562
|
|
5
|
|
|
|
|
|
|
require Carp;
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %SqlConfig =
|
10
|
|
|
|
|
|
|
(
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------------------------------
|
13
|
|
|
|
|
|
|
# DBI Connect settings
|
14
|
|
|
|
|
|
|
#----------------------------------------
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# which DBD driver to use by default
|
17
|
|
|
|
|
|
|
DSN => 'dbi:Sybase',
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# prepended to database name in the DBI connect string
|
20
|
|
|
|
|
|
|
NAME_PREFIX => 'database=',
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# database to connect to, by default
|
23
|
|
|
|
|
|
|
NAME => 'cezb-html',
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# user to connect as, by default
|
26
|
|
|
|
|
|
|
USER => 'perl',
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# password for DB_USER
|
29
|
|
|
|
|
|
|
PASSWORD => '',
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# other parameters
|
32
|
|
|
|
|
|
|
OTHER_ARGS => '',
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
OTHER_ARG_SEP => ';',
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#----------------------------------------
|
37
|
|
|
|
|
|
|
# constructor arguments
|
38
|
|
|
|
|
|
|
# defined here, so they can be modifed
|
39
|
|
|
|
|
|
|
# by SQL::SqlObject sub-classes.
|
40
|
|
|
|
|
|
|
#----------------------------------------
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Lists each of the constructor arguments (in the
|
43
|
|
|
|
|
|
|
# order to be received, when provided positionaly)
|
44
|
|
|
|
|
|
|
# as hash refs.
|
45
|
|
|
|
|
|
|
#
|
46
|
|
|
|
|
|
|
# Key is the name of the arg, to be used to build
|
47
|
|
|
|
|
|
|
# it's accessor method
|
48
|
|
|
|
|
|
|
#
|
49
|
|
|
|
|
|
|
# Value is an array reference, fields are listed below
|
50
|
|
|
|
|
|
|
#
|
51
|
|
|
|
|
|
|
# 2) arg name, which must have an accessor method
|
52
|
|
|
|
|
|
|
# method of the same name
|
53
|
|
|
|
|
|
|
# 2) a vertical bar seperated list of aliases
|
54
|
|
|
|
|
|
|
# 3) list ref of env vars to search for a value
|
55
|
|
|
|
|
|
|
# 4) a SqlConfig key from which to read default
|
56
|
|
|
|
|
|
|
#
|
57
|
|
|
|
|
|
|
ARGS =>
|
58
|
|
|
|
|
|
|
[
|
59
|
|
|
|
|
|
|
['db_name','name|database','','NAME'],
|
60
|
|
|
|
|
|
|
['db_user','user','','USER'],
|
61
|
|
|
|
|
|
|
['db_password','password|pass|passwd', '','PASSWORD'],
|
62
|
|
|
|
|
|
|
['db_dsn','DSN|dsn','','DSN'],
|
63
|
|
|
|
|
|
|
['db_name_prefix','','','NAME_PREFIX'],
|
64
|
|
|
|
|
|
|
],
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
);
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub arg_index ($)
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#
|
71
|
|
|
|
|
|
|
# given: $KEY
|
72
|
|
|
|
|
|
|
#
|
73
|
|
|
|
|
|
|
# returns the index of $KEY in $SqlConfig->{ARGS}
|
74
|
|
|
|
|
|
|
# or barfs is $KEY is unknown in $SqlConfig->{ARGS}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
{
|
77
|
16
|
|
|
16
|
0
|
33
|
my $key = lc $_[-1]; $key =~ s/^-+//;
|
|
16
|
|
|
|
|
20
|
|
78
|
16
|
|
|
|
|
26
|
my $args = $SqlConfig{ARGS};
|
79
|
16
|
|
|
|
|
113
|
for (0..$#$args)
|
80
|
|
|
|
|
|
|
{
|
81
|
46
|
100
|
|
|
|
1275
|
return $_ if $key =~ /^(?:$SqlConfig{ARGS}[$_][0]|$SqlConfig{ARGS}[$_][1])$/;
|
82
|
|
|
|
|
|
|
}
|
83
|
0
|
|
|
|
|
0
|
Carp::confess "Unknown parameter to SqlObject: \"$_[-1]\"\n";
|
84
|
|
|
|
|
|
|
}
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_arg ($;$$$$)
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# given: $KEY, $aliases, $env_or_envlist, $default, $before_key
|
89
|
|
|
|
|
|
|
#
|
90
|
|
|
|
|
|
|
# registers KEY for a parameter to the SqlObject constructor, by
|
91
|
|
|
|
|
|
|
# adding to the ARGS list in %SqlConfig. $aliases, if provided is
|
92
|
|
|
|
|
|
|
# either a pipe-seperated list of other names for KEY or simply a
|
93
|
|
|
|
|
|
|
# list (array ref) of other names for key. $env_or_envlist is
|
94
|
|
|
|
|
|
|
# either a SCALAR constaining the name of an enviroment variable
|
95
|
|
|
|
|
|
|
# to search for KEYS value, when the constructor is run, or a list
|
96
|
|
|
|
|
|
|
# there of. $before_key
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
{
|
99
|
4
|
|
|
4
|
0
|
8
|
my ($key, $ali, $env, $def, $bef) = @_;
|
100
|
4
|
|
|
|
|
8
|
my @rec = $key;
|
101
|
4
|
50
|
|
|
|
9
|
$ali = join '|', @$ali if ref $ali;
|
102
|
4
|
50
|
33
|
|
|
21
|
push @rec, (defined $ali and $ali) ? $ali : '';
|
103
|
4
|
50
|
33
|
|
|
17
|
push @rec, (defined $env and $env) ? $env : '';
|
104
|
4
|
50
|
33
|
|
|
20
|
push @rec, (defined $def and $def) ? $def : '';
|
105
|
4
|
50
|
33
|
|
|
19
|
if (defined $bef and $bef)
|
106
|
|
|
|
|
|
|
{
|
107
|
4
|
|
|
|
|
6
|
$bef = arg_index $bef;
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
else
|
110
|
|
|
|
|
|
|
{
|
111
|
0
|
|
|
|
|
0
|
$bef = @{$SqlConfig{ARGS}};
|
|
0
|
|
|
|
|
0
|
|
112
|
|
|
|
|
|
|
}
|
113
|
4
|
|
|
|
|
12
|
splice @{$SqlConfig{ARGS}}, $bef, 0, \@rec;
|
|
4
|
|
|
|
|
14
|
|
114
|
4
|
|
|
|
|
12
|
return;
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub add_alias ($@)
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# given: $KEY, @ALISES
|
120
|
|
|
|
|
|
|
#
|
121
|
|
|
|
|
|
|
# add @ALISES to $KEY in $SqlConfig{ARGS}
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
{
|
124
|
3
|
|
|
3
|
0
|
7
|
my $key = shift;
|
125
|
3
|
50
|
|
|
|
9
|
return unless @_;
|
126
|
3
|
|
|
|
|
8
|
my $ali = $SqlConfig{ARGS}[ arg_index $key ][1];
|
127
|
3
|
50
|
|
|
|
33
|
$ali .= '|' if $ali;
|
128
|
3
|
|
|
|
|
10
|
$ali .= join '|',@_;
|
129
|
3
|
|
|
|
|
11
|
$ali =~ s/|$//;
|
130
|
3
|
|
|
|
|
9
|
$SqlConfig{ARGS}[ arg_index $key ][1] = $ali;
|
131
|
3
|
|
|
|
|
11
|
return;
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub add_enviroment_variable
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# given: $KEY, @ENVS
|
137
|
|
|
|
|
|
|
#
|
138
|
|
|
|
|
|
|
# add @ENVS to $KEY in $SqlConfig{ARGS}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
{
|
141
|
3
|
|
|
3
|
0
|
5
|
my $key = shift;
|
142
|
3
|
50
|
|
|
|
10
|
return unless @_;
|
143
|
3
|
|
|
|
|
7
|
my $env = $SqlConfig{ARGS}[ arg_index $key ][2];
|
144
|
3
|
50
|
33
|
|
|
21
|
$env = ($env && !ref $env) ? [$env] : (ref $env ? $env : []);
|
|
|
50
|
|
|
|
|
|
145
|
3
|
50
|
33
|
|
|
19
|
$env = [ $env ] if $env and not ref $env;
|
146
|
3
|
|
|
|
|
9
|
unshift @$env, @_;
|
147
|
3
|
|
|
|
|
7
|
$SqlConfig{ARGS}[ arg_index $key ][2] = $env;
|
148
|
3
|
|
|
|
|
9
|
return;
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub set_default ($$)
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# given: $KEY, $DEFAULT
|
154
|
|
|
|
|
|
|
#
|
155
|
|
|
|
|
|
|
# set the default for $KEY in $SqlConfig{ARGS}
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
{
|
158
|
0
|
|
|
0
|
0
|
0
|
my ($key, $def) = @_;
|
159
|
0
|
0
|
|
|
|
0
|
return unless defined $def;
|
160
|
0
|
|
|
|
|
0
|
$SqlConfig{ARGS}[ arg_index $key ][2] = $def;
|
161
|
0
|
|
|
|
|
0
|
return;
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub set ($@)
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# given: $KEY, $value
|
167
|
|
|
|
|
|
|
#
|
168
|
|
|
|
|
|
|
# add $KEY to %SqlConfig
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
{
|
171
|
8
|
|
|
8
|
0
|
77
|
my $key = shift;
|
172
|
8
|
50
|
66
|
|
|
198
|
return unless (@_ and defined $_[0]) or not exists $SqlConfig{$key};
|
|
|
|
66
|
|
|
|
|
173
|
8
|
100
|
|
|
|
40
|
$SqlConfig{$key} = (not defined $_[0]) ? '' : ($#_ ? \@_ : $_[0]);
|
|
|
100
|
|
|
|
|
|
174
|
8
|
|
|
|
|
20
|
return;
|
175
|
|
|
|
|
|
|
}
|
176
|
|
|
|
|
|
|
1;
|
177
|
|
|
|
|
|
|
|