| 1 | package FFI::Platypus::Legacy::Raw::MemPtr; | ||||||||||||||
| 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 Carp qw( croak ); | ||||||||||||
|
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::Memory qw( malloc free memcpy ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 7 | ▶ | use FFI::Platypus::Buffer qw( scalar_to_buffer buffer_to_scalar ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # ABSTRACT: FFI::Platypus::Legacy::Raw memory pointer type | ||||||||||||||
| 11 | 7 | our $VERSION = '0.06'; # VERSION | |||||||||||||
| 12 | |||||||||||||||
| 13 | 7 | our @ISA = qw( FFI::Platypus::Legacy::Raw::Ptr ); | |||||||||||||
| 14 | |||||||||||||||
| 15 | |||||||||||||||
| 16 | sub new | ||||||||||||||
| 17 | 3 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 18 | 3 | my($class, $size) = @_; | |||||||||||||
| 19 | 3 | my $ptr = malloc $size; | |||||||||||||
| 20 | 3 | ▶ | die "malloc failed" unless defined $ptr; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 3 | bless \$ptr, $class; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | sub DESTROY | ||||||||||||||
| 25 | 9 | ▶ | { | ||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | 9 | my($self) = @_; | |||||||||||||
| 27 | 9 | free $$self; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | sub new_from_buf | ||||||||||||||
| 32 | 4 | ▶ | { | ||||||||||||
|
Subroutine
new_from_buf: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 33 | 4 | my($class, undef, $size) = @_; | |||||||||||||
| 34 | 4 | my $dst = malloc $size; | |||||||||||||
| 35 | 4 | my($src, undef) = scalar_to_buffer $_[1]; | |||||||||||||
| 36 | 4 | memcpy $dst, $src, $size; | |||||||||||||
| 37 | 4 | bless \$dst, $class; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | |||||||||||||||
| 41 | 7 | _ffi_package | |||||||||||||
| 42 | ->attach( | ||||||||||||||
| 43 | ['ffi__platypus__legacy__raw__memptr__new_from_ptr' => | ||||||||||||||
| 44 | '_new_from_ptr'] | ||||||||||||||
| 45 | => ['opaque'] => 'opaque' | ||||||||||||||
| 46 | ) | ||||||||||||||
| 47 | ; | ||||||||||||||
| 48 | |||||||||||||||
| 49 | sub new_from_ptr | ||||||||||||||
| 50 | 2 | ▶ | { | ||||||||||||
|
Subroutine
new_from_ptr: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 51 | 2 | my($class, $src) = @_; | |||||||||||||
| 52 | 2 | ▶ | if(ref $src) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | { | ||||||||||||||
| 54 | 1 | ▶ | if(eval { $src->isa('FFI::Platypus::Legacy::Raw::Ptr') }) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | { | ||||||||||||||
| 56 | 1 | $src = $$src; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | 2 | my $dst = _new_from_ptr($src); | |||||||||||||
| 60 | 2 | bless \$dst, $class; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | |||||||||||||||
| 64 | 7 | _ffi_package->attach_cast('_opaque_to_string', 'opaque' => 'string'); | |||||||||||||
| 65 | |||||||||||||||
| 66 | ## NOTE: prototype for a method is kind of dumb but we are including it for | ||||||||||||||
| 67 | ## full compatability with FFI::Raw | ||||||||||||||
| 68 | sub to_perl_str ($;$) | ||||||||||||||
| 69 | 4 | ▶ | { | ||||||||||||
|
Subroutine
to_perl_str: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||
| 70 | 4 | my($self, $size) = @_; | |||||||||||||
| 71 | 4 | ▶ | if(@_ == 1) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 72 | { | ||||||||||||||
| 73 | 1 | return _opaque_to_string($$self); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | elsif(@_ == 2) | ||||||||||||||
| 76 | { | ||||||||||||||
| 77 | 3 | return buffer_to_scalar($$self, $size); | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | else | ||||||||||||||
| 80 | { | ||||||||||||||
| 81 | 0 | croak "Wrong number of arguments"; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | sub tostr { | ||||||||||||
|
Subroutine
tostr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||
| 88 | 0 | return $self->to_perl_str(@_) | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 7 | 1; | |||||||||||||
| 92 | |||||||||||||||
| 93 | __END__ | ||||||||||||||