Apache2-WebApp-Plugin-DBI
view release on metacpan or search on metacpan
lib/Apache2/WebApp/Plugin/DBI.pm view on Meta::CPAN
#----------------------------------------------------------------------------+
#
# Apache2::WebApp::Plugin::DBI - Database interface wrapper
#
# DESCRIPTION
#
# A database independent interface that gives your application universal
# supports across many databases including MySQL, PostGRe, and Oracle.
# Also supports many common flat file formats.
#
# AUTHOR
# Marc S. Brooks <mbrooks@cpan.org>
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
#----------------------------------------------------------------------------+
package Apache2::WebApp::Plugin::DBI;
use strict;
use base 'Apache2::WebApp::Plugin';
use DBI;
use Params::Validate qw( :all );
our $VERSION = 0.10;
#~~~~~~~~~~~~~~~~~~~~~~~~~~[ OBJECT METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#----------------------------------------------------------------------------+
# connect(\%config)
#
# Make a new database connection.
sub connect {
my ( $self, $config )
= validate_pos( @_,
{ type => OBJECT },
{ type => HASHREF }
);
my $driver = $config->{driver};
my $host = $config->{host} || 'localhost';
my $name = $config->{name};
my $user = $config->{user};
my $password = $config->{password};
my $commit = $config->{commit};
return if (!$name && !$user && !$password);
return DBI->connect(
"dbi:$driver:$name:$host", $user, $password,
{
PrintError => 1,
RaiseError => 1,
AutoCommit => ($commit) ? 1 : 0,
}
)
or $self->error($DBI::errstr);
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~[ PRIVATE METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#----------------------------------------------------------------------------+
# _init(\%params)
#
# Return a reference of $self to the caller.
sub _init {
my ( $self, $params ) = @_;
return $self;
}
1;
__END__
=head1 NAME
Apache2::WebApp::Plugin::DBI - Database interface wrapper
=head1 SYNOPSIS
my $obj = $c->plugin('DBI')->method( ... ); # Apache2::WebApp::Plugin::DBI->method()
or
$c->plugin('DBI')->method( ... );
=head1 DESCRIPTION
A database independent interface that gives your application universal support
across many databases including MySQL, PostGRe, and Oracle. Also supports many
common flat file formats.
=head1 PREREQUISITES
( run in 1.705 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )