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
« lib/FFI/Build/PluginData.pm ↑ Summary blib/lib/FFI/Platypus/Buffer.pm »
1 package FFI::Platypus::Function;
2  
3 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 56 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use FFI::Platypus;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: An FFI function object
9 56 our $VERSION = '2.11'; # VERSION
10  
11  
12 use overload '&{}' => sub {
13 98 ▶ my $ffi = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 98 ▶ sub { $ffi->call(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
15 }, 'bool' => sub {
16 9 ▶ my $ffi = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
17 9 return $ffi;
18 56 ▶}, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 package FFI::Platypus::Function::Function;
21  
22 56 ▶use parent qw( FFI::Platypus::Function );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub attach
25 {
26 859 ▶ my($self, $perl_name, $proto) = @_;
Subroutine attach: called CC=3 SCAR=11.0
27  
28 859 my $frame = -1;
29 859 my($caller, $filename, $line);
30  
31 859 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ and do { do { () = caller ++$frame } } 860 859 1719
32 1719 ($caller, $filename, $line) = caller(++$frame);
33 } while( $caller =~ /^FFI::Platypus(|::Function|::Function::Wrapper|::Declare)$/ );
34  
35 859 ▶ $perl_name = join '::', $caller, $perl_name
Branch: 1 branch
BranchTrueFalseTotal
unless $perl_name =~ /::/ 854 5 859
36 unless $perl_name =~ /::/;
37  
38 859 $self->_attach($perl_name, "$filename:$line", $proto);
39 859 $self;
40 }
41  
42 sub sub_ref
43 {
44 24 ▶ my($self) = @_;
Subroutine sub_ref: called CC=2 SCAR=6.9
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 56 ▶use parent qw( FFI::Platypus::Function );
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 sub new
61 {
62 32 ▶ my($class, $function, $wrapper) = @_;
Subroutine new: called CC=1 SCAR=0.0
63 32 bless [ $function, $wrapper ], $class;
64 }
65  
66 sub call
67 {
68 19 ▶ my($function, $wrapper) = @{ shift() };
Subroutine call: called CC=1 SCAR=0.0
69 19 @_ = ($function, @_);
70 19 goto &$wrapper;
71 }
72  
73 sub attach
74 {
75 21 ▶ my($self, $perl_name, $proto) = @_;
Subroutine attach: called CC=4 SCAR=13.9
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 {
90 46 ▶ unshift @_, $xsub;
Subroutine __ANON__: called CC=1 SCAR=0.0
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 56 ▶ 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 {
106 1 ▶ my($self) = @_;
Subroutine sub_ref: called CC=1 SCAR=0.0
107 1 my($function, $wrapper) = @{ $self };
108 1 my $xsub = $function->sub_ref;
109  
110 return sub {
111 1 ▶ unshift @_, $xsub;
Subroutine __ANON__: called CC=1 SCAR=0.0
112 1 goto &$wrapper;
113 1 };
114 }
115  
116 56 1;
117  
118 __END__
« lib/FFI/Build/PluginData.pm ↑ Summary blib/lib/FFI/Platypus/Buffer.pm »