| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||
| 2 | ## File: DiaColloDB::threads::shared.pm | ||||||||||||||||||||||||||||
| 3 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||
| 4 | ## Descript: DiaColloDB: temporary data structures: use threads/shared.pm or forks/shared.pm | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package DiaColloDB::threads::shared; | ||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use DiaColloDB::threads; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our ($MODULE); | |||||||||||||||||||||||||||
| 11 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=8 SCAR=32.1
| |||||||||||||||||||||||||||||
| 12 | #$MODULE = '' if ($^P); ##-- disable threads if running under debugger | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | if (!defined($DiaColloDB::threads::MODULE)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 15 | 0 | $MODULE = ''; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | elsif (!defined($MODULE)) { | ||||||||||||||||||||||||||||
| 18 | ##-- attempt to load thread support | ||||||||||||||||||||||||||||
| 19 | 1 | my $loadme = $DiaColloDB::threads::MODULE; #.'::shared'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | if ($INC{"$loadme/shared.pm"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | ##-- thread-support already loaded | ||||||||||||||||||||||||||||
| 23 | 1 | $MODULE = "${loadme}::shared"; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | else { | ||||||||||||||||||||||||||||
| 26 | ##-- no thread-support loaded yet (loading forks/shared.pm does NOT set $INC{"threads/shared.pm"}=>"/path/to/forks/shared.pm") | ||||||||||||||||||||||||||||
| 27 | #print STDERR __PACKAGE__, ": attempting to load $module\n"; | ||||||||||||||||||||||||||||
| 28 | 0 | my $rc = eval "use ${loadme}::shared; 1"; | |||||||||||||||||||||||||||
| 29 | 0 | my $err = "$@"; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | $MODULE = ($rc && !$err) ? "${loadme}::shared" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rc and not $err
MC/DC0%0/2
$rc and not $err
$rc
not $err
Truth table0%0/3
A and not(B)
A= $rcB= not $err
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | warn(__PACKAGE__, " Warning: failed to load thread-support via ${loadme}/shared.pm: $err") if (!$MODULE); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $MODULE //= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$DiaColloDB::threads::shared::MODULE //= ""
MC/DC0%0/1
$DiaColloDB::threads::shared::MODULE //= ""
$DiaColloDB::threads::shared::MODULE
Truth table50%1/2
A
A= $DiaColloDB::threads::shared::MODULE
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | if ($MODULE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | #my $that = shift; | ||||||||||||||||||||||||||||
| 40 | 1 | my $caller = caller; | |||||||||||||||||||||||||||
| 41 | 1 | my $sub = eval qq{sub { package $caller; $MODULE->import(); } }; | |||||||||||||||||||||||||||
| 42 | 1 | $sub->(@_); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||