blib/lib/FFI/Platypus/Function.pm

filter: Statementstmt 100% 76 / 76 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 19 / 19 Podpod n/a totaltotal 100% 107 / 107 CC 7 SCAR 5.9
CC
7
Cov
100%
attach
4.0
attach
3.0
sub_ref
2.0
CRAP 1.8
« blib/lib/FFI/Platypus/Buffer.pm ↑ Summary blib/lib/FFI/Platypus/TypeParser.pm »
1 package FFI::Platypus::Function;
2  
3 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 57 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 57 ▶use FFI::Platypus;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: An FFI function object
9 57 our $VERSION = '2.12'; # VERSION
10  
11  
12 57 ▶use overload '&{}' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13 98 my $ffi = shift;
14 98 ▶ sub { $ffi->call(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
15 7 ▶}, 'bool' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
16 7 my $ffi = shift;
17 7 return $ffi;
18 57 }, fallback => 1;
19  
20 package FFI::Platypus::Function::Function;
21  
22 57 ▶use parent qw( FFI::Platypus::Function );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub attach
25 891 ▶{
Subroutine attach: called CC=3 SCAR=11.0
26 891 my($self, $perl_name, $proto) = @_;
27  
28 891 my $frame = -1;
29 891 my($caller, $filename, $line);
30  
31 891 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ and do { do { () = caller ++$frame } } 892 891 1783
32 1783 ($caller, $filename, $line) = caller(++$frame);
33 } while( $caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ );
34  
35 891 ▶ $perl_name = join '::', $caller, $perl_name
Branch: 1 branch
BranchTrueFalseTotal
unless $perl_name =~ /::/ 886 5 891
36 unless $perl_name =~ /::/;
37  
38 891 $self->_attach($perl_name, "$filename:$line", $proto);
39 891 $self;
40 }
41  
42 sub sub_ref
43 24 ▶{
Subroutine sub_ref: called CC=2 SCAR=6.9
44 24 my($self) = @_;
45  
46 24 my $frame = -1;
47 24 my($caller, $filename, $line);
48  
49 24 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ and do { do { () = caller ++$frame } } 41 24 65
50 65 ($caller, $filename, $line) = caller(++$frame);
51 } while( $caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ );
52  
53 24 $self->_sub_ref("$filename:$line");
54 }
55  
56 package FFI::Platypus::Function::Wrapper;
57  
58 57 ▶use parent qw( FFI::Platypus::Function );
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 sub new
61 32 ▶{
Subroutine new: called CC=1 SCAR=0.0
62 32 my($class, $function, $wrapper) = @_;
63 32 bless [ $function, $wrapper ], $class;
64 }
65  
66 sub call
67 19 ▶{
Subroutine call: called CC=1 SCAR=0.0
68 19 my($function, $wrapper) = @{ shift() };
69 19 @_ = ($function, @_);
70 19 goto &$wrapper;
71 }
72  
73 sub attach
74 21 ▶{
Subroutine attach: called CC=4 SCAR=13.9
75 21 my($self, $perl_name, $proto) = @_;
76 21 my($function, $wrapper) = @{ $self };
77  
78 21 ▶ unless($perl_name =~ /::/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($perl_name =~ /::/) 20 1 21
79 {
80 20 my $caller;
81 20 my $frame = -1;
82 20 ▶ do { $caller = caller(++$frame) } while( $caller =~ /^FFI::Platypus(|::Declare)$/ );
Branch: 1 branch
BranchTrueFalseTotal
$caller =~ /^FFI::Platypus(|::Declare)$/ and do { do { $caller = caller ++$frame } } 17 20 37
83 20 $perl_name = join '::', $caller, $perl_name
84 }
85  
86 21 my $xsub = $function->sub_ref;
87  
88 {
89 21 ▶ my $code = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
90 46 unshift @_, $xsub;
91 46 goto &$wrapper;
92 21 };
93 21 ▶ if(defined $proto)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proto) 4 17 21
94 {
95 4 _set_prototype($proto, $code);
96 }
97 57 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
98 21 *{$perl_name} = $code;
99 }
100  
101 21 $self;
102 }
103  
104 sub sub_ref
105 1 ▶{
Subroutine sub_ref: called CC=1 SCAR=0.0
106 1 my($self) = @_;
107 1 my($function, $wrapper) = @{ $self };
108 1 my $xsub = $function->sub_ref;
109  
110 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
111 1 unshift @_, $xsub;
112 1 goto &$wrapper;
113 1 };
114 }
115  
116 57 1;
117  
118 __END__
« blib/lib/FFI/Platypus/Buffer.pm ↑ Summary blib/lib/FFI/Platypus/TypeParser.pm »