| 1 | package FFI::Platypus::Type::StringArray; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use FFI::Platypus; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Platypus custom type for arrays of strings | ||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '2.12'; # VERSION | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant _incantation => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | $^O eq 'MSWin32' && do { require Config; $Config::Config{archname} =~ /MSWin32-x64/ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$^O eq "MSWin32" and do {
require Config;
$Config::Config{"archname"} =~ /MSWin32-x64/
}
MC/DC0%0/2
$^O eq "MSWin32" and do {
require Config;
$Config::Config{"archname"} =~ /MSWin32-x64/
}
$^O eq "MSWin32"
do {
require Config;
$Config::Config{"archname"} =~ /MSWin32-x64/
}
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= do {
require Config;
$Config::Config{"archname"} =~ /MSWin32-x64/
}
| |||||||||||||||||||||||||||||
| 14 | ? 'Q' | ||||||||||||||||||||||||||||
| 15 | 1 | : 'L!'; | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant _size_of_pointer => FFI::Platypus->new( api => 2 )->sizeof('opaque'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant _pointer_buffer => "P" . _size_of_pointer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my @stack; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub perl_to_native | ||||||||||||||||||||||||||||
| 22 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
perl_to_native: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | # this is the variable length version | ||||||||||||||||||||||||||||
| 24 | # and is actually simpler than the | ||||||||||||||||||||||||||||
| 25 | # fixed length version | ||||||||||||||||||||||||||||
| 26 | 4 | my $count = scalar @{ $_[0] }; | |||||||||||||||||||||||||||
| 27 | 4 | my $pointers = pack(('P' x $count)._incantation, @{ $_[0] }, 0); | |||||||||||||||||||||||||||
| 28 | 4 | my $array_pointer = unpack _incantation, pack 'P', $pointers; | |||||||||||||||||||||||||||
| 29 | 4 | push @stack, [ \$_[0], \$pointers ]; | |||||||||||||||||||||||||||
| 30 | 4 | $array_pointer; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub perl_to_native_post | ||||||||||||||||||||||||||||
| 34 | 16 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
perl_to_native_post: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 16 | pop @stack; | |||||||||||||||||||||||||||
| 36 | 16 | (); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub native_to_perl | ||||||||||||||||||||||||||||
| 40 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
native_to_perl: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | return unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 3 | my @list; | |||||||||||||||||||||||||||
| 43 | 3 | my $i=0; | |||||||||||||||||||||||||||
| 44 | 3 | while(1) | |||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 7 | my $pointer_pointer = unpack( | |||||||||||||||||||||||||||
| 47 | _incantation, | ||||||||||||||||||||||||||||
| 48 | unpack( | ||||||||||||||||||||||||||||
| 49 | _pointer_buffer, | ||||||||||||||||||||||||||||
| 50 | pack( | ||||||||||||||||||||||||||||
| 51 | _incantation, $_[0]+_size_of_pointer*$i | ||||||||||||||||||||||||||||
| 52 | ) | ||||||||||||||||||||||||||||
| 53 | ) | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | 7 | ▶ | last unless $pointer_pointer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 4 | push @list, unpack('p', pack(_incantation, $pointer_pointer)); | |||||||||||||||||||||||||||
| 57 | 4 | $i++; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 3 | \@list; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub ffi_custom_type_api_1 | ||||||||||||||||||||||||||||
| 63 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
ffi_custom_type_api_1: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | # arg0 = class | ||||||||||||||||||||||||||||
| 65 | # arg1 = FFI::Platypus instance | ||||||||||||||||||||||||||||
| 66 | # arg2 = array size | ||||||||||||||||||||||||||||
| 67 | # arg3 = default value | ||||||||||||||||||||||||||||
| 68 | 5 | my(undef, undef, $count, $default) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | my $config = { | |||||||||||||||||||||||||||
| 71 | native_type => 'opaque', | ||||||||||||||||||||||||||||
| 72 | perl_to_native => \&perl_to_native, | ||||||||||||||||||||||||||||
| 73 | perl_to_native_post => \&perl_to_native_post, | ||||||||||||||||||||||||||||
| 74 | native_to_perl => \&native_to_perl, | ||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 5 | ▶ | if(defined $count) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 4 | my $end = $count-1; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 12 | ▶ | $config->{perl_to_native} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 82 | 12 | my $incantation = ''; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my @list = ((map { | ||||||||||||||||||||||||||||
| 85 | defined $_ | ||||||||||||||||||||||||||||
| 86 | 48 | ▶ | ? do { $incantation .= 'P'; $_ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | : defined $default | ||||||||||||||||||||||||||||
| 88 | 6 | ? do { $incantation .= 'P'; $default } | |||||||||||||||||||||||||||
| 89 | 60 | ▶ | : do { $incantation .= _incantation; 0 }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 12 | } @{ $_[0] }[0..$end]), 0); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 12 | $incantation .= _incantation; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 12 | my $pointers = pack $incantation, @list; | |||||||||||||||||||||||||||
| 95 | 12 | my $array_pointer = unpack _incantation, pack 'P', $pointers; | |||||||||||||||||||||||||||
| 96 | 12 | push @stack, [ \@list, $pointers ]; | |||||||||||||||||||||||||||
| 97 | 12 | $array_pointer; | |||||||||||||||||||||||||||
| 98 | 4 | }; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | my $pointer_buffer = "P@{[ FFI::Platypus->new( api => 2 )->sizeof('opaque') * $count ]}"; | |||||||||||||||||||||||||||
| 101 | 4 | my $incantation_count = _incantation.$count; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | $config->{native_to_perl} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 104 | 4 | ▶ | return unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 3 | my @pointer_pointer = unpack($incantation_count, unpack($pointer_buffer, pack(_incantation, $_[0]))); | |||||||||||||||||||||||||||
| 106 | 3 | ▶ | [map { $_ ? unpack('p', pack(_incantation, $_)) : $default } @pointer_pointer]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 4 | }; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 5 | $config; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||