FFI.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 89.8% 53 / 59 CC 4 SCAR 5.5
CC
4
Cov
91%
_ffi
3.1
BEGIN
2.1
BEGIN
1.0
CRAP 1.7
« FFI/Library.pm ↑ Summary
1 package FFI;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use FFI::Platypus;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use constant _is_win32 => $^O =~ /^(MSWin32|cygwin|msys2?)$/ && FFI::Platypus->abis->{stdcall};
Subroutine BEGIN: called CC=2 SCAR=7.6
Condition33%1/3
$^O =~ /^(MSWin32|cygwin|msys2?)$/ && 'FFI::Platypus'->abis->{'stdcall'}
!ll&&!rl&&r
300
MC/DC0%0/2
$^O =~ /^(MSWin32|cygwin|msys2?)$/ && 'FFI::Platypus'->abis->{'stdcall'}
$^O =~ /^(MSWin32|cygwin|msys2?)$/ 'FFI::Platypus'->abis->{'stdcall'}
Truth table33%1/3
A && B
A= $^O =~ /^(MSWin32|cygwin|msys2?)$/B= 'FFI::Platypus'->abis->{'stdcall'}
ABresult
0X0
100
111
8  
9 # ABSTRACT: Perl Foreign Function Interface based on libffi
10 3 our $VERSION = '1.15'; # VERSION
11  
12 3 our $ffi = FFI::Platypus->new;
13 3 $ffi->lib(undef);
14  
15 my $stdcall_ffi = _is_win32
16 3 ? do {
17 my $ffi = FFI::Platypus->new;
18 $ffi->lib(undef);
19 $ffi->abi('stdcall');
20 }
21 : $ffi;
22  
23 3 our %typemap = qw(
24 c char
25 C uchar
26 s short
27 S ushort
28 i int
29 I uint
30 l long
31 L ulong
32 f float
33 d double
34 p string
35 v void
36 o opaque
37 );
38  
39 sub _ffi
40 10 ▶{
Subroutine _ffi: called CC=3 SCAR=11.4
41 10 ▶ if($_[0] =~ s/^([sc])//)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ s/^([sc])//) { } 10 0 10
42 {
43 10 ▶ return $stdcall_ffi if $1 eq 's';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "s" 2 8 10
44 }
45 else
46 {
47 0 Carp::croak("first character of signature must be s or c");
48 }
49
50 8 $ffi;
51 }
52  
53 sub call
54 9 ▶{
Subroutine call: called CC=1 SCAR=0.0
Pod documented
55 9 my $addr = shift;
56 9 my $signature = shift;
57 9 my $ffi = _ffi($signature);
58 9 my($ret_type, @args_types) = map { $typemap{$_} } split //, $signature;
59 9 $ffi->function($addr => \@args_types => $ret_type)->call(@_);
60 }
61  
62 sub callback
63 1 ▶{
Subroutine callback: called CC=1 SCAR=0.0
Pod documented
64 1 my($signature, $sub) = @_;
65 1 my $ffi = _ffi($signature);
66 1 my($ret_type, @args_types) = map { $typemap{$_} } split //, $signature;
67 1 my $type = '(' . join(',', @args_types) . ')->' . $ret_type;
68 1 my $closure = $ffi->closure($sub);
69 1 bless {
70 addr => $ffi->cast($type => 'opaque', $closure),
71 sub => $sub,
72 closure => $closure,
73 }, 'FFI::Callback';
74 }
75  
76 package FFI::Callback;
77  
78 1 ▶sub addr { shift->{addr} }
Subroutine addr: called CC=1 SCAR=0.0
79  
80 3 1;
81  
82 __END__
« FFI/Library.pm ↑ Summary