Gantry::Utils::DBConnHelper - connection info and dbh cache manager base module
package Gantry::Utils::DBConnHelper::YourHelper; use base 'Gantry::Utils::DBConnHelper'; Gantry::Utils::DBConnHelper->set_subclass( 'Gantry::Utils::DBConnHelper::YourHelper' ); sub get_dbh {...} sub set_dbh {...} sub get_conn_info {...} sub set_conn_info {...} # only for some helpers sub get_auth_dbh {...} sub set_auth_dbh {...} sub get_auth_conn_info {...} sub set_auth_conn_info {...} # only for some helpers
This is mostly a documentation module. You should probably use one of the available implementing modules like Gantry::Utils::DBConnHelper::Script, Gantry::Utils::DBConnHelper::MP13, etc. If none of those fit your needs you need to subclass this modules and define all of the methods listed below (see the synopsis for an example). If you choose to subclass, you will inherit the import method from this module. It allows your callers to pass a hash reference of database connection info in their use statement, instead of calling set_conn_info. This only works for the Script helper.
Your subclass MUST call this method at compile time passing in the fully qualified name of your subclass.
Returns the name of the subclass providing the actual connection information. Used by any one that wants to ask the subclass for connection info. The prime example is Gantry::Utils::ModelHelper.
Your module needs to implement the methods below. Failure to implement them will likely result in a fatal error at run time (or difficult to track bugs).
Get methods don't receive any parameters other than the invocant.
(required by Gantry::Utils::CDBI and Gantry::Utils::Model)
Return a valid dbh if you have one or undef if not.
Receives a dbh which it should store in its cache.
Returns a hash reference of connection info with these keys:
a full dsn suitable for passing directly to DBI's connect method
the name of the database user
the password for dbuser
Other keys in the hash are ignored.
In addition to connecting to an application database, Gantry can provide authentication. In that case it uses a separate connection to the app's auth database. This enables it to share authentication databases across apps.
Note that there is nothing that prevents you from storing the auth info in the same database as the app data. We just use two connections to add the flexibility to split these. In any case, if you are using Gantry auth, you must use the methods below.
(Note the symmetry between these methods and the ones above. These simply have auth_ inserted into their names.)
(required by Gantry::Utils::AuthCDBI and Gantry::Utils::AuthModel)
Returns the database handle for the authentication database.
Receives a database handle for the authentication database which it should cache for later retrieval by get_auth_dbh.
It is perfectly reasonable to use the same database -- or even database handle -- for both the auth and regular connections. But, you need to provide the methods above so that Gantry can find them.
This module does supply a useful import method which you can inherit. It allows users to supply the connection information hash as a parameter in their use statement like this:
use Gantry::Utils::DBConnHelper::YourSubclass { dbconn = 'dbi:Pg:dbname=mydb;host=127.0.0.1', dbuser = 'someuser', dbpass = 'not_saying', };
The caller has the option of doing this in two steps (in case they need to calculate the connection information at run time):
use Gantry::Utils::DBConnHelper::YourSubclass; # ... figure out what information to provide Gantry::Utils::DBConnHelper::YourSubclass->set_conn_info( { dbconn = $dsn, dbuser = $user, dbpass = $pass, } );
The import method does not help with authentication connection info.
Gantry::Util::DBConnHelper::Script has two other methods for use by scripts, constructors, init methods or the like.
Not implemented by mod_perl helpers.
Receives a hash of connection information suitable for use as the return value of get_conn_info.
Receives a hash reference of connection info which it should store for later retrieval via get_conn_info.
Phil Crow <philcrow2000@yahoo.com>
Copyright (c) 2005-6, Phil Crow.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
To install Gantry, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gantry
CPAN shell
perl -MCPAN -e shell install Gantry
For more information on module installation, please visit the detailed CPAN module installation guide.