[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] DBH plugin configuration


Hi all,

I am just looking at the DBH plugin and how it is used:

use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);

 sub cgiapp_init  {
    my $self = shift;

    # use the same args as DBI->connect();
    $self->dbh_config($data_source, $username, $auth, \%attr);
}

Since you need to get $data_source from somewhere, this might actually be more like:


use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);

 sub cgiapp_init  {
    my $self = shift;
    # get the params
    my $data_source = $self->param('data_source');
    my $username = $self->param('data_source_user');
    my $auth = $self->param('data_source_pass');

   # use the same args as DBI->connect();
$self->dbh_config($data_source, $username, $auth. { SomeAttr => 1});
}

I think it should be possible to completely get rid of all this code by having some naming conventions
for the CGI::App instance  parameters.
The plugin could then bootstrap itself from the parameters of the instance.

my $app = new MyCGIApp;
$app->param (
	'::Plugin::DBH' =>
		{ data_source => [ 'dbi:...', 'blah', 'blah' ] }
);

dbh_config could use these parameters to connect to the DB.
It would only do this unless explicitly configured, which makes this a backwards-compatible feature.

The "::Plugin::DBH" data_source parameter could also take a hash of arrays to accomodate named handles.


Not everyone is setting parameters in the instance script. Some people are using configuration files in various formats that get more or less automagically (code-free) included. This kind of plugin autoconfiguration would also integrate nicely with those.

Am I making sense to anyone?

Thilo



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.