| 1 | package Rose::DB::Cache; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use base 'Rose::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Rose::DB::Cache::Entry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 17 | our $VERSION = '0.755'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 17 | our $Debug = 0; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use Rose::Class::MakeMethods::Generic | ||||||||||||||||||||||||||||
| 15 | 17 | ▶ | ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 17 | inheritable_scalar => | |||||||||||||||||||||||||||
| 17 | [ | ||||||||||||||||||||||||||||
| 18 | 'entry_class', | ||||||||||||||||||||||||||||
| 19 | '_default_use_cache_during_apache_startup', | ||||||||||||||||||||||||||||
| 20 | ], | ||||||||||||||||||||||||||||
| 21 | 17 | ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | __PACKAGE__->entry_class('Rose::DB::Cache::Entry'); | |||||||||||||||||||||||||||
| 24 | 17 | __PACKAGE__->default_use_cache_during_apache_startup(0); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 17 | our($MP2_Is_Child, $Apache_Has_Started); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub default_use_cache_during_apache_startup | ||||||||||||||||||||||||||||
| 29 | 17 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
default_use_cache_during_apache_startup: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 17 | my($class) = shift; | |||||||||||||||||||||||||||
| 31 | 17 | ▶ | return $class->_default_use_cache_during_apache_startup($_[0] ? 1 : 0) if(@_); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 0 | return $class->_default_use_cache_during_apache_startup; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub use_cache_during_apache_startup | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
use_cache_during_apache_startup: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 0 | my($self) = shift; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return $self->{'use_cache_during_apache_startup'} = $_[0] ? 1 : 0 if(@_); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if(defined $self->{'use_cache_during_apache_startup'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | return $self->{'use_cache_during_apache_startup'}; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else | ||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||
| 47 | 0 | return $self->{'use_cache_during_apache_startup'} = | |||||||||||||||||||||||||||
| 48 | ref($self)->default_use_cache_during_apache_startup; | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub prepare_for_apache_fork | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prepare_for_apache_fork: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my($self) = shift; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | foreach my $entry ($self->db_cache_entries) | |||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if($entry->created_during_apache_startup) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 0 | my $db = $entry->db; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | $Debug && warn "$$ Disconnecting and undef-ing ", $db->dbh, " contained in $db"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $db->dbh->disconnect; | |||||||||||||||||||||||||||
| 63 | 0 | $db->dbh(undef); | |||||||||||||||||||||||||||
| 64 | 0 | $db = undef; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | $Debug && warn "$$ Deleting cache entry for $db"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | delete $self->{'cache'}{$entry->key}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub build_cache_key | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
build_cache_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my($class, %args) = @_; | |||||||||||||||||||||||||||
| 74 | 0 | return join("\0", $args{'domain'}, $args{'type'}); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | QUIET: | ||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 17 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 17 | ▶ | use constant MOD_PERL_1 => ($ENV{'MOD_PERL'} && !$ENV{'MOD_PERL_API_VERSION'}) ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
Condition33%1/3
$ENV{"MOD_PERL"} and not $ENV{"MOD_PERL_API_VERSION"}
MC/DC0%0/2
$ENV{"MOD_PERL"} and not $ENV{"MOD_PERL_API_VERSION"}
$ENV{"MOD_PERL"}
not $ENV{"MOD_PERL_API_VERSION"}
Truth table33%1/3
A and not(B)
A= $ENV{"MOD_PERL"}B= not $ENV{"MOD_PERL_API_VERSION"}
| |||||||||||||||||||||||||||||
| 81 | 17 | ▶ | use constant MOD_PERL_2 => ($ENV{'MOD_PERL'} && $ENV{'MOD_PERL_API_VERSION'} == 2) ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
Condition33%1/3
$ENV{"MOD_PERL"} and $ENV{"MOD_PERL_API_VERSION"} == 2
MC/DC0%0/2
$ENV{"MOD_PERL"} and $ENV{"MOD_PERL_API_VERSION"} == 2
$ENV{"MOD_PERL"}
$ENV{"MOD_PERL_API_VERSION"} == 2
Truth table33%1/3
A and B
A= $ENV{"MOD_PERL"}B= $ENV{"MOD_PERL_API_VERSION"} == 2
| |||||||||||||||||||||||||||||
| 82 | 17 | ▶ | use constant APACHE_DBI => ($INC{'Apache/DBI.pm'} || $Apache::DBI::VERSION) ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
Condition33%1/3
$INC{"Apache/DBI.pm"} or $Apache::DBI::VERSION
MC/DC0%0/2
$INC{"Apache/DBI.pm"} or $Apache::DBI::VERSION
$INC{"Apache/DBI.pm"}
$Apache::DBI::VERSION
Truth table33%1/3
A or B
A= $INC{"Apache/DBI.pm"}B= $Apache::DBI::VERSION
| |||||||||||||||||||||||||||||
| 83 | 17 | ▶ | use constant APACHE_DBI_MP2 => (APACHE_DBI && MOD_PERL_2) ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | 17 | ▶ | use constant APACHE_DBI_MP1 => (APACHE_DBI && MOD_PERL_1) ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub db_cache_entries | ||||||||||||||||||||||||||||
| 88 | 17 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
db_cache_entries: not called CC=4 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my($self) = shift; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | return wantarray ? values %{$self->{'cache'} || {}} : | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'cache'} || {}
MC/DC0%0/1
$self->{'cache'} || {}
$self->{'cache'}
Truth table0%0/2
A
A= $self->{'cache'}
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | [ values %{$self->{'cache'} || {}} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'cache'} || {}
MC/DC0%0/1
$self->{'cache'} || {}
$self->{'cache'}
Truth table0%0/2
A
A= $self->{'cache'}
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub db_cache_keys | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
db_cache_keys: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my($self) = shift; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | return wantarray ? keys %{$self->{'cache'} || {}} : | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'cache'} || {}
MC/DC0%0/1
$self->{'cache'} || {}
$self->{'cache'}
Truth table0%0/2
A
A= $self->{'cache'}
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | [ keys %{$self->{'cache'} || {}} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'cache'} || {}
MC/DC0%0/1
$self->{'cache'} || {}
$self->{'cache'}
Truth table0%0/2
A
A= $self->{'cache'}
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub get_db | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_db: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my($self) = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $key = $self->build_cache_key(@_); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(my $entry = $self->{'cache'}{$key}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if(my $db = $entry->db) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | $self->prepare_db($db, $entry); | |||||||||||||||||||||||||||
| 112 | 0 | return $db; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | return undef; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub set_db | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | my($self, $db) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my $key = | |||||||||||||||||||||||||||
| 124 | $self->build_cache_key(domain => $db->domain, | ||||||||||||||||||||||||||||
| 125 | type => $db->type, | ||||||||||||||||||||||||||||
| 126 | db => $db); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $entry = ref($self)->entry_class->new(db => $db, key => $key); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Don't cache anything during apache startup if use_cache_during_apache_startup | ||||||||||||||||||||||||||||
| 131 | # is false. Weird conditional structure is meant to encourage code elimination | ||||||||||||||||||||||||||||
| 132 | # thanks to the lone constants in the if/elsif conditions. | ||||||||||||||||||||||||||||
| 133 | 0 | if(MOD_PERL_1) | |||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | if($Apache::Server::Starting) | ||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | if($self->use_cache_during_apache_startup) | ||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | $entry->created_during_apache_startup(1); | ||||||||||||||||||||||||||||
| 140 | $entry->prepared(0); | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | else | ||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||
| 144 | $Debug && warn "Refusing to cache $db during apache server start-up ", | ||||||||||||||||||||||||||||
| 145 | "because use_cache_during_apache_startup is false"; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | return $db; | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | if(MOD_PERL_2) | |||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||
| 154 | if(!$MP2_Is_Child) | ||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||
| 156 | if($self->use_cache_during_apache_startup) | ||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||
| 158 | $entry->created_during_apache_startup(1); | ||||||||||||||||||||||||||||
| 159 | $entry->prepared(0); | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | else | ||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | $Debug && warn "Refusing to cache $db in pre-fork apache process ", | ||||||||||||||||||||||||||||
| 164 | "because use_cache_during_apache_startup is false"; | ||||||||||||||||||||||||||||
| 165 | return $db; | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | $self->{'cache'}{$key} = $entry; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | return $db; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub clear { shift->{'cache'} = {} } | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 17 | if(MOD_PERL_2) | |||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||
| 179 | require Apache2::ServerUtil; | ||||||||||||||||||||||||||||
| 180 | require Apache2::RequestUtil; | ||||||||||||||||||||||||||||
| 181 | require Apache2::Const; | ||||||||||||||||||||||||||||
| 182 | Apache2::Const->import(-compile => qw(OK)); | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | $MP2_Is_Child = 0; | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | if(__PACKAGE__->apache_has_started) | ||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | $Debug && warn "$$ is already MP2 child (not registering child init handler)\n"; | ||||||||||||||||||||||||||||
| 189 | $MP2_Is_Child = 1; | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | elsif(!$ENV{'ROSE_DB_NO_CHILD_INIT_HANDLER'}) | ||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||
| 193 | Apache2::ServerUtil->server->push_handlers( | ||||||||||||||||||||||||||||
| 194 | PerlChildInitHandler => \&__mod_perl_2_rose_db_child_init_handler); | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | # http://mail-archives.apache.org/mod_mbox/perl-dev/200504.mbox/%3C4256B5FF.5060401@stason.org%3E | ||||||||||||||||||||||||||||
| 199 | # To work around this issue, we'll use a named subroutine. | ||||||||||||||||||||||||||||
| 200 | sub __mod_perl_2_rose_db_child_init_handler | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__mod_perl_2_rose_db_child_init_handler: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $Debug && warn "$$ is MP2 child\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | $MP2_Is_Child = 1; | |||||||||||||||||||||||||||
| 204 | 0 | return Apache2::Const::OK(); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | sub apache_has_started | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
apache_has_started: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 0 | my($class) = shift; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | return $Apache_Has_Started = $_[0] ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return $Apache_Has_Started if(defined $Apache_Has_Started); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | if(MOD_PERL_2) | |||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||
| 220 | return $Apache_Has_Started = $MP2_Is_Child; | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 0 | if(MOD_PERL_1) | |||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||
| 225 | return $Apache_Has_Started = $Apache::Server::Starting; | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | return undef; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | sub prepare_db | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prepare_db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 233 | 0 | my($self, $db, $entry) = @_; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | if(MOD_PERL_1) | |||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||
| 237 | if($Apache::Server::Starting) | ||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||
| 239 | $entry->created_during_apache_startup(1); | ||||||||||||||||||||||||||||
| 240 | $entry->prepared(0); | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | elsif(!$entry->is_prepared) | ||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||
| 244 | if($entry->created_during_apache_startup) | ||||||||||||||||||||||||||||
| 245 | { | ||||||||||||||||||||||||||||
| 246 | if($db->has_dbh) | ||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||
| 248 | $Debug && warn "$$ Disconnecting and undef-ing dbh ", $db->dbh, | ||||||||||||||||||||||||||||
| 249 | " created during apache startup from $db\n"; | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | my $error; | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | TRY: | ||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||
| 255 | local $@; | ||||||||||||||||||||||||||||
| 256 | eval { $db->dbh->disconnect }; # will probably fail! | ||||||||||||||||||||||||||||
| 257 | $error = $@; | ||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | warn "$$ Could not disconnect dbh created during apache startup: ", | ||||||||||||||||||||||||||||
| 261 | $db->dbh, " - $error" if($error); | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | $db->dbh(undef); | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | $entry->created_during_apache_startup(0); | ||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | Apache->push_handlers(PerlCleanupHandler => sub | ||||||||||||||||||||||||||||
| 270 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | $Debug && warn "$$ Clear dbh and prepared flag for $db, $entry\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $db->dbh(undef) if($db); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $entry->prepared(0) if($entry); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | }); | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | $entry->prepared(1); | ||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # Not a chained elsif to help Perl eliminate the unused code (maybe unnecessary?) | ||||||||||||||||||||||||||||
| 281 | 0 | if(MOD_PERL_2) | |||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | if(!$MP2_Is_Child) | ||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||
| 285 | $entry->created_during_apache_startup(1); | ||||||||||||||||||||||||||||
| 286 | $entry->prepared(0); | ||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | elsif(!$entry->is_prepared) | ||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||
| 290 | if($entry->created_during_apache_startup) | ||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||
| 292 | if($db->has_dbh) | ||||||||||||||||||||||||||||
| 293 | { | ||||||||||||||||||||||||||||
| 294 | $Debug && warn "$$ Disconnecting and undef-ing dbh ", $db->dbh, | ||||||||||||||||||||||||||||
| 295 | " created during apache startup from $db\n"; | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | my $error; | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | TRY: | ||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||
| 301 | local $@; | ||||||||||||||||||||||||||||
| 302 | eval { $db->dbh->disconnect }; # will probably fail! | ||||||||||||||||||||||||||||
| 303 | $error = $@; | ||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | warn "$$ Could not disconnect dbh created during apache startup: ", | ||||||||||||||||||||||||||||
| 307 | $db->dbh, " - $error" if($error); | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | $db->dbh(undef); | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | $entry->created_during_apache_startup(0); | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | my($r, $error); | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | TRY: | ||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||
| 319 | local $@; | ||||||||||||||||||||||||||||
| 320 | eval { $r = Apache2::RequestUtil->request }; | ||||||||||||||||||||||||||||
| 321 | $error = $@; | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | if($error) | ||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||
| 326 | $Debug && warn "Couldn't get apache request (restart count is ", | ||||||||||||||||||||||||||||
| 327 | Apache2::ServerUtil::restart_count(), ") - $error\n"; | ||||||||||||||||||||||||||||
| 328 | $entry->created_during_apache_startup(1); # tag for cleanup | ||||||||||||||||||||||||||||
| 329 | $entry->prepared(0); | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | return; | ||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | else | ||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | $r->push_handlers(PerlCleanupHandler => sub | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $Debug && warn "$$ Clear dbh and prepared flag for $db, $entry\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | $db->dbh(undef) if($db); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | $entry->prepared(0) if($entry); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | return Apache2::Const::OK(); | |||||||||||||||||||||||||||
| 341 | }); | ||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | $entry->prepared(1); | ||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 17 | 1; | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | __END__ | ||||||||||||||||||||||||||||