We abstract the database handle out into a a simple subroutine:
sub connect { if ( CACHE_TABLES ) { return $MEMORY_DBH; } else { return Pair::Nic::DBI->connect(); } } |
Now, as long as our code uses __PACKAGE__->connect() whenever it wants a database handle, it doesn't need to know wether it is using the cache or not:
sub get_inventory_info { my $class = shift; my $dbh = __PACKAGE__->connect(); my $query = "SELECT * from " . INVENTORY_CLASS_TABLE . " WHERE inventory_class like ?"; return query_execute( $query, $dbh, $class ); } |