FFI/Util.pm

filter: Statementstmt 72.7% 32 / 44 Branchbran 33.3% 2 / 6 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 63.8% 46 / 72 CC 7 SCAR 14.9
CC
7
Cov
62%
zmq_version
12.0
zmq_soname
5.4
BEGIN
1.0
CRAP 4.4
« FFI/SocketBase.pm ↑ Summary FFI/ZMQ3/Context.pm »
1 package ZMQ::FFI::Util;
2 10 $ZMQ::FFI::Util::VERSION = '0.16';
3 # ABSTRACT: zmq convenience functions
4  
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use FFI::Raw;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 use Sub::Exporter -setup => {
13 exports => [qw(
14 zmq_soname
15 zmq_version
16 )],
17 10 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub zmq_soname {
20 10 ▶ my %args = @_;
Subroutine zmq_soname: called CC=5 SCAR=16.8
Pod documented
21  
22 10 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 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 my $soname;
39 FIND_SONAME:
40 10 for (@sonames) {
41 try {
42 60 ▶ $soname = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
43  
44 60 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 ▶ undef $soname;
Subroutine __ANON__: called CC=1 SCAR=0.0
54 60 };
55  
56 60 ▶ last FIND_SONAME if $soname;
Branch: 1 branch
BranchTrueFalseTotal
if $soname 0 60 60
57 }
58  
59 10 ▶ if ( !$soname && $die ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $soname and $die) 10 0 10
Condition33%1/3
not $soname and $die
!ll&&!rl&&r
0010
MC/DC0%0/2
not $soname and $die
not $soname $die
Truth table33%1/3
not(A) and B
A= not $sonameB= $die
ABresult
0X0
100
111
60 10 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 ▶ my $soname = shift;
Subroutine zmq_version: not called CC=3 SCAR=24.8
Pod documented
71  
72 0 ▶ $soname //= zmq_soname();
Condition0%0/3
$soname //= zmq_soname()
l!l&&r!l&&!r
000
MC/DC0%0/2
$soname //= zmq_soname()
$soname zmq_soname()
Truth table0%0/3
A //= B
A= $sonameB= zmq_soname()
ABresult
1X1
011
000
73  
74 0 ▶ return unless $soname;
Branch: 1 branch
BranchTrueFalseTotal
unless $soname 0 0 0
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);
85  
86 0 my @ptrs = map { unpack('L!', pack('P', $_)) } ($major, $minor, $patch);
87  
88 0 $zmq_version->(@ptrs);
89  
90 0 return map { unpack 'i!', $_ } ($major, $minor, $patch);
91 }
92  
93 10 1;
94  
95 __END__
« FFI/SocketBase.pm ↑ Summary FFI/ZMQ3/Context.pm »