| 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
| |||||||||||||||||||||
| 22 | 17 | my $pm = path($inc)->child($file); | |||||||||||||||||||
| 23 | 17 | ▶ | return () if -f $pm; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 31 | 1 | ▶ | if(-f $wa) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | 1; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||