blib/lib/Wasm/Wasmtime/Linker.pm

filter: Statementstmt 97.0% 100 / 103 Branchbran 60.0% 18 / 30 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 21 / 21 Podpod 100% 1 / 1 totaltotal 86.0% 142 / 165 CC 18 SCAR 10.7
CC
18
Cov
86%
__ANON__
6.4
__ANON__
4.0
__ANON__
3.2
CRAP 2.9
« blib/lib/Wasm/Wasmtime/Config.pm ↑ Summary blib/lib/Wasm/Hook.pm »
1 package Wasm::Wasmtime::Linker;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use FFI::Platypus::Buffer qw( scalar_to_buffer );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Wasm::Wasmtime::FFI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Wasm::Wasmtime::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Wasm::Wasmtime::Extern;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Wasm::Wasmtime::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Wasm::Wasmtime::Func;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Wasm::Wasmtime::Trap;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Ref::Util qw( is_blessed_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Wasmtime linker class
17 9 our $VERSION = '0.24'; # VERSION
18  
19  
20 9 $ffi_prefix = 'wasmtime_linker_';
21 9 $ffi->load_custom_type('::PtrObject' => 'wasmtime_linker_t' => __PACKAGE__);
22  
23  
24 7 ▶$ffi->attach( new => ['wasm_engine_t'] => 'wasmtime_linker_t' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.8
25 7 my($xsub, $class, $store) = @_;
26 7 ▶ Carp::croak("Wasm::Wasmtime::Linker->new requires a Wasm::Wasmtime::Store")
Branch: 1 branch
BranchTrueFalseTotal
unless is_blessed_ref($store) and $store->isa("Wasm::Wasmtime::Store") 0 7 7
Condition33%1/3
is_blessed_ref($store) and $store->isa("Wasm::Wasmtime::Store")
!ll&&!rl&&r
007
MC/DC0%0/2
is_blessed_ref($store) and $store->isa("Wasm::Wasmtime::Store")
is_blessed_ref($store) $store->isa("Wasm::Wasmtime::Store")
Truth table33%1/3
A and B
A= is_blessed_ref($store)B= $store->isa("Wasm::Wasmtime::Store")
ABresult
0X0
100
111
27 unless is_blessed_ref($store) && $store->isa('Wasm::Wasmtime::Store');
28 7 my $self = $xsub->($store->engine);
29 7 $self->{store} = $store;
30 7 $self;
31 9 });
32  
33  
34 7 ▶$ffi->attach( allow_shadowing => [ 'wasmtime_linker_t', 'bool' ] => 'void' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 7 my($xsub, $self, $value) = @_;
36 7 $xsub->($self, $value);
37 7 $self;
38 9 });
39  
40  
41 5 ▶$ffi->attach( define => ['wasmtime_linker_t', 'opaque', 'opaque', 'size_t', 'opaque', 'size_t', 'wasmtime_extern_t'] => 'wasmtime_error_t' => sub {
Subroutine __ANON__: called CC=6 SCAR=18.5
42 5 my $xsub = shift;
43 5 my $self = shift;
44 5 my($module, $name, $extern) = @_;
45  
46 5 ▶ Carp::croak("not an extern: $extern")
Branch: 1 branch
BranchTrueFalseTotal
unless is_blessed_ref($extern) and $extern->isa("Wasm::Wasmtime::Extern") 0 5 5
Condition33%1/3
is_blessed_ref($extern) and $extern->isa("Wasm::Wasmtime::Extern")
!ll&&!rl&&r
005
MC/DC0%0/2
is_blessed_ref($extern) and $extern->isa("Wasm::Wasmtime::Extern")
is_blessed_ref($extern) $extern->isa("Wasm::Wasmtime::Extern")
Truth table33%1/3
A and B
A= is_blessed_ref($extern)B= $extern->isa("Wasm::Wasmtime::Extern")
ABresult
0X0
100
111
47 unless is_blessed_ref($extern) && $extern->isa('Wasm::Wasmtime::Extern');
48  
49 5 ▶ my $mod = defined $module ? "$module" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $module ? : 5 0 5
50 5 ▶ my $nam = defined $name ? "$name" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 5 0 5
51 5 my($mptr, $mlen) = scalar_to_buffer($mod);
52 5 my($nptr, $nlen) = scalar_to_buffer($nam);
53 5 my $e = $extern->to_extern;
54 5 ▶ if(my $error = $xsub->($self, $self->store->context, $mptr, $mlen, $nptr, $nlen, $e))
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &$xsub($self, $self->store->context, $mptr, $mlen, $nptr, $nlen, $e)) 1 4 5
55 {
56 1 Carp::croak($error->message);
57 }
58 4 $self;
59 9 });
60  
61  
62 4 ▶$ffi->attach( define_wasi => ['wasmtime_linker_t'] => 'wasmtime_error_t' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
63 4 my($xsub, $self) = @_;
64 4 ▶ if(my $error = $xsub->($self))
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &$xsub($self)) 0 4 4
65 {
66 0 Carp::croak($error->message);
67 }
68 4 $self;
69 9 });
70  
71  
72 20 ▶$ffi->attach( define_instance => ['wasmtime_linker_t', 'opaque', 'opaque', 'size_t', 'wasmtime_instance_t'] => 'wasmtime_error_t' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.8
73 20 my($xsub, $self, $name, $instance) = @_;
74 20 ▶ my $nam = defined $name ? "$name" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 20 0 20
75 20 my($nptr, $nlen) = scalar_to_buffer($nam);
76 20 ▶ if(my $error = $xsub->($self, $self->store->context, $nptr, $nlen, $instance->{data}))
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &$xsub($self, $self->store->context, $nptr, $nlen, $instance->{"data"})) 0 20 20
77 {
78 0 Carp::croak($error->message);
79 }
80 20 $self;
81 9 });
82  
83  
84 21 ▶$ffi->attach( instantiate => ['wasmtime_linker_t','opaque','wasmtime_module_t','wasmtime_instance_t','opaque*'] => 'wasmtime_error_t' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
85 21 my($xsub, $self, $module) = @_;
86 21 my $data = Wasm::Wasmtime::InstanceData->new;
87 21 my $trap;
88 21 ▶ if(my $error = $xsub->($self, $self->store->context, $module, $data, \$trap))
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &$xsub($self, $self->store->context, $module, $data, \$trap)) 1 20 21
89 {
90 1 die Wasm::Wasmtime::Trap->from_error($error);
91 }
92 20 ▶ die Wasm::Wasmtime::Trap->new($trap) if $trap;
Branch: 1 branch
BranchTrueFalseTotal
if $trap 0 20 20
93 20 return Wasm::Wasmtime::Instance->_new_from_data($data, $self->store, $module);
94 9 });
95  
96  
97 2 ▶$ffi->attach( [ get => 'get_one_by_name' ] => ['wasmtime_linker_t','opaque','opaque','size_t','opaque','size_t','wasmtime_extern_t'] => 'bool' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
98 2 my($xsub, $self, $module, $name) = @_;
99 2 ▶ my $mod = defined $module ? "$module" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $module ? : 2 0 2
100 2 ▶ my $nam = defined $name ? "$name" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
101 2 my($mptr, $mlen) = scalar_to_buffer($mod);
102 2 my($nptr, $nlen) = scalar_to_buffer($nam);
103 2 my $extern = Wasm::Wasmtime::ExternData->new;
104 2 ▶ $xsub->($self, $self->store->context, $mptr, $mlen, $nptr, $nlen, $extern)
Branch: 1 branch
BranchTrueFalseTotal
&$xsub($self, $self->store->context, $mptr, $mlen, $nptr, $nlen, $extern) or Carp::croak("no such item in linker: ${mod}::$nam") 1 1 2
105 or Carp::croak("no such item in linker: $mod\::$nam");
106 1 my $obj = Wasm::Wasmtime::Extern->from_extern($extern, $self->store);
107 1 $extern->free;
108 1 $obj;
109 9 });
110  
111  
112 1 ▶$ffi->attach( get_default => ['wasmtime_linker_t','opaque','opaque','size_t','wasmtime_func_t'] => 'wasmtime_error_t' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
113 1 my($xsub, $self, $name) = @_;
114 1 ▶ my $nam = defined $name ? "$name" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 1 0 1
115 1 my($nptr, $nlen) = scalar_to_buffer($nam);
116 1 my $data = Wasm::Wasmtime::FuncData->new;
117 1 ▶ if(my $error = $xsub->($self, $self->store->context, $nptr, $nlen, $data))
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &$xsub($self, $self->store->context, $nptr, $nlen, $data)) 0 1 1
118 {
119 0 Carp::croak($error->message);
120 }
121 1 bless { data => $data, store => $self->store }, 'Wasm::Wasmtime::Func';
122 9 });
123  
124  
125 97 ▶sub store { shift->{store} }
Subroutine store: called CC=1 SCAR=0.0
Pod documented
126  
127 9 _generate_destroy('wasmtime_linker_delete');
128  
129 9 1;
130  
131 __END__
« blib/lib/Wasm/Wasmtime/Config.pm ↑ Summary blib/lib/Wasm/Hook.pm »