| 1 | package DBIO::MySQL::MariaDBForkGuard; | ||||||||||
| 2 | # ABSTRACT: keep a forked child's exit from closing DBD::MariaDB connections it inherited | ||||||||||
| 3 | |||||||||||
| 4 | 50 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 50 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 50 | our $VERSION = '0.900007'; | |||||||||
| 8 | |||||||||||
| 9 | # Set once, to the pid that installed the guard. The wrapper compares against it. | ||||||||||
| 10 | 50 | my $OWNER; | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 206 | ▶ | sub install { | ||||||||
|
Subroutine
install: called CC=4 SCAR=19.2
Pod
documented
| |||||||||||
| 15 | 206 | ▶ | return 1 if defined $OWNER; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | return 0 unless eval { require DBD::MariaDB; 1 }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | my $original = DBD::MariaDB::dr->can('disconnect_all') or return 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | $OWNER = $$; | |||||||||
| 22 | |||||||||||
| 23 | 50 | ▶ | no warnings 'redefine'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 50 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 0 | ▶ | *{'DBD::MariaDB::dr::disconnect_all'} = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 26 | 0 | ▶ | return 1 if $$ != $OWNER; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | goto &$original; | |||||||||
| 28 | 0 | }; | |||||||||
| 29 | |||||||||||
| 30 | 0 | return 1; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 50 | 1; | |||||||||
| 35 | |||||||||||
| 36 | __END__ | ||||||||||