File Coverage

blib/lib/Wasm/Wasmtime/Extern.pm
Criterion Covered Total %
statement 28 29 96.5
branch n/a
condition n/a
subroutine 9 10 90.0
pod 1 1 100.0
total 38 40 95.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::Extern;
2              
3 16     16   3334 use strict;
  16         38  
  16         522  
4 16     16   116 use warnings;
  16         39  
  16         380  
5 16     16   254 use 5.008004;
  16         57  
6 16     16   1783 use Wasm::Wasmtime::FFI;
  16         41  
  16         7699  
7              
8             require Wasm::Wasmtime::Func;
9             require Wasm::Wasmtime::Global;
10             require Wasm::Wasmtime::Table;
11             require Wasm::Wasmtime::Memory;
12              
13             # ABSTRACT: Wasmtime extern class
14             our $VERSION = '0.23'; # VERSION
15              
16              
17             $ffi_prefix = 'wasm_extern_';
18              
19             $ffi->attach( [ kind => '_kind' ] => ['opaque'] => 'uint8' );
20              
21             my @cast;
22              
23             sub _cast
24             {
25 64     64   169 my(undef, $index) = @_;
26 64         127 my $caller = caller;
27 64         378 my($name) = map { lc $_ } $caller =~ /::([a-z]+)$/i;
  64         232  
28 64         382 $cast[$index] = $ffi->function( "wasm_extern_as_$name" => ['opaque'] => "wasm_${name}_t" )->sub_ref;
29             }
30              
31             $ffi->custom_type('wasm_extern_t' => {
32             native_type => 'opaque',
33             native_to_perl => sub {
34             my $extern = shift;
35             Carp::croak("extern error") unless defined $extern;
36             my $kind = _kind($extern);
37             $cast[$kind]->($extern);
38             },
39             });
40              
41             $ffi->attach_cast('new', 'opaque', 'wasm_extern_t', sub {
42             my($xsub, undef, $ptr, $owner) = @_;
43             my $self = $xsub->($ptr);
44             $self->{owner} = $owner;
45             $self;
46             });
47              
48 16     16   170 use constant is_func => 0;
  16         71  
  16         1236  
49 16     16   123 use constant is_global => 0;
  16         41  
  16         858  
50 16     16   106 use constant is_table => 0;
  16         42  
  16         753  
51 16     16   94 use constant is_memory => 0;
  16         49  
  16         1509  
52              
53 0     0 1   sub kind { die "internal error" };
54              
55             _generate_vec_class();
56              
57             1;
58              
59             __END__