| 1 | package FFI::Platypus::Legacy::Raw::Callback; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 7 | ▶ | use FFI::Platypus::Memory qw( strdup free ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 7 | ▶ | use FFI::Platypus::Legacy::Raw::Platypus; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | # ABSTRACT: FFI::Platypus::Legacy::Raw function pointer type | ||||||||||||||
| 9 | 7 | our $VERSION = '0.06'; # VERSION | |||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | sub new | ||||||||||||||
| 13 | 7 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 14 | 7 | my($class, $coderef, $ret_type, @arg_types) = @_; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 7 | my $self; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 7 | ▶ | if($ret_type eq 's') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | { | ||||||||||||||
| 20 | 1 | $ret_type = 'opaque'; | |||||||||||||
| 21 | 1 | my $original = $coderef; | |||||||||||||
| 22 | 2 | ▶ | $coderef = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||
| 23 | 2 | ▶ | free $self->{strptr} if $self->{strptr}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 2 | delete $self->{strptr}; | |||||||||||||
| 25 | 2 | my $string = $original->(@_); | |||||||||||||
| 26 | 2 | ▶ | return undef unless defined $string; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 1 | $self->{strptr} = strdup($string); | |||||||||||||
| 28 | 1 | }; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 7 | ▶ | if($ret_type eq 'p') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | { | ||||||||||||||
| 33 | 3 | $ret_type = 'opaque'; | |||||||||||||
| 34 | 3 | my $original = $coderef; | |||||||||||||
| 35 | 3 | ▶ | $coderef = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.3
| |||||||||||||||
| 36 | 3 | my $ptr = $original->(@_); | |||||||||||||
| 37 | 3 | ▶ | return undef unless defined $ptr; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 2 | ▶ | if(ref $ptr) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | { | ||||||||||||||
| 40 | 1 | ▶ | if(eval { $ptr->isa('FFI::Platypus::Legacy::Raw::Ptr') }) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 41 | 1 | { $ptr = $$ptr } | |||||||||||||
| 42 | 0 | elsif(eval { $ptr->isa('FFI::Platypus::Legacy::Raw::Callback') }) | |||||||||||||
| 43 | 0 | { $ptr = $ptr->{ptr} } | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | 2 | $ptr; | |||||||||||||
| 46 | 3 | }; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 7 | my $closure = _ffi_package->closure($coderef); | |||||||||||||
| 50 | 7 | my $closure_type = '(' . join(',', @arg_types) . ")->$ret_type"; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 7 | $self = bless { | |||||||||||||
| 53 | coderef => $coderef, | ||||||||||||||
| 54 | closure => $closure, | ||||||||||||||
| 55 | ptr => _ffi_package->cast($closure_type => 'opaque', $closure), | ||||||||||||||
| 56 | }, $class; | ||||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | sub DESTROY | ||||||||||||||
| 60 | 6 | ▶ | { | ||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.1
| |||||||||||||||
| 61 | 6 | my($self) = @_; | |||||||||||||
| 62 | 6 | ▶ | free $self->{strptr} if $self->{strptr}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 6 | delete $self->{strptr}; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | |||||||||||||||
| 67 | 7 | 1; | |||||||||||||
| 68 | |||||||||||||||
| 69 | __END__ | ||||||||||||||