line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Utils::DBConnHelper::Script; |
2
|
2
|
|
|
2
|
|
8
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use base 'Gantry::Utils::DBConnHelper'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1082
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Gantry::Utils::DBConnHelper->set_subclass( |
7
|
|
|
|
|
|
|
'Gantry::Utils::DBConnHelper::Script' |
8
|
|
|
|
|
|
|
); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $dbh; |
11
|
|
|
|
|
|
|
my $conn_info; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $auth_dbh; |
14
|
|
|
|
|
|
|
my $auth_conn_info; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_dbh { |
17
|
0
|
|
|
0
|
1
|
0
|
return $dbh; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub set_dbh { |
21
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
22
|
0
|
|
|
|
|
0
|
$dbh = shift; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_conn_info { |
26
|
0
|
|
|
0
|
1
|
0
|
return $conn_info; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub set_conn_info { |
30
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
31
|
1
|
|
|
|
|
3
|
$conn_info = shift; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
35
|
|
|
|
|
|
|
# The methods below are for cgi scripts which use auth databases. |
36
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_auth_dbh { |
39
|
0
|
|
|
0
|
1
|
0
|
return $auth_dbh; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_auth_dbh { |
43
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
44
|
0
|
|
|
|
|
0
|
$auth_dbh = shift; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_auth_conn_info { |
48
|
0
|
0
|
|
0
|
1
|
0
|
return ( $auth_conn_info ) ? $auth_conn_info : $conn_info; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub set_auth_conn_info { |
52
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
53
|
1
|
|
|
|
|
2
|
$auth_conn_info = shift; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Gantry::Utils::DBConnHelper::Script - connection info and dbh cache manager for scripts |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Gantry::Utils::DBConnHelper::Script { |
65
|
|
|
|
|
|
|
dbconn => 'dbi:Pg:dbname=mydb;host=127.0.0.1', |
66
|
|
|
|
|
|
|
dbuser => 'someuser', |
67
|
|
|
|
|
|
|
dbpass => 'not_saying', |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
OR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use Gantry::Utils::DBConnHelper::Script; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# ... do something, usually involving figuring out your conn info |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Gantry::Utils::DBConnHelper::Script->set_conn_info( $conn_info_hash_ref ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
In either case, if you need httpd authentication (say in CGI): |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Gantry::Utils::DBConnHelper::Script->set_auth_conn_info( |
81
|
|
|
|
|
|
|
$auth_conn_hash_ref |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
When you use a model which inherits from Gantry::Utils::CDBI or |
87
|
|
|
|
|
|
|
Gantry::Utils::Model etc., using this module can help with database |
88
|
|
|
|
|
|
|
connection management. Feel free to implement your own subclass |
89
|
|
|
|
|
|
|
of Gantry::Utils::DBConnHelper if you need more control. That |
90
|
|
|
|
|
|
|
base class specifies which methods you must implement. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 Normal Connection METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
See Gantry::Utils::DBConnHelper for a description of the methods available |
95
|
|
|
|
|
|
|
here. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Note that only cgi scripts need to worry about the auth methods. |
98
|
|
|
|
|
|
|
Off line scripts don't need to authenticate through apache. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Here is a list of the methods documented in Gantry::Utils::DBConnHelper. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item get_auth_conn_info |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item get_auth_dbh |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item get_conn_info |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item get_dbh |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item set_auth_conn_info |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item set_auth_dbh |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item set_conn_info |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item set_dbh |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Phil Crow |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Copyright (c) 2005-6, Tim Keefer. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
131
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
132
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |