summaryrefslogtreecommitdiff
path: root/perl-lib/PgCommitFest/Request.pm
diff options
context:
space:
mode:
authorRobert Haas2009-05-24 02:00:19 +0000
committerRobert Haas2009-05-24 02:00:19 +0000
commitc393c68db3df467ee02dbc83aad4662e36cc7629 (patch)
tree4ec308daa9e4846e017d706960d16bfa2c73b351 /perl-lib/PgCommitFest/Request.pm
parenta1bb7bcda0069888fb580d0b7089bd9e3634de06 (diff)
Avoid opening the database connection sooner than necessary.
Diffstat (limited to 'perl-lib/PgCommitFest/Request.pm')
-rw-r--r--perl-lib/PgCommitFest/Request.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/perl-lib/PgCommitFest/Request.pm b/perl-lib/PgCommitFest/Request.pm
index 4ceaf7f..ae38399 100644
--- a/perl-lib/PgCommitFest/Request.pm
+++ b/perl-lib/PgCommitFest/Request.pm
@@ -12,6 +12,9 @@ die "Must set PGCOMMITFEST_ROOT to root directory of installation!\n"
our $ROOT = $ENV{'PGCOMMITFEST_ROOT'};
our $template = Template->new({ 'INCLUDE_PATH' => $ROOT . '/template',
'FILTERS' => { 'htmlsafe' => \&PgCommitFest::WebControl::escape } });
+our $PG = 'dbi:Pg:dbname=pgcommitfest';
+our $PGUSERNAME = 'pgcommitfest';
+our $PGPASSWORD = '';
$CGI::POST_MAX = 65536;
$CGI::DISABLE_UPLOADS = 1; # No need for uploads at present.
@@ -23,7 +26,7 @@ sub new {
'cgi' => $cgi,
'control' => {},
'control_list' => [],
- 'db' => $db,
+ 'db' => undef,
'error_list' => [],
'header' => {
'Content-type' => 'text/html',
@@ -105,9 +108,18 @@ sub control {
sub db {
my ($self) = @_;
+ if (!defined $self->{'db'}) {
+ $self->{'db'} =
+ PgCommitFest::DB->connect($PG, $PGUSERNAME, $PGPASSWORD);
+ }
return $self->{'db'};
}
+sub db_is_connected {
+ my ($self) = @_;
+ defined $self->{'db'};
+}
+
sub error {
my ($self, $fmt, @arg) = @_;
push @{$self->{'error_list'}}, sprintf($fmt, @arg);