File Coverage

blib/lib/Wasm/Wasmtime/Trap.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::Trap;
2              
3 17     17   563 use strict;
  17         36  
  17         550  
4 17     17   88 use warnings;
  17         37  
  17         398  
5 17     17   283 use 5.008004;
  17         64  
6 17     17   1791 use Wasm::Wasmtime::FFI;
  17         43  
  17         1954  
7 17     17   4422 use Wasm::Wasmtime::Store;
  17         67  
  17         1399  
8             use overload
9 4     4   1270 '""' => sub { shift->message . "\n" },
10 12     12   73 bool => sub { 1 },
11 17     17   164 fallback => 1;
  17         52  
  17         187  
12              
13             # ABSTRACT: Wasmtime trap class
14             our $VERSION = '0.23'; # VERSION
15              
16              
17             $ffi_prefix = 'wasm_trap_';
18             $ffi->load_custom_type('::PtrObject' => 'wasm_trap_t' => __PACKAGE__);
19              
20              
21             $ffi->attach( new => [ 'wasm_store_t', 'wasm_byte_vec_t*' ] => 'wasm_trap_t' => sub {
22             my $xsub = shift;
23             my $class = shift;
24             if(@_ == 1)
25             {
26             my $ptr = shift;
27             return bless {
28             ptr => $ptr,
29             }, $class;
30             }
31             else
32             {
33             my $store = shift;
34             my $message = Wasm::Wasmtime::ByteVec->new($_[0]);
35             return $xsub->($store, $message);
36             }
37             });
38              
39              
40             $ffi->attach( message => ['wasm_trap_t', 'wasm_byte_vec_t*'] => sub {
41             my($xsub, $self) = @_;
42             my $message = Wasm::Wasmtime::ByteVec->new;
43             $xsub->($self, $message);
44             my $ret = $message->get;
45             $ret =~ s/\0$//;
46             $message->delete;
47             $ret;
48             });
49              
50              
51             $ffi->attach( [ wasmtime_trap_exit_status => 'exit_status' ] => ['wasm_trap_t', 'int*'] => 'bool' => sub {
52             my($xsub, $self) = @_;
53             my $status;
54             $xsub->($self, \$status)
55             ? $status
56             : undef;
57             });
58              
59             _generate_destroy();
60              
61             1;
62              
63             __END__