Apache-SecSess
view release on metacpan or search on metacpan
SecSess/DBI.pm view on Meta::CPAN
#
# DBI.pm - basic DB interface for Apache::SecSess::* objects
#
# renamed from Id: SecSessDBI.pm,v 1.8 2002/05/06 06:33:17 pliam Exp
# $Id: DBI.pm,v 1.1 2002/05/19 05:15:29 pliam Exp $
#
package Apache::SecSess::DBI;
use strict;
use IO::File;
use DBI;
use vars qw($VERSION);
$VERSION = sprintf("%d.%02d", (q$Name: SecSess_Release_0_09 $ =~ /\d+/g));
#
# object and DB initialization
#
## new
sub new {
my $class = shift;
my $self = bless({@_}, $class);
$self->_init;
return $self;
}
## init object only means acquiring DBI login info
sub _init {
my $self = shift;
my ($usage, $file, $fh, $dbistr, $dbiuser, $dbipw);
## define usage
$usage = sprintf("usage: %s->new([%s] || [%s]);\n", ref($self),
"dbifile => 'filename'",
"dbistr => 'DBI string', dbiuser => 'DBI user', "
. "dbipw => 'DBI password'"
);
## must provide some way to connect
if ($self->{dbistr} && defined($self->{dbiuser}) &&
defined($self->{dbipw})) {
return;
}
unless ($file = $self->{dbifile}) { die $usage; }
## read login info from file
unless ($fh = IO::File->new($file)) {
die "Cannot open DBI login file '$file'\n";
}
chomp($self->{dbistr} = <$fh>);
chomp($self->{dbiuser} = <$fh>);
chomp($self->{dbipw} = <$fh>);
unless ($self->{dbistr} && $self->{dbiuser} && $self->{dbipw}) {
die "DBI login file has missing data.";
}
}
## initiate or restart the database connection
sub refresh_dbh {
my $self = shift;
( run in 1.579 second using v1.01-cache-2.11-cpan-99c4e6809bf )