blib/lib/Wasm/Hook.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 93.2% 69 / 74 CC 7 SCAR 10.6
CC
7
Cov
93%
_hook
6.0
unimport
2.0
BEGIN
1.0
CRAP 2.9
« blib/lib/Wasm/Wasmtime/Linker.pm ↑ Summary blib/lib/Wasm/Wasmtime/Store.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.24'; # VERSION
14  
15  
16 sub _hook
17 3 ▶{
Subroutine _hook: called CC=6 SCAR=18.0
18 3 my(undef, $file) = @_;
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 1 ▶{
Subroutine import: called CC=1 SCAR=0.0
47 1 __PACKAGE__->unimport;
48 1 push @INC, \&_hook;
49 }
50  
51 sub unimport
52 2 ▶{
Subroutine unimport: called CC=2 SCAR=7.1
53 2 ▶ @INC = grep { !is_ref($_) || refaddr($_) != refaddr(\&_hook) } @INC;
Condition66%2/3
!is_ref($_) || builtin::refaddr($_) != builtin::refaddr(\&Wasm::Hook::_hook)
l!l&&r!l&&!r
1601
MC/DC50%1/2
!is_ref($_) || builtin::refaddr($_) != builtin::refaddr(\&Wasm::Hook::_hook)
!is_ref($_) builtin::refaddr($_) != builtin::refaddr(\&Wasm::Hook::_hook)
Truth table66%2/3
not(A) || B
A= !is_ref($_)B= builtin::refaddr($_) != builtin::refaddr(\&Wasm::Hook::_hook)
ABresult
1X1
011
000
54 }
55  
56 1 1;
57  
58 __END__
« blib/lib/Wasm/Wasmtime/Linker.pm ↑ Summary blib/lib/Wasm/Wasmtime/Store.pm »