| 1 | package Rose::DBx::AutoReconnect; | ||||||||||||||||||||||||||||
| 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 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Rose::DBx::Cache::Anywhere; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | __PACKAGE__->db_cache_class('Rose::DBx::Cache::Anywhere'); | |||||||||||||||||||||||||||
| 11 | 2 | __PACKAGE__->use_private_registry(1); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | DBI->trace(1) if $ENV{PERL_DEBUG} && $ENV{PERL_DEBUG} > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"PERL_DEBUG"} and $ENV{"PERL_DEBUG"} > 1
MC/DC0%0/2
$ENV{"PERL_DEBUG"} and $ENV{"PERL_DEBUG"} > 1
$ENV{"PERL_DEBUG"}
$ENV{"PERL_DEBUG"} > 1
Truth table33%1/3
A and B
A= $ENV{"PERL_DEBUG"}B= $ENV{"PERL_DEBUG"} > 1
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Rose::Object::MakeMethods::Generic ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | 'scalar --get_set_init' => [qw( debug logfh )], ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Rose::DBx::AutoReconnect - Rose::DB with auto-reconnect to server | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Rose::DBx::AutoReconnect; | ||||||||||||||||||||||||||||
| 26 | my $db = Rose::DBx::AutoReconnect->new; | ||||||||||||||||||||||||||||
| 27 | $db->logger('hello world'); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Rose::DBx::AutoReconnect is a subclass of Rose::DB. Additional features | ||||||||||||||||||||||||||||
| 32 | include: | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =over | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =item | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | If using new_or_cached() method, will ping() dbh on every fetch from | ||||||||||||||||||||||||||||
| 39 | cache to ensure that the dbh is connected. This extends | ||||||||||||||||||||||||||||
| 40 | the basic Rose::DB::Cache behaviour beyond mod_perl/Apache::DBI. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Convenient logger() method for debugging. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Always uses DBI connect_cached() method when creating handles. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Rose::DBx::AutoReconnect was written to allow new_or_cached() to | ||||||||||||||||||||||||||||
| 53 | work with MySQL's "morning bug" and to allow for restarting | ||||||||||||||||||||||||||||
| 54 | your database without restarting your application. | ||||||||||||||||||||||||||||
| 55 | See also Rose::DBx::Cache::Anywhere. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 METHODS | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 init_logfh | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Defaults to STDERR. Get/set it with logfh(). | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub init_logfh { *STDERR{IO} } | ||||||||||||||||||||||||||
|
Subroutine
init_logfh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 init_debug | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Defaults to value of PERL_DEBUG env var (if set) or 0 (false). | ||||||||||||||||||||||||||||
| 72 | Get/set it with debug(). | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub init_debug { $ENV{PERL_DEBUG} || 0 } | ||||||||||||||||||||||||||
|
Subroutine
init_debug: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head2 logger( I<msg> ) | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Writes I<msg> to the filehandle set with logfh(). | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub logger { | ||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 0 | my @msg = @_; | |||||||||||||||||||||||||||
| 87 | 0 | for my $m (@msg) { | |||||||||||||||||||||||||||
| 88 | 0 | print { $self->logfh } join( ' ', $self->loglabel, $m, "\n" ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 loglabel | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Returns a pretty timestamp and label. Used by logger(). | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub loglabel { | ||||||||||||||||||||||||||
|
Subroutine
loglabel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 0 | my $time = localtime(); | |||||||||||||||||||||||||||
| 101 | 0 | return '[' . $time . '] ' . '[' . $self->nick . '] '; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head2 nick | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Returns pretty label unique to this DB object. Used by loglabel(). | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub nick { | ||||||||||||||||||||||||||
|
Subroutine
nick: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | return join( '.', | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->host || 'localhost'
MC/DC0%0/1
$self->host || 'localhost'
$self->host
Truth table0%0/2
A
A= $self->host
| |||||||||||||||||||||||||||||
| 113 | $self->domain, $self->type, $self->database . '@' . ($self->host||'localhost') ); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head2 dbi_connect | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Override base method to use DBI connect_cached() method. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub dbi_connect { | ||||||||||||||||||||||||||
|
Subroutine
dbi_connect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->logger(" ---------> dbi->connect") if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | return DBI->connect_cached(@_); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||