Ima::DBI::Contextual - Liteweight context-aware dbi handle cache and utility methods.
This module has been deprecated. Do not use.
package Foo; use base 'Ima::DBI::Contextual'; my @dsn = ( 'DBI:mysql:dbname:hostname', 'username', 'password', { RaiseError => 0, }); __PACKAGE__->set_db('Main', @dsn);
Then, elsewhere:
my $dbh = Foo->db_Main; # Use $dbh like you normally would: my $sth = $dbh->prepare( ... );
If you like Ima::DBI but need it to be more context-aware (eg: tie dbi connections to more than the name and process id) then you need Ima::DBI::Contextual.
Ima::DBI::Contextual
Indications: For permanent relief of symptoms related to hosting multiple mod_perl web applications on one server, where each application uses a different database but they all refer to the database handle via Class->db_Main. Such symptoms may include:
Class->db_Main
Wonky behavior which causes one website to fail because it's connected to the wrong database.
Scenario - Everything is going fine, you're clicking around walking your client through a demo of the web application and then BLAMMO - 500 server error! Another click and it's OK. WTF? You look at the log for Foo application and it says something like "Unknown method 'frobnicate' in package Bar::bozo"
Unknown method 'frobnicate' in package Bar::bozo
Funny thing is - you never connected to that database. You have no idea WHY it is trying to connect to that database. Pouring over the guts in Ima::DBI it's clear that Ima::DBI only caches database handles by Process ID ($$) and name (eg: db_Main). So if the same Apache child process has more than one application running within it and each application has db_Main then it's just a matter of time before your application blows up.
$$
db_Main
Wondering for years what happened.
Years, no less.
Not impressing your boss.
Yeah - it can happen - when you have them take a look at your new shumwidget and instead of working - it doesn't work. All your preaching about unit tests and DRY go right out the window when the basics (eg - connecting to the CORRECT FRIGGIN' DATABASE) are broken.
Ima::DBI
John Drago <jdrago_999@yahoo.com>
This software is Free software and may be used and redistributed under the same terms as Perl itself.
To install Ima::DBI::Contextual, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ima::DBI::Contextual
CPAN shell
perl -MCPAN -e shell install Ima::DBI::Contextual
For more information on module installation, please visit the detailed CPAN module installation guide.