blib/lib/App/plasm.pm

filter: Statementstmt 97.2% 105 / 108 Branchbran 67.8% 19 / 28 Conditioncond 75.0% 6 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 92.0% 23 / 25 Podpod 0.0% 0 / 1 totaltotal 88.5% 155 / 175 CC 18 SCAR 11.7
CC
18
Cov
90%
main
7.1
main
5.3
main
4.2
CRAP 3.2
↑ Summary
1 package App::plasm;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Perl WebAssembly command line tool
10 4 our $VERSION = '0.03'; # VERSION
11  
12  
13 sub main
14 14 ▶{
Subroutine main: called CC=7 SCAR=19.6
Pod undocumented
15 14 my $class = shift; # unused
16  
17 14 Getopt::Long::Configure('permute');
18  
19 14 ▶ if(defined $_[0] && $_[0] =~ /\.wasm$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /\.wasm$/) 0 14 14
Condition66%2/3
defined $_[0] and $_[0] =~ /\.wasm$/
!ll&&!rl&&r
2120
MC/DC0%0/2
defined $_[0] and $_[0] =~ /\.wasm$/
defined $_[0] $_[0] =~ /\.wasm$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /\.wasm$/
ABresult
0X0
100
111
20 {
21 0 unshift @_, 'run';
22 }
23  
24 14 ▶ if(defined $_[0] && $_[0] !~ /^-/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and not $_[0] =~ /^-/) { } 9 5 14
Condition100%3/3
defined $_[0] and not $_[0] =~ /^-/
!ll&&!rl&&r
239
MC/DC100%2/2
defined $_[0] and not $_[0] =~ /^-/
defined $_[0] not $_[0] =~ /^-/
Truth table100%3/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^-/
ABresult
0X0
100
111
25 {
26 9 my $cmd = shift;
27 9 my $class = "App::plasm::$cmd";
28 9 my $main = $class->can('main');
29 9 ▶ pod2usage({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $main 1 8 9
30 -message => "no subcommand '$cmd'",
31 -exitval => 2,
32 }) unless defined $main;
33 8 return $main->(@_);
34 }
35 else
36 {
37 5 local @ARGV = @_;
38 GetOptions(
39 1 ▶ 'help|h' => sub { pod2usage({ -exitval => 0 }) },
Subroutine __ANON__: called CC=1 SCAR=0.0
40 1 ▶ 'version|v' => sub { print "plasm version @{[ App::plasm->VERSION || 'dev' ]} Wasm.pm @{[ Wasm->VERSION ]}\n"; exit 0 },
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition50%1/2
'App::plasm'->VERSION || 'dev'
l!l
10
MC/DC0%0/1
'App::plasm'->VERSION || 'dev'
'App::plasm'->VERSION
Truth table50%1/2
A
A= 'App::plasm'->VERSION
Aresult
11
00
41 5 ▶ ) or pod2usage({ -exitval => 2 });
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", sub { pod2usage({"-exitval", 0}); } , "version|v", sub { print qq[plasm version @{["App::plasm"->VERSION || "dev"];} Wasm.pm @{["Wasm"->VERSION];}\n]; &CORE::GLOBAL::exit(0); } ) or pod2usage({"-exitval", 2}) 2 1 3
42 2 pod2usage({ -exitval => 2 });
43 }
44 }
45  
46 package App::plasm::run;
47  
48 4 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
49 4 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
50 4 ▶use Wasm 0.08;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 4 ▶use Wasm::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 4 my $sandbox;
54  
55 sub main
56 5 ▶{
Subroutine main: called CC=4 SCAR=13.9
57 5 local @ARGV = @_;
58  
59 5 Getopt::Long::Configure('require_order');
60  
61 5 my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/run");
62  
63 GetOptions(
64 1 ▶ 'help|h' => sub { pod2usage({ -exitval => 0, @pod }) },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 5 ▶ ) or pod2usage({ -exitval => 2, @pod });
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", sub { pod2usage({"-exitval", 0, @pod}); } ) or pod2usage({"-exitval", 2, @pod}) 3 1 4
66  
67 3 my $filename = shift @ARGV;
68  
69 3 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 3 3
70 -exitval => 2,
71 }) unless defined $filename;
72  
73 3 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 1 2 3
74 -message => "File not found: $filename",
75 -exitval => 2,
76 }) unless -f $filename;
77  
78 2 my $class = "App::plasm::run::sandbox@{[ $sandbox++ ]}";
79  
80 2 local $0 = $filename;
81  
82 2 Wasm->import(
83 -api => 0,
84 -package => $class,
85 -file => $filename,
86 );
87  
88 2 my $start = $class->can('_start');
89 2 $start->();
90  
91 # TODO: detect exit value and pass that on...
92  
93 2 return 0;
94 }
95  
96 package App::plasm::dump;
97  
98 4 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
99 4 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
100 4 ▶use Wasm::Wasmtime 0.08;
Subroutine BEGIN: called CC=1 SCAR=0.0
101  
102 sub main
103 2 ▶{
Subroutine main: called CC=4 SCAR=14.5
104 2 local @ARGV = @_;
105  
106 2 my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/run");
107  
108 GetOptions(
109 0 ▶ 'help|h' => sub { pod2usage({ -exitval => 0, @pod }) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 2 ▶ ) or pod2usage({ -exitval => 2, @pod });
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", sub { pod2usage({"-exitval", 0, @pod}); } ) or pod2usage({"-exitval", 2, @pod}) 2 0 2
111  
112 2 my $filename = shift @ARGV;
113  
114 2 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 2 2
115 -exitval => 2,
116 }) unless defined $filename;
117  
118 2 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 2 2
119 -message => "File not found: $filename",
120 -exitval => 2,
121 }) unless -f $filename;
122  
123 2 my $module = Wasm::Wasmtime::Module->new(
124 file => $filename,
125 );
126  
127 2 print $module->to_string;
128  
129 2 return 0;
130 }
131  
132 package App::plasm::wat;
133  
134 4 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
135 4 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
136 4 ▶use Wasm::Wasmtime::Wat2Wasm qw( wat2wasm );
Subroutine BEGIN: called CC=1 SCAR=0.0
137 4 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 sub main
140 1 ▶{
Subroutine main: called CC=5 SCAR=16.6
141 1 local @ARGV = @_;
142  
143 1 my @pod = (-verbose => 99, -sections => "SUBCOMMANDS/wat");
144  
145 GetOptions(
146 0 ▶ 'help|h' => sub { pod2usage({ -exitval => 0, @pod }) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
147 1 ▶ ) or pod2usage({ -exitval => 2, @pod });
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help|h", sub { pod2usage({"-exitval", 0, @pod}); } ) or pod2usage({"-exitval", 2, @pod}) 1 0 1
148  
149 1 my $filename = shift @ARGV;
150  
151 1 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 1 1
152 -exitval => 2,
153 }) unless defined $filename;
154  
155 1 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 1 1
156 -message => "File not found: $filename",
157 -exitval => 2,
158 }) unless -f $filename;
159  
160 1 my $in = path($filename);
161 1 my $out = $in->parent->child(do {
162 1 my $basename = $in->basename;
163 1 $basename =~ s/\.wat$//;
164 1 $basename . '.wasm';
165 });
166  
167 1 ▶ pod2usage({ @pod,
Branch: 1 branch
BranchTrueFalseTotal
if -e $out 0 1 1
168 -message => "Output file already exists: $out",
169 -exitval => 2,
170 }) if -e $out;
171  
172 1 $out->spew_raw(wat2wasm($in->slurp_utf8));
173  
174 1 return 0;
175 }
176  
177 4 1;
178  
179 __END__
↑ Summary