blib/lib/FFI/Platypus/Closure.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 88.2% 15 / 17 Podpod 66.6% 4 / 6 totaltotal 88.6% 78 / 88 CC 6 SCAR 4.7
CC
6
Cov
92%
get_data
3.0
new
2.0
unstick
2.0
CRAP 1.6
« blib/lib/FFI/Platypus/Function.pm ↑ Summary blib/lib/FFI/Platypus/TypeParser.pm »
1 package FFI::Platypus::Closure;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use FFI::Platypus;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Scalar::Util qw( refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use overload '&{}' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
10 4 my $self = shift;
11 4 ▶ sub { $self->{code}->(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
12 0 ▶}, bool => sub { 1 }, fallback => 1;
Subroutine __ANON__: not called CC=1 SCAR=0.2
13  
14 # ABSTRACT: Platypus closure object
15 19 our $VERSION = '2.14_01'; # TRIAL VERSION
16  
17  
18 sub new
19 89 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod documented
20 89 my($class, $coderef) = @_;
21 89 ▶ croak "not a coderef" unless ref($coderef) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $coderef eq "CODE" 0 89 89
22 89 my $self = bless { code => $coderef, cbdata => {}, sticky => 0 }, $class;
23 89 $self;
24 }
25  
26 sub add_data
27 90 ▶{
Subroutine add_data: called CC=1 SCAR=0.0
Pod undocumented
28 90 my($self, $payload, $type) = @_;
29 90 $self->{cbdata}{$type} = bless \$payload, 'FFI::Platypus::ClosureData';
30 }
31  
32 sub get_data
33 91 ▶{
Subroutine get_data: called CC=3 SCAR=11.0
Pod undocumented
34 91 my($self, $type) = @_;
35  
36 # under ithreads the data from the parent thread is not cloned (see
37 # CLONE_SKIP below), so it will be undef in a child thread.
38 91 ▶ if (exists $self->{cbdata}->{$type} && defined ${$self->{cbdata}->{$type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cbdata"}{$type} and defined ${$self->{"cbdata"}{$type};}) 1 90 91
Condition66%2/3
exists $self->{"cbdata"}{$type} and defined ${$self->{"cbdata"}{$type};}
!ll&&!rl&&r
9001
MC/DC50%1/2
exists $self->{"cbdata"}{$type} and defined ${$self->{"cbdata"}{$type};}
exists $self->{"cbdata"}{$type} defined ${$self->{"cbdata"}{$type};}
Truth table66%2/3
A and B
A= exists $self->{"cbdata"}{$type}B= defined ${$self->{"cbdata"}{$type};}
ABresult
0X0
100
111
39 1 return ${$self->{cbdata}->{$type}};
40 }
41  
42 90 return 0;
43 }
44  
45  
46 sub call
47 2 ▶{
Subroutine call: called CC=1 SCAR=0.0
Pod documented
48 2 my $self = shift;
49 2 $self->{code}->(@_)
50 }
51  
52  
53 sub sticky
54 4 ▶{
Subroutine sticky: called CC=2 SCAR=6.9
Pod documented
55 4 my($self) = @_;
56 4 ▶ unless( $self->{sticky}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sticky"}) 3 1 4
57 3 $self->{sticky} = 1;
58 3 $self->_sticky;
59 }
60 4 return $self;
61 }
62  
63  
64 sub unstick
65 3 ▶{
Subroutine unstick: called CC=2 SCAR=7.0
Pod documented
66 3 my($self) = @_;
67 3 ▶ if( $self->{sticky} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sticky"}) 3 0 3
68 3 $self->{sticky} = 0;
69 3 $self->_unstick;
70 }
71 3 return $self;
72 }
73  
74 package FFI::Platypus::ClosureData;
75  
76 19 our $VERSION = '2.14_01'; # TRIAL VERSION
77  
78 # The C closure belongs to the thread that created it, so don't let a
79 # child thread use it, or free it when the child thread exits.
80 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
81  
82 19 1;
83  
84 __END__
« blib/lib/FFI/Platypus/Function.pm ↑ Summary blib/lib/FFI/Platypus/TypeParser.pm »