Legacy/Raw/Callback.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 77.7% 14 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 91.5% 65 / 71 CC 10 SCAR 11.6
CC
10
Cov
90%
__ANON__
5.6
new
3.0
__ANON__
3.0
CRAP 3.2
↑ Summary Legacy/Raw/Platypus.pm »
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
BranchTrueFalseTotal
if ($ret_type eq "s") 1 6 7
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
BranchTrueFalseTotal
if $self->{"strptr"} 1 1 2
24 2 delete $self->{strptr};
25 2 my $string = $original->(@_);
26 2 ▶ return undef unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 1 1 2
27 1 $self->{strptr} = strdup($string);
28 1 };
29 }
30  
31 7 ▶ if($ret_type eq 'p')
Branch: 1 branch
BranchTrueFalseTotal
if ($ret_type eq "p") 3 4 7
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
BranchTrueFalseTotal
unless defined $ptr 1 2 3
38 2 ▶ if(ref $ptr)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ptr) 1 1 2
39 {
40 1 ▶ if(eval { $ptr->isa('FFI::Platypus::Legacy::Raw::Ptr') })
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { $ptr->isa('FFI::Platypus::Legacy::Raw::Ptr') } }) { } 1 0 1
elsif (eval { do { $ptr->isa('FFI::Platypus::Legacy::Raw::Callback') } }) { } 0 0 0
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
BranchTrueFalseTotal
if $self->{"strptr"} 0 6 6
63 6 delete $self->{strptr};
64 }
65  
66  
67 7 1;
68  
69 __END__
↑ Summary Legacy/Raw/Platypus.pm »