Legacy/Raw.pm

filter: Statementstmt 93.2% 55 / 59 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.7% 18 / 19 Podpod 100% 8 / 8 totaltotal 92.7% 89 / 96 CC 6 SCAR 5.6
CC
6
Cov
91%
attach
4.2
new
2.0
new_from_ptr
2.0
CRAP 1.8
« Legacy/Raw/MemPtr.pm ↑ Summary Lang/Raw.pm »
1 package FFI::Platypus::Legacy::Raw;
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;
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 7 ▶use FFI::Platypus::Legacy::Raw::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use FFI::Platypus::Legacy::Raw::Ptr;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use FFI::Platypus::Legacy::Raw::MemPtr;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 use overload
11 7 ▶ '&{}' => \&coderef,
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 'bool' => \&_bool;
13  
14 # ABSTRACT: Perl bindings to the portable FFI library (libffi)
15 7 our $VERSION = '0.06'; # VERSION
16  
17 3 ▶sub _bool {
Subroutine _bool: called CC=1 SCAR=0.0
18 3 my $ffi = shift;
19 3 return $ffi;
20 }
21  
22  
23 sub _new
24 57 ▶{
Subroutine _new: called CC=1 SCAR=0.0
25 57 my($class, $ffi, $id, $ret_type, @types) = @_;
26 57 my $f = $ffi->function($id => \@types => $ret_type);
27 56 bless [$f], $class;
28 }
29  
30 sub new
31 57 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
32 57 my($class, $library, $function, @types) = @_;
33 57 ▶ my $self = $class->_new(
Branch: 1 branch
BranchTrueFalseTotal
defined $library ? : 54 3 57
34 defined $library ? _ffi $library : _ffi_libc,
35 $function,
36 @types
37 );
38 56 $self->[1] = $function;
39 56 $self;
40 }
41  
42  
43 sub new_from_ptr
44 0 ▶{
Subroutine new_from_ptr: not called CC=1 SCAR=6.9
Pod documented
45 0 my($class, $ptr, @types) = @_;
46 0 $class->_new(
47 _ffi_package,
48 $ptr,
49 @types,
50 );
51
52 }
53  
54  
55 sub call
56 97 ▶{
Subroutine call: called CC=1 SCAR=0.0
Pod documented
57 97 my $self = shift;
58 97 $self->[0]->call(@_);
59 }
60  
61  
62 sub coderef
63 33 ▶{
Subroutine coderef: called CC=1 SCAR=0.0
Pod documented
64 33 my $self = shift;
65 33 ▶ return sub { $self->call(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
66 }
67  
68  
69 1 ▶sub memptr { FFI::Platypus::Legacy::Raw::MemPtr->new(@_) }
Subroutine memptr: called CC=1 SCAR=0.0
Pod documented
70  
71  
72 7 ▶sub callback { FFI::Platypus::Legacy::Raw::Callback->new(@_) }
Subroutine callback: called CC=1 SCAR=0.0
Pod documented
73  
74  
75 sub void () { 'v' }
76  
77  
78 sub int () { 'i' }
79  
80  
81 sub uint () { 'I' }
82  
83  
84 sub short () { 'z' }
85  
86  
87 sub ushort () { 'Z' }
88  
89  
90 sub long () { 'l' }
91  
92  
93 sub ulong () { 'L' }
94  
95  
96 sub int64 () { 'x' }
97  
98  
99 sub uint64 () { 'X' }
100  
101  
102 sub char () { 'c' }
103  
104  
105 sub uchar () { 'C' }
106  
107  
108 sub float () { 'f' }
109  
110  
111 sub double () { 'd' }
112  
113  
114 sub str () { 's' }
115  
116  
117 sub ptr () { 'p' }
118  
119  
120 sub attach
121 3 ▶{
Subroutine attach: called CC=4 SCAR=14.5
Pod documented
122 3 my($self, $perl_name, $proto) = @_;
123  
124 3 ▶ unless(defined $perl_name)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $perl_name) 2 1 3
125 {
126 2 $perl_name = $self->[1];
127 2 ▶ unless(defined $perl_name)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $perl_name) 0 2 2
128 {
129 0 require Carp;
130 0 Carp::croak("Cannot determine function name from a pointer");
131 }
132 }
133  
134 # some of this logic is unfortunately replicated
135 # in FFI-Platypus :/
136 3 ▶ if($perl_name !~ /::/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($perl_name =~ /::/) 3 0 3
137 {
138 3 my $caller = caller;
139 3 $perl_name = join '::', $caller, $perl_name;
140 }
141
142 3 $self->[0]->attach($perl_name, $proto);
143 }
144  
145  
146 sub platypus
147 2 ▶{
Subroutine platypus: called CC=2 SCAR=6.9
Pod documented
148 2 my(undef, $library) = @_;
149 2 ▶ unless(defined $library)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $library) 1 1 2
150 {
151 1 require Carp;
152 1 Carp::croak("cannot get platypus instance for undef lib");
153 }
154 1 _ffi $library;
155 }
156  
157  
158 7 1;
159  
160 __END__
« Legacy/Raw/MemPtr.pm ↑ Summary Lang/Raw.pm »