blib/lib/Wasm/Wasmtime/GlobalType.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 90.2% 83 / 92 CC 6 SCAR 10.0
CC
6
Cov
92%
__ANON__
6.4
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« blib/lib/Wasm/Wasmtime/Module.pm ↑ Summary blib/lib/Wasm/Wasmtime/MemoryType.pm »
1 package Wasm::Wasmtime::GlobalType;
2  
3 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use base qw( Wasm::Wasmtime::ExternType );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶use Wasm::Wasmtime::FFI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 ▶use Wasm::Wasmtime::ValType;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 26 ▶use Ref::Util qw( is_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use constant is_globaltype => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use constant kind => 'globaltype';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # ABSTRACT: Wasmtime global type class
15 26 our $VERSION = '0.24'; # VERSION
16  
17  
18 26 $ffi_prefix = 'wasm_globaltype_';
19 26 $ffi->load_custom_type('::PtrObject' => 'wasm_globaltype_t' => __PACKAGE__);
20  
21  
22 26 my %mutability = (
23 const => 0,
24 var => 1,
25 );
26  
27 5 ▶$ffi->attach( new => ['wasm_valtype_t','uint8'] => 'wasm_globaltype_t' => sub {
Subroutine __ANON__: called CC=6 SCAR=18.6
28 5 my $xsub = shift;
29 5 my $class = shift;
30 5 my $ptr;
31 my $owner;
32 5 ▶ if(defined $_[0] && !is_ref($_[0]) && $_[0] =~ /^[0-9]+$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not is_ref($_[0]) and $_[0] =~ /^[0-9]+$/) { } 0 5 5
Condition66%4/6
defined $_[0] and not is_ref($_[0]) and $_[0] =~ /^[0-9]+$/
!ll&&!rl&&r
140
defined $_[0] and not is_ref($_[0])
!ll&&!rl&&r
014
MC/DC0%0/3
defined $_[0] and not is_ref($_[0]) and $_[0] =~ /^[0-9]+$/
defined $_[0] not is_ref($_[0]) $_[0] =~ /^[0-9]+$/
Truth table50%2/4
A and not(B) and C
A= defined $_[0]B= not is_ref($_[0])C= $_[0] =~ /^[0-9]+$/
ABCresult
0XX0
10X0
1100
1111
33 {
34 0 my($ptr, $owner) = @_;
35 0 return bless {
36 ptr => $ptr,
37 owner => $owner,
38 }, $class;
39 }
40 else
41 {
42 5 my($valtype, $mutability) = @_;
43 5 ▶ if(ref($valtype) eq 'Wasm::Wasmtime::ValType')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $valtype eq 'Wasm::Wasmtime::ValType') { } 1 4 5
44 {
45 1 $valtype = Wasm::Wasmtime::ValType->new($valtype->kind);
46 }
47 else
48 {
49 4 $valtype = Wasm::Wasmtime::ValType->new($valtype);
50 }
51 5 ▶ Carp::croak("mutability must be one of 'const' or 'var'") unless defined $mutability{$mutability};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mutability{$mutability} 0 5 5
52 5 my $self = $xsub->($valtype, $mutability{$mutability});
53 5 delete $valtype->{ptr};
54 5 return $self;
55 }
56 26 });
57  
58  
59 11 ▶$ffi->attach( content => ['wasm_globaltype_t'] => 'wasm_valtype_t' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 11 my($xsub, $self) = @_;
61 11 my $valtype = $xsub->($self);
62 11 $valtype->{owner} = $self;
63 11 $valtype;
64 26 });
65  
66  
67 26 my @mutability = (
68 'const',
69 'var',
70 );
71  
72 7 ▶$ffi->attach( mutability => ['wasm_globaltype_t'] => 'uint8' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 7 my($xsub, $self) = @_;
74 7 $mutability[$xsub->($self)];
75 26 });
76  
77  
78 sub to_string
79 3 ▶{
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
80 3 my($self) = @_;
81 3 return sprintf("(%s %s)", $self->mutability, $self->content->to_string);
82 }
83  
84 26 __PACKAGE__->_cast(1);
85 26 _generate_destroy();
86  
87 26 1;
88  
89 __END__
« blib/lib/Wasm/Wasmtime/Module.pm ↑ Summary blib/lib/Wasm/Wasmtime/MemoryType.pm »