blib/lib/Wasm/Hook.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 95.7% 68 / 71 CC 7 SCAR 10.6
CC
7
Cov
95%
_hook
6.0
unimport
2.0
BEGIN
1.0
CRAP 2.9
« blib/lib/Wasm/Wasmtime/WasiInstance.pm ↑ Summary blib/lib/Wasm/Wasmtime/ExportType.pm »
1 package Wasm::Hook;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Wasm;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Ref::Util qw( is_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Automatically load WebAssembly modules without a Perl wrapper
13 1 our $VERSION = '0.23'; # VERSION
14  
15  
16 sub _hook
17 {
18 3 ▶ my(undef, $file) = @_;
Subroutine _hook: called CC=6 SCAR=18.0
19 3 foreach my $inc (@INC)
20 {
21 19 ▶ next if ref $inc;
Branch: 1 branch
BranchTrueFalseTotal
if ref $inc 2 17 19
22 17 my $pm = path($inc)->child($file);
23 17 ▶ return () if -f $pm;
Branch: 1 branch
BranchTrueFalseTotal
if -f $pm 0 17 17
24 17 my $basename = $pm->basename;
25 17 $basename =~ s/\.pm$//;
26 0 my($wa) = sort { $b->stat->mtime <=> $a->stat->mtime }
27 34 grep { -f $_ }
28 17 map { $pm->parent->child($basename . $_) }
29 qw( .wasm .wat );
30 17 ▶ next unless defined $wa;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wa 16 1 17
31 1 ▶ if(-f $wa)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $wa) 1 0 1
32 {
33 1 my $package = $file;
34 1 $package =~ s/\.pm$//;
35 1 $package =~ s/\//::/g;
36 1 my $perl = qq{package $package; use Wasm -api => 0, -exporter => 'ok', -file => "$wa"; 1;\n};
37 1 my $fh;
38 1 open $fh, '<', \$perl;
39 1 return ($fh);
40 }
41 }
42 2 return ();
43 }
44  
45 sub import
46 {
47 1 ▶ __PACKAGE__->unimport;
Subroutine import: called CC=1 SCAR=0.0
48 1 push @INC, \&_hook;
49 }
50  
51 sub unimport
52 {
53 2 ▶ @INC = grep { !is_ref($_) || refaddr($_) != refaddr(\&_hook) } @INC;
Subroutine unimport: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not is_ref($_) or builtin::refaddr($_) != builtin::refaddr(\&Wasm::Hook::_hook) 1 16 17
54 }
55  
56 1 1;
57  
58 __END__
« blib/lib/Wasm/Wasmtime/WasiInstance.pm ↑ Summary blib/lib/Wasm/Wasmtime/ExportType.pm »