File Coverage

blib/lib/Wasm/Memory.pm
Criterion Covered Total %
statement 32 32 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 11 11 100.0
pod 5 6 83.3
total 52 56 92.8


line stmt bran cond sub pod time code
1             package Wasm::Memory;
2              
3 5     5   479 use strict;
  5         14  
  5         204  
4 5     5   26 use warnings;
  5         10  
  5         131  
5 5     5   127 use 5.008004;
  5         20  
6 5     5   499 use Wasm::Wasmtime::Caller ();
  5         18  
  5         128  
7 5     5   29 use base qw( Exporter );
  5         9  
  5         1986  
8              
9             our @EXPORT_OK = qw( wasm_caller_memory );
10              
11             # ABSTRACT: Interface to WebAssembly Memory
12             our $VERSION = '0.22'; # VERSION
13              
14              
15             sub wasm_caller_memory
16             {
17 2     2 1 598 my $caller = Wasm::Wasmtime::Caller::wasmtime_caller();
18             defined $caller
19 2 100       11 ? do {
20 1         8 my $wm = $caller->export_get('memory');
21 1 50 33     22 defined $wm && $wm->is_memory
22             ? __PACKAGE__->new($wm)
23             : undef;
24             } : undef;
25             }
26              
27             sub new
28             {
29 13     13 0 35 my($class, $memory) = @_;
30 13         50 bless \$memory, $class;
31             }
32              
33              
34 1     1 1 1427 sub address { ${shift()}->data }
  1         9  
35 1     1 1 401 sub size { ${shift()}->data_size }
  1         6  
36              
37              
38             sub limits
39             {
40 3     3 1 1964 my $self = shift;
41 3         10 my $memory = $$self;
42 3         14 my $type = $memory->type;
43 3         12 ($memory->size, @{ $type->limits });
  3         36  
44             }
45              
46              
47             sub grow
48             {
49 1     1 1 650 my($self, $count) = @_;
50 1         2 ${$self}->grow($count);
  1         6  
51             }
52              
53             1;
54              
55             __END__