File Coverage

blib/lib/Wasm/Wasmtime/ExternType.pm
Criterion Covered Total %
statement 28 30 93.3
branch n/a
condition n/a
subroutine 9 11 81.8
pod 2 2 100.0
total 39 43 90.7


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::ExternType;
2              
3 26     26   228634 use strict;
  26         64  
  26         736  
4 26     26   191 use warnings;
  26         74  
  26         597  
5 26     26   412 use 5.008004;
  26         113  
6 26     26   2266 use Wasm::Wasmtime::FFI;
  26         87  
  26         4953  
7              
8             require Wasm::Wasmtime::FuncType;
9             require Wasm::Wasmtime::GlobalType;
10             require Wasm::Wasmtime::TableType;
11             require Wasm::Wasmtime::MemoryType;
12              
13             # ABSTRACT: Wasmtime extern type class
14             our $VERSION = '0.23'; # VERSION
15              
16              
17 0     0 1 0 sub kind { die "internal error" };
18 26     26   274 use constant is_functype => 0;
  26         67  
  26         1795  
19 26     26   181 use constant is_globaltype => 0;
  26         88  
  26         1351  
20 26     26   174 use constant is_tabletype => 0;
  26         71  
  26         1453  
21 26     26   233 use constant is_memorytype => 0;
  26         69  
  26         8668  
22              
23             $ffi_prefix = 'wasm_externtype_';
24              
25             $ffi->attach( [ kind => '_kind' ] => ['opaque'] => 'uint8' );
26              
27             my @cast;
28              
29             sub _cast
30             {
31 104     104   262 my(undef, $index) = @_;
32 104         238 my $caller = caller;
33 104         652 my($name) = map { lc $_ } $caller =~ /::([a-z]+Type)$/i;
  104         406  
34 104         604 $cast[$index] = $ffi->function( "wasm_externtype_as_$name" => ['opaque'] => "wasm_${name}_t" )->sub_ref;
35             }
36              
37             $ffi->custom_type('wasm_externtype_t' => {
38             native_type => 'opaque',
39             native_to_perl => sub {
40             my $externtype = shift;
41             Carp::croak("externtype error") unless defined $externtype;
42             my $kind = _kind($externtype);
43             $cast[$kind]->($externtype);
44             },
45             });
46              
47              
48             sub to_string
49             {
50 0     0 1   die "internal error"; # pure virtual ish
51             }
52              
53             1;
54              
55             __END__