AppConfig::DBI - support for DBI connection via AppConfig


NAME

AppConfig::DBI - support for DBI connection (info) via AppConfig


SYNOPSIS

 # .cshrc
 setenv APPCONFIG /Users/metaperl/.appconfig # dont forget the dot!!!
 setenv APPCONFIG_DBI "${APPCONFIG}-dbi"
 # .appconfig-dbi
 [basic]
 user   = postgres
 dsn    = dbi:Pg:dbname=mydb
 attr RaiseError =  0
 attr PrintError =  0
 attr Taint      =  1
 # DBIx::AnyDBD usage:
 my @connect_data = AppConfig::DBI->connect_data_for('dev_db');
 my $dbh          = DBIx::AnyDBD->connect(@connect_data, "MyClass");
 # pure DBI usage
 use AppConfig::DBI;
 my $config = shift or die "must give label for config";
 my $dbh    = AppConfig::DBI->connect($config);
 # over-ride .appconfig-dbi from the command line:
 perl dbi-script.pl basic -basic_user tim_bunce -basic_pass dbi_rocks
 perl dbi-script.pl basic -basic_attr "RaiseError=1" -basic_attr "Taint=0"


DESCRIPTION

This module facilitates DBI-style or DBIx::AnyDBD-style database connections for sites and applications which make use of AppConfig to configure their applications via files and/or command-line arguments.

It provides two methods, connect and connect_data_for which return a DBI database handle or an array of DBI connection info, respectively.

Each of the 4 DBI connection parameters (username, password, dsn, attr) can be defined via any of the methods supported by AppConfig, meaning via a configuration file, or simple-style command-line arguments. AppConfig provides support for both simple and Getopt::Long style, but Getopt::Long is overkill for a module this simple.


RELATED MODULES / MOTIVATION FOR THIS ONE

The only module similar to this on CPAN is DBIx::Password. Here are some points of comparison/contrast.

My CPAN module set will be AppConfig-dependant

From now on, any module of mine which requires configuration info will use AppConfig to get it. I thought about using XML but a discussion on Perlmonks.Org and one on p5ee@perl.org both made strong arguments in favor of AppConfig.

EXPORT

None by default.


AUTHOR

T. M. Brannon <tbone@cpan.org>


SEE ALSO

DBIx::Password AppConfig AppConfig::Std