File Coverage

blib/lib/Wasm/Wasmtime/Wat2Wasm.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::Wat2Wasm;
2              
3 22     22   233386 use strict;
  22         54  
  22         723  
4 22     22   126 use warnings;
  22         50  
  22         628  
5 22     22   453 use 5.008004;
  22         96  
6 22     22   564 use Wasm::Wasmtime::FFI;
  22         57  
  22         2880  
7 22     22   176 use base qw( Exporter );
  22         50  
  22         7316  
8              
9             # ABSTRACT: Convert WebAssembly Text to Wasm
10             our $VERSION = '0.22'; # VERSION
11              
12              
13             our @EXPORT = qw( wat2wasm );
14              
15             $ffi_prefix = 'wasmtime_';
16              
17              
18             $ffi->attach( wat2wasm => ['wasm_byte_vec_t*','wasm_byte_vec_t*'] => 'wasmtime_error_t' => sub {
19             my $xsub = shift;
20             my $wat = Wasm::Wasmtime::ByteVec->new($_[0]);
21             my $ret = Wasm::Wasmtime::ByteVec->new;
22             my $error = $xsub->($wat, $ret);
23             if($error)
24             {
25             Carp::croak($error->message . "\nwat2wasm error");
26             }
27             else
28             {
29             my $wasm = $ret->get;
30             $ret->delete;
31             return $wasm;
32             }
33             });
34              
35             1;
36              
37             __END__