| 1 | package FFI::Platypus::Record::StringArray; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use FFI::Platypus::Memory qw( strdup calloc free ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use constant _ptr_size => FFI::Platypus->new->sizeof('opaque'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: Array of strings for your FFI record | ||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | my $ffi; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||
| 16 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 17 | 1 | my $class = shift; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | $ffi ||= FFI::Platypus->new( lib => [undef] ); | ||||||||||||||||||
|
Condition33%1/3
$ffi ||= "FFI::Platypus"->new("lib", [undef])
MC/DC0%0/2
$ffi ||= "FFI::Platypus"->new("lib", [undef])
$ffi
"FFI::Platypus"->new("lib", [undef])
Truth table33%1/3
A ||= B
A= $ffiB= "FFI::Platypus"->new("lib", [undef])
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | my $size = @_; | |||||||||||||||||||
| 22 | 1 | ▶ | my $array = [map { defined $_ ? strdup($_) : undef } @_, undef]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 1 | my $opaque = calloc($size, _ptr_size); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | $ffi->function( | |||||||||||||||||||
| 26 | memcpy => [ 'opaque', "opaque[$size]", 'size_t' ] => 'opaque', | ||||||||||||||||||||
| 27 | )->call($opaque, $array, $size * _ptr_size); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | my $self = bless { | |||||||||||||||||||
| 30 | array => $array, | ||||||||||||||||||||
| 31 | opaque => $opaque, | ||||||||||||||||||||
| 32 | }, $class; | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub opaque | ||||||||||||||||||||
| 37 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
opaque: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 38 | 3 | my($self) = @_; | |||||||||||||||||||
| 39 | 3 | $self->{opaque}; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | sub size | ||||||||||||||||||||
| 44 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 45 | 1 | my($self) = @_; | |||||||||||||||||||
| 46 | 1 | scalar @{ $self->{array} } - 1; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub element | ||||||||||||||||||||
| 51 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 52 | 4 | my($self, $index) = @_; | |||||||||||||||||||
| 53 | 4 | $ffi->cast( 'opaque' => 'string', $self->{array}->[$index] ); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub DESTROY | ||||||||||||||||||||
| 57 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 58 | 1 | my($self) = @_; | |||||||||||||||||||
| 59 | 1 | free($_) for grep { defined $_ } @{ $self->{array} }; | |||||||||||||||||||
| 60 | 1 | free($self->{opaque}); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||