SPOPSx::Ginsu::DBI - Ginsu datasource base class.
Assuming the files MyDBI.pm, MyBaseObject.pm, MyObject.pm and my_dbi_conf.pm from steps 1-4 of SPOPSx::Ginsu POD SYNOPSIS ...
use my_dbi_conf.pm # defines package variables for DSN, etc. use MyObject; MyObject->dbi_connect; MyObject->dbi_disconnect; $dbh = MyObject->global_datasource_handle; MyObject->drop_table; MyObject->create_table; MyObject->recreate_table;
This class inherits from SPOPS::DBI::MySQL and SPOPS::DBI and serves as a base class for your own datasource class (e.g. t/MyDBI.pm) which is in turn a base class for all of your Ginsu object classes. The methods defined here and inherited by all Ginsu objects are for creating, destroying and returning the database connection, and dropping, creating and recreating (dropping and creating again) the table corresponding to the class. All methods are class methods, but can also be called as object methods.
The database connection parameters DBI_DSN, DBI_USER, DBI_PASS, and DBI_OPT are held in package variables with the respective names in your datasource class (e.g. t/MyDBI.pm). Closures of the same names are used to return their values and a closure,
set_dbi_connect_args() is used to set their values. Another datasource class package variable, DBH, holds the database handle when connected. This is also accessed and set through closures named
set_DBH(), respectively. Please see t/MyDBI.pm for an example of such
$rc = CLASS->dbi_connect $rc = CLASS->dbi_connect( $DBI_DSN, $DBI_USER, $DBI_PASS, $DBI_OPT )
Calls DBI->connect() and passes back the return value. Arguments to DBI->connect() are found by calling the DBI_DSN, DBI_USER, DBI_PASS and DBI_OPT methods. If values are passed in for these arguments, they are first passed to the
Calls disconnect() on the handle retured by the classes
DBH() method. Then sets clears the database handle by passing undef to the
$dbh = CLASS->global_datasource_handle $dbh = $object->global_datasource_handle
Returns a DBI database handle. If a cached handle is not available, it calls
dbi_connect and caches and returns the handle. Retries 10 times if necessary, before giving up.
Drops the class's base_table from the database.
Creates the class's table based on the SQL stored in the class's $TABLE_DEF. We typically use 'CREATE TABLE IF NOT EXISTS'.
drop_table() followed by a
$Log: DBI.pm,v $ Revision 1.18 2004/06/02 15:05:42 ray Now requires SPOPS-0.86
Revision 1.17 2004/04/23 18:05:30 ray Updated docs.
Revision 1.16 2004/04/23 16:50:54 ray Renamed from ESPOPS::DBI and updated docs.
Copyright (c) 2001-2004 PSERC. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Ray Zimmerman, <firstname.lastname@example.org>