SqlObject/Config.pm

filter: Statementstmt 86.7% 46 / 53 Branchbran 56.2% 18 / 32 Conditioncond 41.6% 10 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 6 totaltotal 58.7% 81 / 138 CC 26 SCAR 22.5
CC
26
Cov
68%
add_arg
17.9
add_enviroment_variable
9.4
set
6.2
CRAP 9.5
« SqlObject/ODBC.pm ↑ Summary SqlObject/Pg.pm »
1 package SQL::SqlObject::Config;
2
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 require Carp;
6
7 3 our $VERSION = '0.01';
8
9 3 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 16 ▶{
Subroutine arg_index: called CC=3 SCAR=11.0
Pod undocumented
77 16 my $key = lc $_[-1]; $key =~ s/^-+//;
78 16 my $args = $SqlConfig{ARGS};
79 16 for (0..$#$args)
80 {
81 46 ▶ return $_ if $key =~ /^(?:$SqlConfig{ARGS}[$_][0]|$SqlConfig{ARGS}[$_][1])$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^(?:$SQL::SqlObject::Config::SqlConfig{"ARGS"}[$_][0]|$SQL::SqlObject::Config::SqlConfig{"ARGS"}[$_][1])$/ 16 30 46
82 }
83 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 4 ▶{
Subroutine add_arg: called CC=10 SCAR=28.8
Pod undocumented
99 4 my ($key, $ali, $env, $def, $bef) = @_;
100 4 my @rec = $key;
101 4 ▶ $ali = join '|', @$ali if ref $ali;
Branch: 1 branch
BranchTrueFalseTotal
if ref $ali 0 4 4
102 4 ▶ push @rec, (defined $ali and $ali) ? $ali : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $ali && $ali ? : 4 0 4
Condition33%1/3
defined $ali and $ali
!ll&&!rl&&r
004
MC/DC0%0/2
defined $ali and $ali
defined $ali $ali
Truth table33%1/3
A and B
A= defined $aliB= $ali
ABresult
0X0
100
111
103 4 ▶ push @rec, (defined $env and $env) ? $env : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $env && $env ? : 4 0 4
Condition33%1/3
defined $env and $env
!ll&&!rl&&r
004
MC/DC0%0/2
defined $env and $env
defined $env $env
Truth table33%1/3
A and B
A= defined $envB= $env
ABresult
0X0
100
111
104 4 ▶ push @rec, (defined $def and $def) ? $def : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $def && $def ? : 4 0 4
Condition33%1/3
defined $def and $def
!ll&&!rl&&r
004
MC/DC0%0/2
defined $def and $def
defined $def $def
Truth table33%1/3
A and B
A= defined $defB= $def
ABresult
0X0
100
111
105 4 ▶ if (defined $bef and $bef)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bef and $bef) { } 4 0 4
Condition33%1/3
defined $bef and $bef
!ll&&!rl&&r
004
MC/DC0%0/2
defined $bef and $bef
defined $bef $bef
Truth table33%1/3
A and B
A= defined $befB= $bef
ABresult
0X0
100
111
106 {
107 4 $bef = arg_index $bef;
108 }
109 else
110 {
111 0 $bef = @{$SqlConfig{ARGS}};
112 }
113 4 splice @{$SqlConfig{ARGS}}, $bef, 0, \@rec;
114 4 return;
115 }
116
117 sub add_alias ($@)
118
119 # given: $KEY, @ALISES
120 #
121 # add @ALISES to $KEY in $SqlConfig{ARGS}
122
123 3 ▶{
Subroutine add_alias: called CC=3 SCAR=11.1
Pod undocumented
124 3 my $key = shift;
125 3 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
126 3 my $ali = $SqlConfig{ARGS}[ arg_index $key ][1];
127 3 ▶ $ali .= '|' if $ali;
Branch: 1 branch
BranchTrueFalseTotal
if $ali 3 0 3
128 3 $ali .= join '|',@_;
129 3 $ali =~ s/|$//;
130 3 $SqlConfig{ARGS}[ arg_index $key ][1] = $ali;
131 3 return;
132 }
133
134 sub add_enviroment_variable
135
136 # given: $KEY, @ENVS
137 #
138 # add @ENVS to $KEY in $SqlConfig{ARGS}
139
140 3 ▶{
Subroutine add_enviroment_variable: called CC=7 SCAR=22.4
Pod undocumented
141 3 my $key = shift;
142 3 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
143 3 my $env = $SqlConfig{ARGS}[ arg_index $key ][2];
144 3 ▶ $env = ($env && !ref $env) ? [$env] : (ref $env ? $env : []);
Branch: 2 branches
BranchTrueFalseTotal
$env && !ref($env) ? : 0 3 3
ref $env ? : 0 3 3
Condition33%1/3
$env and not ref $env
!ll&&!rl&&r
300
MC/DC0%0/2
$env and not ref $env
$env not ref $env
Truth table33%1/3
A and not(B)
A= $envB= not ref $env
ABresult
0X0
100
111
145 3 ▶ $env = [ $env ] if $env and not ref $env;
Branch: 1 branch
BranchTrueFalseTotal
if $env and not ref $env 0 3 3
Condition33%1/3
$env and not ref $env
!ll&&!rl&&r
030
MC/DC0%0/2
$env and not ref $env
$env not ref $env
Truth table33%1/3
A and not(B)
A= $envB= not ref $env
ABresult
0X0
100
111
146 3 unshift @$env, @_;
147 3 $SqlConfig{ARGS}[ arg_index $key ][2] = $env;
148 3 return;
149 }
150
151 sub set_default ($$)
152
153 # given: $KEY, $DEFAULT
154 #
155 # set the default for $KEY in $SqlConfig{ARGS}
156
157 0 ▶{
Subroutine set_default: not called CC=2 SCAR=17.9
Pod undocumented
158 0 my ($key, $def) = @_;
159 0 ▶ return unless defined $def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def 0 0 0
160 0 $SqlConfig{ARGS}[ arg_index $key ][2] = $def;
161 0 return;
162 }
163
164 sub set ($@)
165
166 # given: $KEY, $value
167 #
168 # add $KEY to %SqlConfig
169
170 8 ▶{
Subroutine set: called CC=6 SCAR=18.3
Pod undocumented
171 8 my $key = shift;
172 8 ▶ return unless (@_ and defined $_[0]) or not exists $SqlConfig{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] or not exists $SQL::SqlObject::Config::SqlConfig{$key} 0 8 8
Condition66%4/6
@_ and defined $_[0] or not exists $SQL::SqlObject::Config::SqlConfig{$key}
l!l&&r!l&&!r
440
@_ and defined $_[0]
!ll&&!rl&&r
404
MC/DC0%0/3
@_ and defined $_[0] or not exists $SQL::SqlObject::Config::SqlConfig{$key}
@_ defined $_[0] not exists $SQL::SqlObject::Config::SqlConfig{$key}
Truth table40%2/5
A and B or not(C)
A= @_B= defined $_[0]C= not exists $SQL::SqlObject::Config::SqlConfig{$key}
ABCresult
11X1
0X11
1011
0X00
1000
173 8 ▶ $SqlConfig{$key} = (not defined $_[0]) ? '' : ($#_ ? \@_ : $_[0]);
Branch: 2 branches
BranchTrueFalseTotal
!defined($_[0]) ? : 4 4 8
$#_ ? : 1 3 4
174 8 return;
175 }
176 3 1;
177
« SqlObject/ODBC.pm ↑ Summary SqlObject/Pg.pm »