Dave Rolsky > Fey-DBIManager > Fey::DBIManager::Source

Download:
Fey-DBIManager-0.10.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs

Source  

NAME ^

Fey::DBIManager::Source - Wraps a single DBI handle

SYNOPSIS ^

  my $source = Fey::DBIManager::Source->new( dbh => $dbh );

  my $dbh = $source->dbh();

DESCRIPTION ^

A Fey::DBIManager::Source object provides a wrapper around a DBI handle which does things like ensure that handles are recreated properly after a fork.

A source can be created from an existing DBI handle, or from parameters such as the dsn and authentication info.

METHODS ^

This class provides the following methods:

Fey::DBIManager::Source->new(...)

Creates a new Fey::DBIManager::Source object. This method accepts a number of parameters.

$source->dbh()

Returns a database handle for the source. If you did not pass a handle to the constructor, this may create a new handle. If auto_refresh is true, this may cause a new handle to be created. See "HANDLE FRESHNESS" for more details.

$source->dsn()

$source->username()

$source->password()

$source->post_connect()

$source->auto_connect()

These methods simply return the value of the specified attribute.

$source->attributes()

This method reutrns attributes hash reference for the source. This will be a combination of any attributes passed to the constructor plus the "REQUIRED ATTRIBUTES".

$source->allows_nested_transactions()

Returns a boolean indicating whether or not the database to which the source connects supports nested transactions. It does this by trying to issue two calls to $dbh->begin_work() followed by two calls to $dbh->rollback() (in an eval block).

REQUIRED ATTRIBUTES ^

In order to provide consistency for Fey::ORM, sources enforce a set of standard attributes on DBI handles:

HANDLE FRESHNESS ^

If auto_refresh is true for a source, then every call to $source->dbh() incurs the cost of a "freshness" check. The upside of this is that it will just work in the face of forks, threading, and lost connections.

First, we check to see if the pid has changed since the handle was created. If it has, we set InactiveDestroy to true in the handle and disconnect it. If the thread has changed, we just disconnect the handle.

Finally, we check $dbh->{Active] and call $dbh->ping(). If either of these is false, we disconnect the handle.

If the handle is not fresh, a new one is created.

AUTHOR ^

Dave Rolsky, <autarch@urth.org>

BUGS ^

Please report any bugs or feature requests to bug-fey-dbimanager@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE ^

Copyright 2006-2008 Dave Rolsky, All Rights Reserved.

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