| 1 | package Rose::DBx::Cache::Anywhere; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use base qw( Rose::DB::Cache ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Rose::DBx::Cache::Anywhere - get Apache::DBI behaviour without Apache | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This class is used by Rose::DBx::AutoReconnect. | ||||||||||
| 14 | The author uses | ||||||||||
| 15 | Rose::DB with Catalyst under both the Catalyst dev server and | ||||||||||
| 16 | FastCGI and found that the standard Rose::DB::Cache behaviour | ||||||||||
| 17 | did not work well with those environments. | ||||||||||
| 18 | |||||||||||
| 19 | =head1 METHODS | ||||||||||
| 20 | |||||||||||
| 21 | =head2 prepare_db( I<rose_db>, I<entry> ) | ||||||||||
| 22 | |||||||||||
| 23 | Overrides default method to always ping() dbh if not running | ||||||||||
| 24 | under mod_perl. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub prepare_db { | ||||||||
|
Subroutine
prepare_db: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 29 | 0 | my ( $self, $db, $entry ) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | $db->debug && $db->logger("prepare_db for entry $entry"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | if ( Rose::DB::Cache::MOD_PERL_1 || Rose::DB::Cache::MOD_PERL_2 ) { | |||||||||
| 34 | return $self->SUPER::prepare_db( $db, $entry ); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | if ( !$entry->is_prepared ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | ▶ | if ( $entry->created_during_apache_startup ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | ▶ | if ( $db->has_dbh ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | ▶ | $db->debug | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | && $db->logger( "$$ Disconnecting and undef-ing dbh " | ||||||||||
| 42 | . $db->dbh | ||||||||||
| 43 | . " created during apache startup from $db" ); | ||||||||||
| 44 | 0 | eval { $db->dbh->disconnect }; # will probably fail! | |||||||||
| 45 | 0 | ▶ | $@ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | && $db->logger( | ||||||||||
| 47 | "$$ Could not disconnect dbh created during apache startup: " | ||||||||||
| 48 | . $db->dbh | ||||||||||
| 49 | . " - $@" ); | ||||||||||
| 50 | 0 | $db->dbh(undef); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | $entry->created_during_apache_startup(0); | |||||||||
| 54 | 0 | return; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | $entry->prepared(1); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | if ( !$db->dbh->ping ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $db->logger("dbh->ping failed ... unsetting dbh for automatic retry"); | |||||||||
| 62 | 0 | $db->dbh(undef); | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 2 | 1; | |||||||||
| 67 | |||||||||||
| 68 | __END__ | ||||||||||