File Coverage

blib/lib/Wasm/Wasmtime/WasiInstance.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::WasiInstance;
2              
3 10     10   506 use strict;
  10         21  
  10         295  
4 10     10   48 use warnings;
  10         20  
  10         267  
5 10     10   170 use 5.008004;
  10         39  
6 10     10   185 use Wasm::Wasmtime::FFI;
  10         21  
  10         1128  
7 10     10   73 use Wasm::Wasmtime::Store;
  10         22  
  10         241  
8 10     10   475 use Wasm::Wasmtime::Trap;
  10         34  
  10         284  
9 10     10   4066 use Wasm::Wasmtime::WasiConfig;
  10         33  
  10         2474  
10              
11             # ABSTRACT: WASI instance class
12             our $VERSION = '0.22'; # VERSION
13              
14              
15             $ffi_prefix = 'wasi_instance_';
16             $ffi->load_custom_type('::PtrObject' => 'wasi_instance_t' => __PACKAGE__);
17              
18              
19             $ffi->attach( new => ['wasm_store_t', 'string', 'wasi_config_t', 'opaque*'] => 'wasi_instance_t' => sub {
20             my $xsub = shift;
21             my $class = shift;
22             my $store = shift;
23             my $name = shift;
24             my $config = defined $_[0] && ref($_[0]) eq 'Wasm::Wasmtime::WasiConfig' ? shift : Wasm::Wasmtime::WasiConfig->new;
25             my $trap;
26             my $instance = $xsub->($store, $name, $config, \$trap);
27             delete $config->{ptr};
28             unless($instance)
29             {
30             if($trap)
31             {
32             die Wasm::Wasmtime::Trap->new($trap);
33             }
34             Carp::croak("failed to create wasi instance");
35             }
36             $instance;
37             });
38              
39             # TODO: bind_import
40              
41             _generate_destroy();
42              
43             1;
44              
45             __END__