File Coverage

blib/lib/Doubly.pm
Criterion Covered Total %
statement 11 19 57.8
branch 1 2 50.0
condition n/a
subroutine 4 7 57.1
pod n/a
total 16 28 57.1


line stmt bran cond sub pod time code
1             package Doubly;
2              
3 41     41   10067406 use 5.006;
  41         199  
4 41     41   282 use strict;
  41         91  
  41         1516  
5 41     41   348 use warnings;
  41         114  
  41         14011  
6              
7             our $VERSION = '0.14';
8              
9             # Shared storage for refs that need to survive across threads
10             our %_ref_storage;
11             our $_ref_next_id;
12             our $_sharing_initialized;
13              
14             # Initialize sharing at compile time if threads are already loaded
15 0           BEGIN {
16             # Initialize variables here before any runtime code overwrites them
17 41     41   187 $Doubly::_ref_next_id = 0;
18 41         148 $Doubly::_sharing_initialized = 0;
19            
20 41 50       3227 if ($INC{'threads.pm'}) {
21 0           require threads::shared;
22             # Use fully qualified function name with explicit refs
23 0           &threads::shared::share(\%Doubly::_ref_storage);
24 0           &threads::shared::share(\$Doubly::_ref_next_id);
25 0           $Doubly::_sharing_initialized = 1;
26             }
27              
28             # Minimal helpers for XS to store/retrieve from shared hash
29             # (shared hashes need Perl-side assignment to work correctly)
30 0     0     sub _xs_store_ref { $_ref_storage{$_[0]} = $_[1] }
31 0     0     sub _xs_get_ref { $_ref_storage{$_[0]} }
32 0     0     sub _xs_clear_ref { delete $_ref_storage{$_[0]} }
33             }
34              
35             require XSLoader;
36             XSLoader::load('Doubly', $VERSION);
37              
38             1;
39              
40             __END__