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.


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:

  • 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"

    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.

  • 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.




John Drago <>


This software is Free software and may be used and redistributed under the same terms as Perl itself.