| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $self->{"cbdata"}{$type} and defined ${$self->{"cbdata"}{$type};}
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};}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||