Rose::DBx::Cache::Anywhere - get Apache::DBI behaviour without Apache


Rose-DBx-AutoReconnect documentation Contained in the Rose-DBx-AutoReconnect distribution.

Index


Code Index:

NAME

Top

Rose::DBx::Cache::Anywhere - get Apache::DBI behaviour without Apache

DESCRIPTION

Top

This class is used by Rose::DBx::AutoReconnect. The author uses Rose::DB with Catalyst under both the Catalyst dev server and FastCGI and found that the standard Rose::DB::Cache behaviour did not work well with those environments.

METHODS

Top

prepare_db( rose_db, entry )

Overrides default method to always ping() dbh if not running under mod_perl.

AUTHOR

Top

Peter Karman, <karman at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-rose-dbx-autoreconnect at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-DBx-AutoReconnect. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Rose::DBx::AutoReconnect

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Rose-DBx-AutoReconnect

* CPAN Ratings

http://cpanratings.perl.org/d/Rose-DBx-AutoReconnect

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-DBx-AutoReconnect

* Search CPAN

http://search.cpan.org/dist/Rose-DBx-AutoReconnect

ACKNOWLEDGEMENTS

Top

The Minnesota Supercomputing Institute http://www.msi.umn.edu/ sponsored the development of this software.

COPYRIGHT

Top


Rose-DBx-AutoReconnect documentation Contained in the Rose-DBx-AutoReconnect distribution.
package Rose::DBx::Cache::Anywhere;
use strict;
use warnings;
use Carp;
use base qw( Rose::DB::Cache );

sub prepare_db {
    my ( $self, $db, $entry ) = @_;

    $db->debug && $db->logger("prepare_db for entry $entry");

    if ( Rose::DB::Cache::MOD_PERL_1 || Rose::DB::Cache::MOD_PERL_2 ) {
        return $self->SUPER::prepare_db( $db, $entry );
    }

    if ( !$entry->is_prepared ) {
        if ( $entry->created_during_apache_startup ) {
            if ( $db->has_dbh ) {
                $db->debug
                    && $db->logger( "$$ Disconnecting and undef-ing dbh "
                        . $db->dbh
                        . " created during apache startup from $db" );
                eval { $db->dbh->disconnect };    # will probably fail!
                $@
                    && $db->logger(
                    "$$ Could not disconnect dbh created during apache startup: "
                        . $db->dbh
                        . " - $@" );
                $db->dbh(undef);
            }

            $entry->created_during_apache_startup(0);
            return;
        }

        $entry->prepared(1);
    }

    if ( !$db->dbh->ping ) {
        $db->logger("ping failed");
        $db->dbh(undef);
    }
}

1;

__END__