File Coverage

blib/lib/DiaColloDB/threads/shared.pm
Criterion Covered Total %
statement 15 20 75.0
branch 4 12 33.3
condition 1 5 20.0
subroutine 4 4 100.0
pod n/a
total 24 41 58.5


line stmt bran cond sub pod time code
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     1   8 use DiaColloDB::threads;
  1         3  
  1         7  
8 1     1   67 use strict;
  1         2  
  1         184  
9              
10             our ($MODULE);
11             BEGIN {
12             #$MODULE = '' if ($^P); ##-- disable threads if running under debugger
13              
14 1 50   1   8 if (!defined($DiaColloDB::threads::MODULE)) {
    50          
15 0         0 $MODULE = '';
16             }
17             elsif (!defined($MODULE)) {
18             ##-- attempt to load thread support
19 1         2 my $loadme = $DiaColloDB::threads::MODULE; #.'::shared';
20              
21 1 50       13 if ($INC{"$loadme/shared.pm"}) {
22             ##-- thread-support already loaded
23 1         4 $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         0 my $rc = eval "use ${loadme}::shared; 1";
29 0         0 my $err = "$@";
30 0 0 0     0 $MODULE = ($rc && !$err) ? "${loadme}::shared" : '';
31 0 0       0 warn(__PACKAGE__, " Warning: failed to load thread-support via ${loadme}/shared.pm: $err") if (!$MODULE);
32             }
33 1   50     97 $MODULE //= '';
34             }
35             }
36              
37             sub import {
38 1 50   1   6 if ($MODULE) {
39             #my $that = shift;
40 1         3 my $caller = caller;
41 1         71 my $sub = eval qq{sub { package $caller; $MODULE->import(); } };
42 1         22 $sub->(@_);
43             }
44             }
45              
46             1; ##-- be happy
47              
48             __END__