blib/script/spvm

filter: Statementstmt 71.7% 33 / 46 Branchbran 50.0% 9 / 18 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 62.2% 51 / 82 CC 1 SCAR 0.0
CC
1
Cov
64%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« SPVM.xs ↑ Summary blib/script/spvmcc »
1 #!/usr/local/bin/perl
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use SPVM::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use SPVM::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 SPVM::Builder::Util::getopt
10 # spvm,spvmcc,spvmdeps common
11 'h|help' => \my $help,
12 'v|version' => \my $show_version,
13 'I=s' => \my @spvm_include_dirs,
14 'Mblib' => \my $blib,
15
16 # spvm,spvmcc common
17 'B|build-dir=s' => \my $build_dir,
18 'w' => \my $warning,
19 'f|force' => \my $force,
20
21 # spvm only
22 'no-quiet' => \my $no_quiet,
23 'e=s' => \my $source,
24 'c' => \my $syntax_ok,
25 'M=s' => \my @use_class_names,
26 'class' => \my $script_name_is_class_name
27 ;
28  
29 6 ▶if ($help) {
Branch: 2 branches
BranchTrueFalseTotal
if ($help) { } 0 6 6
elsif ($show_version) { } 0 6 6
30 0 print SPVM::Builder::Util::extract_usage;
31 0 exit 0;
32 }
33 elsif ($show_version) {
34 0 my $version_string = "spvm v$SPVM::VERSION";
35 0 print "$version_string\n";
36 0 exit 0;
37 }
38  
39 6 my $script_name = shift;
40  
41 6 ▶if (!defined $script_name && !defined $source && !defined $source) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $script_name or defined $source or defined $source) 0 6 6
Condition50%3/6
defined $script_name or defined $source or defined $source
l!l&&r!l&&!r
600
defined $script_name or defined $source
l!l&&r!l&&!r
420
MC/DC0%0/3
defined $script_name or defined $source or defined $source
defined $script_name defined $source defined $source
Truth table50%2/4
A or B or C
A= defined $script_nameB= defined $sourceC= defined $source
ABCresult
1XX1
01X1
0011
0000
42 0 die SPVM::Builder::Util::extract_usage;
43 }
44  
45 6 ▶if (defined $script_name && defined $source) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $script_name and defined $source) 0 6 6
Condition66%2/3
defined $script_name and defined $source
!ll&&!rl&&r
240
MC/DC0%0/2
defined $script_name and defined $source
defined $script_name defined $source
Truth table66%2/3
A and B
A= defined $script_nameB= defined $source
ABresult
0X0
100
111
46 0 die "[spvm command]Specifying both SCRIPT_NAME and -e option is not allowed.";
47 }
48  
49 6 ▶if (defined $source) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $source) { } 2 4 6
elsif (defined $script_name) { } 4 0 4
50 2 $script_name = "-e";
51 }
52 elsif (defined $script_name) {
53 4 ▶ if ($script_name_is_class_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script_name_is_class_name) 0 4 4
54 0 my $class_name = $script_name;
55 0 $script_name = SPVM::Builder::Util::search_spvm_file($class_name);
56 0 ▶ unless (defined $script_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $script_name) 0 0 0
57 0 die "Cannot find $class_name class in @INC";
58 }
59 }
60
61 4 eval { $source = SPVM::Builder::Util::slurp_binary($script_name); };
62 4 $source = "#file \"$script_name\"\x{A}$source";
63 }
64  
65 6 SPVM::Builder::Util::setup_spvm_command_environment($script_name, $source, $blib, \@spvm_include_dirs, $build_dir, undef, $no_quiet, $warning, $force);
66  
67 6 for my $use_class_name (@use_class_names) {
68 2 SPVM::Global::build_class($use_class_name, __FILE__, __LINE__);
69 }
70  
71 6 SPVM::Global::build_class('Native', __FILE__, __LINE__);
72 6 SPVM::Global::build_class('Native::MethodCall', __FILE__, __LINE__);
73  
74 6 my $anon_class_name = SPVM::Global::build_anon_class($source, __FILE__, __LINE__);
75  
76 5 SPVM::Native->check_bootstrap_method($anon_class_name);
77  
78 5 my $spvm_anon_class_name = "SPVM::$anon_class_name";
79  
80 5 ▶if ($syntax_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($syntax_ok) 0 5 5
81 0 print STDERR "syntax OK\n";
82 0 exit 0;
83 }
84  
85 5 $spvm_anon_class_name->main;
86  
87 =encoding utf8
88  
89 =head1 Name
90  
91 spvm - Executing SPVM programs
92  
93 =head1 Description
94  
95 The spvm command executes SPVM programs.
96  
97 =head1 Usage
98  
99 Usage: spvm [OPTIONS] SCRIPT_NAME
100
101 spvm myapp.spvm
102
103 Options:
104 -h, --help Shows this message
105 -v, --version Shows the version
106 -I DIRECTORY Adds a include directory
107 -Mblib Same as "-Mblib" in perl
108
109 -B, --build-dir DIRECTORY Build diretory
110 -w Enables warning flag
111 -f|--force Compilations and links are forced
112
113 --no-quiet Shows diagnostic messages.
114 -e SOURCE Executes a program source code in main method.
115 -c Check syntx only
116 -M CLASS_NAME Loads the SPVM class
117 --class Interprets SCRIPT_NAME as a class name and searches for it
118  
119 =head1 Details
120  
121 spvm [OPTIONS] SCRIPT_NAME
122  
123 The C<spvm> command executes a SPVM program.
124  
125 I<OPTIONS> are L<options|/"Options">.
126  
127 I<SCRIPT_NAME> is a script path that contains an SPVM script.
128
129 # myapp.spvm
130 use Fn;
131 my $var = 1;
132 say $var;
133  
134 Anon class that contains a L<bootstrap method|SPVM::Document::Language::Class/"Bootstrap Method"> is allowed as an SPVM script.
135  
136 # myapp.spvm
137 class {
138
139 version "1.001";
140
141 our $FOO : int;
142
143 use Fn;
144
145 static method main : void () {
146 my $var = 1;
147 say $var;
148 }
149 }
150  
151 The base name of I<SCRIPT_NAME> must be a L</"Script Base Name">. Otherwise an exception is thrown.
152  
153 See L<Class Search Directories|SPVM::Document::Language::Class/"Class Search Directories"> about default class search directories.
154  
155 See L<SPVM::Document::EnvironmentVariables> about available environment variables.
156  
157 =head2 Script Base Name
158  
159 A script base name ends with C<.spvm>.
160  
161 A script base name without C<.spvm> consists of L<word characters|SPVM::Document::Language::Tokenization/"Word Characters"> and C<->.
162  
163 It dose not contains C<__>.
164  
165 It dose not begin with C<0-9>.
166  
167 It dose not begin with C<->.
168  
169 It dose not end with C<->.
170  
171 It dose not contains C<-->.
172  
173 Examples:
174
175 # Script Base Names
176 foo.spvm
177 foo_bar2.spvm
178 myapp-foo.spvm
179
180 # Invalid Script Base Names
181 2foo.spvm
182 foo__bar.spvm
183 -myapp.spvm
184 myapp-.spvm
185 myapp--foo.spvm
186  
187 =head1 Options
188  
189 =head2 --help
190  
191 Outputs how to use the C<spvm> command to standard output.
192  
193 =head2 -h
194  
195 -h
196  
197 Same as L</"--help">.
198  
199 =head2 --version
200  
201 Outputs the version of the C<spvm> command to standard output. This version is the same as the version of L<SPVM>.
202  
203 =head2 -v
204  
205 -v
206  
207 Same as L</"--version">.
208  
209 =head2 -I
210  
211 -I DIRECTORY
212  
213 Prepends I<DIRECTORY> to L<class search directories|SPVM::Document::Language::Class/"Class Search Directories">
214  
215 This option can be specified multiple times.
216  
217 -I dir1 -I dir2
218  
219 In this case, class search directories becomes the following.
220  
221 [dir1, dir2, default_dirs]
222  
223 =head2 -Mblib
224  
225 -Mblib
226  
227 Uses Perl's L<blib> module.
228  
229 This is useful for testing a native module before it is installed.
230  
231 When this option is specified, C<blib/lib> and C<blib/arch> are prepended to C<@INC> and the library search paths.
232  
233 =head2 --build-dir
234  
235 --build-dir DIRECTORY
236  
237 Sets L<SPVM_BUILD_DIR|SPVM::Document::EnvironmentVariables/"SPVM_BUILD_DIR"> environment variable to I<DIRECTORY>.
238  
239 =head2 -B
240  
241 -B DIRECTORY
242  
243 Same as L</"--build-dir">.
244  
245 =head2 -w
246  
247 -w
248  
249 Enables warning flag.
250  
251 Implementation:
252  
253 Sets L<CommandInfo#WARNING|SPVM::CommandInfo> class variable to 1.
254  
255 =head2 -f
256  
257 -f
258  
259 Compilations and links are forced.
260  
261 =head2 --force
262  
263 Same as L</"-f">.
264  
265 =head2 --no-quiet
266  
267 Shows diagnostic messages.
268  
269 =head2 -e
270  
271 -e SOURCE
272  
273 Executes a source code I<SOURCE> in C<main> method.
274  
275 Examples:
276  
277 spvm -e 'say "Hello World!";';
278
279 =head2 -c
280  
281 -c
282  
283 Checks syntax only.
284  
285 =head2 -M
286  
287 -M CLASS_NAME
288  
289 Loads the SPVM class I<CLASS_NAME>.
290  
291 This is useful for pre-loading classes or ensuring that a class is compiled.
292  
293 This option can be specified multiple times.
294  
295 spvm -MFoo -MBar myapp.spvm
296  
297 Implementation:
298  
299 Calls L</"build_class"> method for I<CLASS_NAME>.
300  
301 =head2 --class
302  
303 --class
304  
305 Interprets I<SCRIPT_NAME> as a class name and searches for it in the class search paths.
306  
307 This allows you to specify a class name directly instead of a file path.
308  
309 Example:
310  
311 spvm --class Foo::Bar
312  
313 =head1 lib Directive
314  
315 If the source code specified by I<SCRIPT_NAME>, or C<-e> option contains lib directives, The directories specified by lib directive is prepeneded to L<class search directories|SPVM::Document::Language::Class/"Class Search Directories">.
316
317 #lib "$FindBin::Bin/lib"
318
319 This directories specified by lib directive is placed after the directories specified by L</"-I"> option.
320  
321 =head1 Copyright & License
322  
323 Copyright 2023 Yuki Kimoto. All Rights Reserved.
324  
325 MIT License.
« SPVM.xs ↑ Summary blib/script/spvmcc »