line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZMQ::FFI::Util; |
2
|
|
|
|
|
|
|
$ZMQ::FFI::Util::VERSION = '0.16'; |
3
|
|
|
|
|
|
|
# ABSTRACT: zmq convenience functions |
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
57
|
use strict; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
444
|
|
6
|
10
|
|
|
10
|
|
48
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
398
|
|
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
8424
|
use FFI::Raw; |
|
10
|
|
|
|
|
83498
|
|
|
10
|
|
|
|
|
308
|
|
9
|
10
|
|
|
10
|
|
79
|
use Carp; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
1006
|
|
10
|
10
|
|
|
10
|
|
9325
|
use Try::Tiny; |
|
10
|
|
|
|
|
17369
|
|
|
10
|
|
|
|
|
776
|
|
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
|
|
105
|
use Sub::Exporter -setup => { |
13
|
|
|
|
|
|
|
exports => [qw( |
14
|
|
|
|
|
|
|
zmq_soname |
15
|
|
|
|
|
|
|
zmq_version |
16
|
|
|
|
|
|
|
)], |
17
|
10
|
|
|
10
|
|
13596
|
}; |
|
10
|
|
|
|
|
143466
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub zmq_soname { |
20
|
10
|
|
|
10
|
1
|
200
|
my %args = @_; |
21
|
|
|
|
|
|
|
|
22
|
10
|
|
|
|
|
33
|
my $die = $args{die}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Try to find a soname available on this system |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Linux .so symlink conventions are linker_name => soname => real_name |
27
|
|
|
|
|
|
|
# e.g. libzmq.so => libzmq.so.X => libzmq.so.X.Y.Z |
28
|
|
|
|
|
|
|
# Unfortunately not all distros follow this convention (Ubuntu). So first |
29
|
|
|
|
|
|
|
# we'll try the linker_name, then the sonames. |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# If Linux extensions fail also try platform specific |
32
|
|
|
|
|
|
|
# extensions (e.g. OS X) before giving up. |
33
|
10
|
|
|
|
|
62
|
my @sonames = qw( |
34
|
|
|
|
|
|
|
libzmq.so libzmq.so.3 libzmq.so.1 |
35
|
|
|
|
|
|
|
libzmq.dylib libzmq.3.dylib libzmq.1.dylib |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
16
|
my $soname; |
39
|
|
|
|
|
|
|
FIND_SONAME: |
40
|
10
|
|
|
|
|
27
|
for (@sonames) { |
41
|
|
|
|
|
|
|
try { |
42
|
60
|
|
|
60
|
|
1890
|
$soname = $_; |
43
|
|
|
|
|
|
|
|
44
|
60
|
|
|
|
|
14830
|
my $zmq_version = FFI::Raw->new( |
45
|
|
|
|
|
|
|
$soname => 'zmq_version', |
46
|
|
|
|
|
|
|
FFI::Raw::void, |
47
|
|
|
|
|
|
|
FFI::Raw::ptr, # major |
48
|
|
|
|
|
|
|
FFI::Raw::ptr, # minor |
49
|
|
|
|
|
|
|
FFI::Raw::ptr # patch |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
catch { |
53
|
60
|
|
|
60
|
|
745
|
undef $soname; |
54
|
60
|
|
|
|
|
440
|
}; |
55
|
|
|
|
|
|
|
|
56
|
60
|
50
|
|
|
|
628
|
last FIND_SONAME if $soname; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
10
|
50
|
33
|
|
|
112
|
if ( !$soname && $die ) { |
60
|
10
|
|
|
|
|
3235
|
croak |
61
|
|
|
|
|
|
|
qq(Could not load libzmq, tried:\n), |
62
|
|
|
|
|
|
|
join(', ', @sonames),"\n", |
63
|
|
|
|
|
|
|
q(Is libzmq on your ld path?); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $soname; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub zmq_version { |
70
|
0
|
|
|
0
|
1
|
|
my $soname = shift; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$soname //= zmq_soname(); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return unless $soname; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $zmq_version = FFI::Raw->new( |
77
|
|
|
|
|
|
|
$soname => 'zmq_version', |
78
|
|
|
|
|
|
|
FFI::Raw::void, |
79
|
|
|
|
|
|
|
FFI::Raw::ptr, # major |
80
|
|
|
|
|
|
|
FFI::Raw::ptr, # minor |
81
|
|
|
|
|
|
|
FFI::Raw::ptr # patch |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my ($major, $minor, $patch) = map { pack 'i!', $_ } (0, 0, 0); |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @ptrs = map { unpack('L!', pack('P', $_)) } ($major, $minor, $patch); |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$zmq_version->(@ptrs); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return map { unpack 'i!', $_ } ($major, $minor, $patch); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |