| 1 | package FFI::Platypus::Legacy::Raw::Platypus; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 8 | ▶ | use Ref::Util qw( is_ref ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 8 | ▶ | use FFI::Platypus; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 8 | ▶ | use base qw( Exporter ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: Private class for FFI::Platypus::Legacy::Raw | ||||||||||||||||||||
| 10 | 8 | our $VERSION = '0.06'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 8 | our @EXPORT = qw( _ffi _ffi_libc _ffi_package ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | sub _add_p_type | ||||||||||||||||||||
| 15 | 19 | ▶ | { | ||||||||||||||||||
|
Subroutine
_add_p_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 19 | my $ffi = shift; | |||||||||||||||||||
| 17 | $ffi->custom_type( | ||||||||||||||||||||
| 18 | 'p' => { | ||||||||||||||||||||
| 19 | native_type => 'opaque', | ||||||||||||||||||||
| 20 | 4 | ▶ | native_to_perl => sub { $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 34 | ▶ | perl_to_native => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 22 | 34 | ▶ | if(is_ref $_[0]) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | { | ||||||||||||||||||||
| 24 | 29 | ▶ | if(eval { $_[0]->isa('FFI::Platypus::Legacy::Raw::Ptr') }) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 25 | 18 | { return ${$_[0]} } | |||||||||||||||||||
| 26 | 11 | elsif(eval { $_[0]->isa('FFI::Platypus::Legacy::Raw::Callback') }) | |||||||||||||||||||
| 27 | 11 | { return $_[0]->{ptr} } | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 5 | $_[0]; | |||||||||||||||||||
| 30 | }, | ||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||
| 32 | 19 | ); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 8 | my %ffi; | |||||||||||||||||||
| 36 | sub _ffi ($) | ||||||||||||||||||||
| 37 | 55 | ▶ | { | ||||||||||||||||||
|
Subroutine
_ffi: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 38 | 55 | my $lib = shift; | |||||||||||||||||||
| 39 | 55 | ▶ | die "lib is not defined" unless defined $lib; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 55 | ▶ | $ffi{$lib} ||= do { | ||||||||||||||||||
|
Condition66%2/3
$ffi{$lib} ||= do {
my $ffi = "FFI::Platypus"->new;
$ffi->lang("Raw");
$ffi->lib($lib);
_add_p_type($ffi);
$ffi
}
MC/DC0%0/2
$ffi{$lib} ||= do {
my $ffi = "FFI::Platypus"->new;
$ffi->lang("Raw");
$ffi->lib($lib);
_add_p_type($ffi);
$ffi
}
$ffi{$lib}
do {
my $ffi = "FFI::Platypus"->new;
$ffi->lang("Raw");
$ffi->lib($lib);
_add_p_type($ffi);
$ffi
}
Truth table66%2/3
A ||= B
A= $ffi{$lib}B= do {
my $ffi = "FFI::Platypus"->new;
$ffi->lang("Raw");
$ffi->lib($lib);
_add_p_type($ffi);
$ffi
}
| |||||||||||||||||||||
| 41 | 8 | my $ffi = FFI::Platypus->new; | |||||||||||||||||||
| 42 | 8 | $ffi->lang('Raw'); | |||||||||||||||||||
| 43 | 8 | $ffi->lib($lib); | |||||||||||||||||||
| 44 | 8 | _add_p_type($ffi); | |||||||||||||||||||
| 45 | 8 | $ffi; | |||||||||||||||||||
| 46 | }; | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | my $libc; | ||||||||||||||||||||
| 50 | sub _ffi_libc () | ||||||||||||||||||||
| 51 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
_ffi_libc: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 52 | 4 | ▶ | unless($libc) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | { | ||||||||||||||||||||
| 54 | 3 | $libc = FFI::Platypus->new; | |||||||||||||||||||
| 55 | 3 | $libc->lang('Raw'); | |||||||||||||||||||
| 56 | 3 | $libc->lib(undef); | |||||||||||||||||||
| 57 | 3 | _add_p_type($libc); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 4 | $libc; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 8 | my $package; | |||||||||||||||||||
| 64 | sub _ffi_package () | ||||||||||||||||||||
| 65 | 29 | ▶ | { | ||||||||||||||||||
|
Subroutine
_ffi_package: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 66 | 29 | ▶ | unless($package) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | { | ||||||||||||||||||||
| 68 | 8 | $package = FFI::Platypus->new; | |||||||||||||||||||
| 69 | 8 | $package->lang('Raw'); | |||||||||||||||||||
| 70 | 8 | my $file = __FILE__; | |||||||||||||||||||
| 71 | # assumes of course that both this and ../Raw.pm | ||||||||||||||||||||
| 72 | # are installed together and in the same place. | ||||||||||||||||||||
| 73 | 8 | $file =~ s{Raw/Platypus\.pm$}{Raw.pm}; | |||||||||||||||||||
| 74 | 8 | $package->package('FFI::Platypus::Legacy::Raw', $file); | |||||||||||||||||||
| 75 | 8 | _add_p_type($package); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 29 | $package; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 8 | 1; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||