Legacy/Raw/MemPtr.pm

filter: Statementstmt 93.7% 45 / 48 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 89.3% 67 / 75 CC 6 SCAR 6.4
CC
6
Cov
90%
to_perl_str
3.1
new_from_ptr
3.0
new
2.0
CRAP 1.9
« Legacy/Raw/Platypus.pm ↑ Summary Legacy/Raw.pm »
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
BranchTrueFalseTotal
unless defined $ptr 0 3 3
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
BranchTrueFalseTotal
if (ref $src) 1 1 2
53 {
54 1 ▶ if(eval { $src->isa('FFI::Platypus::Legacy::Raw::Ptr') })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $src->isa("FFI::Platypus::Legacy::Raw::Ptr") } }) 1 0 1
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
BranchTrueFalseTotal
if (@_ == 1) { } 1 3 4
elsif (@_ == 2) { } 3 0 3
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__
« Legacy/Raw/Platypus.pm ↑ Summary Legacy/Raw.pm »