NAME

Object::POOF::DB - Wrapper object around DBI.

VERSION

This document describes Object::POOF::DB version 0.0.6

SYNOPSIS

package TestApp::DB;
use Object::POOF::Constants;
use base qw( Object::POOF::DB );
use Class::Std;
{ 
   sub BUILD {
       my ($self, $ident, $arg_href) = @_;

       # set defaults if not set in constructor
       $self->get_dbname  or $self->set_dbval(name  => 'test');
       $self->get_dbhost  or $self->set_dbval(host  => 'localhost');
       $self->get_dbuname or $self->set_dbval(uname => $EMPTY_STR);
       $self->get_dbpass  or $self->set_dbval(pass  => $EMPTY_STR);
       return;
   }
}

package main;
use English '-no-match-vars';
use Carp;

my $db = TestApp::DB->new();
# or...
# my $db 
#     = TestApp::DB->new({ uname => 'mydbuser', pass => 'mydbpass' });

my $dbh = undef;
eval { $dbh = $db->dbh() };

croak $EVAL_ERROR if ($EVAL_ERROR);  

# it will stringify properly, or...
# if (my $e = Exception::Class->caught('Object::POOF::X') ) {
#     $e->rethrow();
# }

# now use DBI methods on $dbh...
eval { $db->commit() };
# $EVAL_ERROR would be an Object::POOF::X::DB::Do exception

# Mainly you use this to pass a transaction thread 
# to Object::POOF objects:
my $thing = TestApp::Thing->new({ db => $db });
$thing->set_save({
   field1 => 'val1',
   field2 => 'val2',
});

eval { $thing->save() };  # Object::POOF::X::Update exception?
if (my $e = Exception::Class->caught('Object::POOF::X')) {
   $thing->rollback();
   carp $e;
}
else {
   eval { $thing->commit() };  # Object::POOF::X::DB::Do exception?
   # ....
}

DESCRIPTION

This is the Object::POOF suite wrapper around DBI. Its main use is to create a connection object to a MySQL InnoDB database that wraps the transaction thread in an object and provides some nice exception classes.

INTERFACE

Object::POOF::DB is used as a base parent class for your DB object in your application's namespace, which you create with a very simple construct as detailed above. Then your DB object gets a bunch of methods.

$db = TestApp::DB->new() - the only class method

Pass a hash reference of values if you want to override any of the attributes listed in BUILD() above. This is useful if you are running test scripts on another database. However, maybe there ought to be a config file with this info... hmm. I will figure this out better as time goes on.

$rv = $db->do($sql_query);

Should work just like DBI::dbh::do(), except that it returns Exception::Class exceptions with class names of 'Object::POOF::X::DB::Do', or 'Object::POOF::X::DB'.

$sth = $db->prepare($query, \%attrs); # or prepare_cached

Intended to work just about the same way as the DBI versions, but prepare_cached will always use

$db->finish({ sth_name => 'name' });

Finishes a named cached sth. Of course, if you still have a reference to it, you could call finish directly. This is used by DEMOLISH upon destruction to finish all sth's if being destroyed uncleanly.

$db->commit; $db->rollback;

Wrappers around dbh->commit and dbh->rollback that throw Object::POOF::X::DB exceptions.

AUTOMETHOD: my $table_info = $db->table_name();

Returns a hash of information about a particular table, or false if the table does not exist under this database. This hash has two keys. $table_info->{fields} is an array ref containing the names of the fields in the order that a 'describe table_name' would return them. $table_info->{info} is a hash indexed by field name containing information about the fields from the 'describe' and parsing of that information. Mostly this is used internally, but it might be useful to you. This information is cached in a package variable, so even if your interpreter is running multiple transaction handles, it will cache the describe table results across all of them.

DIAGNOSTICS

to do...

Error message here, perhaps with %s placeholders

[Description of error here]

Another error message here

[Description of error here]

[Et cetera, et cetera]

CONFIGURATION AND ENVIRONMENT

Object::POOF::DB requires no configuration files or environment variables at this point, but maybe I will move the database connect info into a global Object::POOF config file at some point.

DEPENDENCIES

Object::POOF and all its dependencies, Class::Std, DBI.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-object-poof-db@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Mark Hedges <hedges@ucsd.edu>

LICENCE AND COPYRIGHT

Copyright (c) 2005, Mark Hedges <hedges@ucsd.edu>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.