File Coverage

blib/lib/Wasm/Wasmtime/Module/Exports.pm
Criterion Covered Total %
statement 45 47 95.7
branch 3 4 75.0
condition 2 3 66.6
subroutine 11 14 78.5
pod 0 2 0.0
total 61 70 87.1


line stmt bran cond sub pod time code
1             package Wasm::Wasmtime::Module::Exports;
2              
3 22     22   159 use strict;
  22         57  
  22         648  
4 22     22   133 use warnings;
  22         45  
  22         550  
5 22     22   429 use 5.008004;
  22         149  
6 22     22   129 use Carp ();
  22         83  
  22         440  
7 22     22   12407 use Hash::Util ();
  22         65077  
  22         2983  
8             use overload
9             '%{}' => sub {
10 4     4   1475 my $self = shift;
11 4         19 my $module = $$self;
12 4         28 $module->{exports};
13             },
14             '@{}' => sub {
15 57     57   809 my $self = shift;
16 57         126 my $module = $$self;
17 57         189 my @exports = $module->_exports;
18 57         335 Internals::SvREADONLY @exports, 1;
19 57         317 Internals::SvREADONLY $exports[$_], 1 for 0..$#exports;
20 57         270 \@exports;
21             },
22 0     0   0 bool => sub { 1 },
23 22     22   181 fallback => 1;
  22         69  
  22         291  
24              
25             # ABSTRACT: Wasmtime module exports class
26             our $VERSION = '0.23'; # VERSION
27              
28              
29             sub new
30             {
31 57     57 0 184 my($class, $module) = @_;
32              
33 57   66     270 $module->{exports} ||= do {
34 38         154 my @exports = $module->_exports;
35 38         102 my %exports;
36 38         113 foreach my $export (@exports)
37             {
38 71         491 $exports{$export->name} = $export->type;
39             }
40 38         542 Hash::Util::lock_hash(%exports);
41 38         1034 \%exports;
42             };
43              
44 57         673 bless \$module, $class;
45             }
46              
47             sub can
48             {
49 10     10 0 25260 my($self, $name) = @_;
50 10         102 my $module = $$self;
51             exists $module->{exports}->{$name}
52 0     0   0 ? sub { $self->$name }
53 10 100       80 : $self->SUPER::can($name);
54             }
55              
56             sub AUTOLOAD
57             {
58 7     7   197 our $AUTOLOAD;
59 7         24 my $self = shift;
60              
61 7         14 my $name = $AUTOLOAD;
62 7         48 $name=~ s/^.*:://;
63              
64 7         33 my $module = $$self;
65 7 50       42 Carp::croak("no export $name") unless exists $module->{exports}->{$name};
66 7         26 $module->{exports}->{$name};
67             }
68              
69             sub DESTROY
70       0     {
71             # needed because of AUTOLOAD
72             }
73              
74              
75             1;
76              
77             __END__