line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wasm::Hook; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
537
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
479
|
use autodie; |
|
1
|
|
|
|
|
14441
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
6845
|
use 5.008004; |
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
569
|
use Wasm; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
7
|
use Ref::Util qw( is_ref ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
9
|
1
|
|
|
1
|
|
7
|
use Path::Tiny qw( path ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
55
|
|
10
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw( refaddr ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
502
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Automatically load WebAssembly modules without a Perl wrapper |
13
|
|
|
|
|
|
|
our $VERSION = '0.21'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _hook |
17
|
|
|
|
|
|
|
{ |
18
|
1
|
|
|
1
|
|
1490
|
my(undef, $file) = @_; |
19
|
1
|
|
|
|
|
3
|
foreach my $inc (@INC) |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
50
|
|
|
|
5
|
next if ref $inc; |
22
|
1
|
|
|
|
|
7
|
my $pm = path($inc)->child($file); |
23
|
1
|
50
|
|
|
|
92
|
return () if -f $pm; |
24
|
1
|
|
|
|
|
22
|
my $basename = $pm->basename; |
25
|
1
|
|
|
|
|
45
|
$basename =~ s/\.pm$//; |
26
|
0
|
|
|
|
|
0
|
my($wa) = sort { $b->stat->mtime <=> $a->stat->mtime } |
27
|
2
|
|
|
|
|
96
|
grep { -f $_ } |
28
|
1
|
|
|
|
|
3
|
map { $pm->parent->child($basename . $_) } |
|
2
|
|
|
|
|
89
|
|
29
|
|
|
|
|
|
|
qw( .wasm .wat ); |
30
|
1
|
50
|
|
|
|
23
|
next unless defined $wa; |
31
|
1
|
50
|
|
|
|
4
|
if(-f $wa) |
32
|
|
|
|
|
|
|
{ |
33
|
1
|
|
|
|
|
17
|
my $package = $file; |
34
|
1
|
|
|
|
|
7
|
$package =~ s/\.pm$//; |
35
|
1
|
|
|
|
|
4
|
$package =~ s/\//::/g; |
36
|
1
|
|
|
|
|
5
|
my $perl = qq{package $package; use Wasm -api => 0, -exporter => 'ok', -file => "$wa"; 1;\n}; |
37
|
1
|
|
|
|
|
5
|
my $fh; |
38
|
1
|
|
|
|
|
15
|
open $fh, '<', \$perl; |
39
|
1
|
|
|
|
|
3869
|
return ($fh); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
return (); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub import |
46
|
|
|
|
|
|
|
{ |
47
|
1
|
|
|
1
|
|
11
|
__PACKAGE__->unimport; |
48
|
1
|
|
|
|
|
35
|
push @INC, \&_hook; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub unimport |
52
|
|
|
|
|
|
|
{ |
53
|
2
|
100
|
|
2
|
|
866
|
@INC = grep { !is_ref($_) || refaddr($_) != refaddr(\&_hook) } @INC; |
|
22
|
|
|
|
|
69
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |