| 1 | package Wasm::Wasmtime::ExportType; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 22 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 22 | ▶ | use Ref::Util qw( is_blessed_ref ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use Wasm::Wasmtime::FFI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use Wasm::Wasmtime::ExternType; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Wasmtime export type class | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 22 | our $VERSION = '0.24'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 22 | $ffi_prefix = 'wasm_exporttype_'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 22 | $ffi->load_custom_type('::PtrObject' => 'wasm_exporttype_t' => __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 180 | ▶ | $ffi->attach( new => ['wasm_byte_vec_t*', 'opaque'] => 'wasm_exporttype_t' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 180 | my $xsub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 180 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # not sure this is actually useful... | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 180 | ▶ | if(defined $_[1] && is_blessed_ref $_[1] && $_[1]->isa('Wasm::Wasmtime::ExternType')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $_[1] and is_blessed_ref($_[1]) and $_[1]->isa("Wasm::Wasmtime::ExternType")
defined $_[1] and is_blessed_ref($_[1])
MC/DC0%0/3
defined $_[1] and is_blessed_ref($_[1]) and $_[1]->isa("Wasm::Wasmtime::ExternType")
defined $_[1]
is_blessed_ref($_[1])
$_[1]->isa("Wasm::Wasmtime::ExternType")
Truth table25%1/4
A and B and C
A= defined $_[1]B= is_blessed_ref($_[1])C= $_[1]->isa("Wasm::Wasmtime::ExternType")
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $name = Wasm::Wasmtime::ByteVec->new(shift); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $externtype = shift; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $self = $xsub->($name, $externtype->{ptr}); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $name->delete; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | else | ||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 180 | my ($ptr,$owner) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 180 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 35 | ptr => $ptr, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | owner => $owner, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | }); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 179 | ▶ | $ffi->attach( name => ['wasm_exporttype_t'] => 'wasm_byte_vec_t*' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 179 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 179 | my $name = $xsub->($self); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 179 | $name->get; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 22 | }); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 123 | ▶ | $ffi->attach( type => ['wasm_exporttype_t'] => 'wasm_externtype_t' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 123 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 123 | my $type = $xsub->($self); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 123 | ▶ | $type->{owner} = $self->{owner} || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'owner'} || $self
MC/DC0%0/2
$self->{'owner'} || $self
$self->{'owner'}
$self
Truth table33%1/3
A || B
A= $self->{'owner'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 123 | $type; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 22 | }); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub to_string | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | my $kind = $self->type->kind; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $kind =~ s/type$//; | |||||||||||||||||||||||||||||||||||||||||
| 62 | # TODO: escape strings ? | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | sprintf '(%s (export "%s") %s)', $kind, $self->name, $self->type->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 22 | _generate_destroy(); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 22 | _generate_vec_class(); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||||||