| 1 | package Wasm::Wasmtime::ImportType; | ||||||||||||||||||||||||||||
| 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 Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use Ref::Util qw( is_blessed_ref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use Wasm::Wasmtime::FFI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use Wasm::Wasmtime::ExternType; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Wasmtime import type class | ||||||||||||||||||||||||||||
| 12 | 22 | our $VERSION = '0.24'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 22 | $ffi_prefix = 'wasm_importtype_'; | |||||||||||||||||||||||||||
| 16 | 22 | $ffi->load_custom_type('::PtrObject' => 'wasm_importtype_t' => __PACKAGE__); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 47 | ▶ | $ffi->attach( new => ['wasm_byte_vec_t*', 'wasm_byte_vec_t*', 'opaque'] => 'wasm_importtype_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=26.3
| |||||||||||||||||||||||||||||
| 20 | 47 | my $xsub = shift; | |||||||||||||||||||||||||||
| 21 | 47 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | 47 | ▶ | if(defined $_[2] && is_blessed_ref $_[2]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[2] and is_blessed_ref($_[2])
MC/DC0%0/2
defined $_[2] and is_blessed_ref($_[2])
defined $_[2]
is_blessed_ref($_[2])
Truth table33%1/3
A and B
A= defined $_[2]B= is_blessed_ref($_[2])
| |||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 0 | my $externtype = $_[2]; | |||||||||||||||||||||||||||
| 25 | # not sure this is actually useful? | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if(is_blessed_ref($externtype) && $externtype->isa('Wasm::Wasmtime::ExternType')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_blessed_ref($externtype) and $externtype->isa("Wasm::Wasmtime::ExternType")
MC/DC0%0/2
is_blessed_ref($externtype) and $externtype->isa("Wasm::Wasmtime::ExternType")
is_blessed_ref($externtype)
$externtype->isa("Wasm::Wasmtime::ExternType")
Truth table0%0/3
A and B
A= is_blessed_ref($externtype)B= $externtype->isa("Wasm::Wasmtime::ExternType")
| |||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 0 | my $module = Wasm::Wasmtime::ByteVec->new(shift); | |||||||||||||||||||||||||||
| 29 | 0 | my $name = Wasm::Wasmtime::ByteVec->new(shift); | |||||||||||||||||||||||||||
| 30 | 0 | my $self = $xsub->($module, $name, $externtype->{ptr}); | |||||||||||||||||||||||||||
| 31 | 0 | $module->delete; | |||||||||||||||||||||||||||
| 32 | 0 | $name->delete; | |||||||||||||||||||||||||||
| 33 | 0 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 0 | Carp::croak("Not an externtype"); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else | ||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 47 | my($ptr,$owner) = @_; | |||||||||||||||||||||||||||
| 43 | 47 | return bless { | |||||||||||||||||||||||||||
| 44 | ptr => $ptr, | ||||||||||||||||||||||||||||
| 45 | owner => $owner, | ||||||||||||||||||||||||||||
| 46 | }, $class; | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 22 | }); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 31 | ▶ | $ffi->attach( name => ['wasm_importtype_t'] => 'wasm_byte_vec_t*' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 31 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 53 | 31 | my $name = $xsub->($self); | |||||||||||||||||||||||||||
| 54 | 31 | $name->get; | |||||||||||||||||||||||||||
| 55 | 22 | }); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 39 | ▶ | $ffi->attach( type => ['wasm_importtype_t'] => 'wasm_externtype_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 59 | 39 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 60 | 39 | my $type = $xsub->($self); | |||||||||||||||||||||||||||
| 61 | 39 | ▶ | $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
| |||||||||||||||||||||||||||||
| 62 | 39 | $type; | |||||||||||||||||||||||||||
| 63 | 22 | }); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 15 | ▶ | $ffi->attach( module => ['wasm_importtype_t'] => 'wasm_byte_vec_t*' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 15 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 68 | 15 | my $name = $xsub->($self); | |||||||||||||||||||||||||||
| 69 | 15 | $name->get; | |||||||||||||||||||||||||||
| 70 | 22 | }); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub to_string | ||||||||||||||||||||||||||||
| 74 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 76 | 2 | my $kind = $self->type->kind; | |||||||||||||||||||||||||||
| 77 | 2 | $kind =~ s/type$//; | |||||||||||||||||||||||||||
| 78 | # TODO: escape strings ? | ||||||||||||||||||||||||||||
| 79 | 2 | sprintf '(%s (import "%s" "%s") %s)', $kind, $self->module, $self->name, $self->type->to_string; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 22 | _generate_destroy(); | |||||||||||||||||||||||||||
| 83 | 22 | _generate_vec_class(); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 22 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||