File Coverage

blib/lib/Wasm/Wasmtime/FuncType.pm
Criterion Covered Total %
statement 36 36 100.0
branch 6 6 100.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 1 1 100.0
total 55 56 98.2


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::FuncType;
2              
3 26     26   222951 use strict;
  26         89  
  26         748  
4 26     26   131 use warnings;
  26         53  
  26         647  
5 26     26   425 use 5.008004;
  26         104  
6 26     26   156 use base qw( Wasm::Wasmtime::ExternType );
  26         49  
  26         7518  
7 26     26   187 use Ref::Util qw( is_arrayref );
  26         57  
  26         1245  
8 26     26   170 use Wasm::Wasmtime::FFI;
  26         75  
  26         2362  
9 26     26   4979 use Wasm::Wasmtime::ValType;
  26         67  
  26         731  
10 26     26   150 use constant is_functype => 1;
  26         52  
  26         1437  
11 26     26   158 use constant kind => 'functype';
  26         93  
  26         14248  
12              
13             # ABSTRACT: Wasmtime function type class
14             our $VERSION = '0.21'; # VERSION
15              
16              
17             $ffi_prefix = 'wasm_functype_';
18             $ffi->load_custom_type('::PtrObject' => 'wasm_functype_t' => __PACKAGE__);
19              
20              
21             $ffi->attach( new => ['wasm_valtype_vec_t*', 'wasm_valtype_vec_t*'] => 'wasm_functype_t' => sub {
22             my $xsub = shift;
23             my $class = shift;
24             if(is_arrayref $_[0] && is_arrayref $_[1])
25             {
26             # try not to think too much about all of the maps here
27             my($params, $results) = map { my $rec = Wasm::Wasmtime::ValTypeVec->new; $rec->set($_) }
28             map { [map { delete $_->{ptr} } map { Wasm::Wasmtime::ValType->new($_) } @$_] } @_;
29             my $self = $xsub->($params, $results);
30             return $self;
31             }
32             else
33             {
34             my($ptr, $owner) = @_;
35             bless {
36             ptr => $ptr,
37             owner => $owner,
38             }, $class;
39             }
40             });
41              
42              
43             $ffi->attach( params => ['wasm_functype_t'] => 'wasm_valtype_vec_t*' => sub {
44             my($xsub, $self) = @_;
45             $xsub->($self)->to_list;
46             });
47              
48              
49             $ffi->attach( results => ['wasm_functype_t'] => 'wasm_valtype_vec_t*' => sub {
50             my($xsub, $self) = @_;
51             $xsub->($self)->to_list;
52             });
53              
54              
55             sub to_string
56             {
57 5     5 1 149 my($self) = @_;
58 5         28 my @params = map { $_->to_string } $self->params;
  9         95  
59 5         64 my @results = map { $_->to_string } $self->results;
  5         30  
60              
61 5         62 my $string = '';
62 5 100       33 $string .= "(param @params)" if @params;
63 5 100 66     46 $string .= ' ' if $string && @results;
64 5 100       34 $string .= "(result @results)" if @results;
65 5         39 $string;
66             }
67              
68             __PACKAGE__->_cast(0);
69             _generate_destroy();
70              
71             1;
72              
73             __END__