blib/lib/SPVM/Dist.pm

filter: Statementstmt 93.1% 391 / 420 Branchbran 80.1% 109 / 136 Conditioncond 80.0% 12 / 15 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 97.9% 47 / 48 Podpod 0.0% 0 / 36 totaltotal 84.7% 563 / 664 CC 74 SCAR 16.1
CC
74
Cov
90%
generate_perl_class_file
12.0
generate_dist
10.0
new
8.3
CRAP 5.0
« blib/lib/SPVM/Builder/Exe.pm ↑ Summary blib/lib/SPVM/Builder/Native/Method.pm »
1 package SPVM::Dist;
2  
3 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 37 ▶use File::Copy 'copy', 'move';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 37 ▶use File::Path 'mkpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 37 ▶use File::Find 'find';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 37 ▶use File::Basename 'dirname', 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 37 ▶use SPVM::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 37 ▶use SPVM::Builder::Config::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 37 ▶use Getopt::Long 'GetOptions';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 37 ▶use Time::Piece();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Field metods
17 395 ▶sub force {
Subroutine force: called CC=2 SCAR=8.4
Pod undocumented
18 395 my $self = shift;
19 395 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 395 395
20 0 $self->{force} = $_[0];
21 0 return $self;
22 }
23 else {
24 395 return $self->{force};
25 }
26 }
27  
28 380 ▶sub class_name {
Subroutine class_name: called CC=2 SCAR=8.4
Pod undocumented
29 380 my $self = shift;
30 380 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 380 380
31 0 $self->{class_name} = $_[0];
32 0 return $self;
33 }
34 else {
35 380 return $self->{class_name};
36 }
37 }
38  
39 502 ▶sub output_dir {
Subroutine output_dir: called CC=2 SCAR=6.9
Pod undocumented
40 502 my $self = shift;
41 502 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 35 467 502
42 35 $self->{output_dir} = $_[0];
43 35 return $self;
44 }
45 else {
46 467 return $self->{output_dir};
47 }
48 }
49  
50 133 ▶sub native {
Subroutine native: called CC=2 SCAR=6.9
Pod undocumented
51 133 my $self = shift;
52 133 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 131 133
53 2 $self->{native} = $_[0];
54 2 return $self;
55 }
56 else {
57 131 return $self->{native};
58 }
59 }
60  
61 63 ▶sub precompile {
Subroutine precompile: called CC=2 SCAR=8.4
Pod undocumented
62 63 my $self = shift;
63 63 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 63 63
64 0 $self->{precompile} = $_[0];
65 0 return $self;
66 }
67 else {
68 63 return $self->{precompile};
69 }
70 }
71  
72 169 ▶sub resource {
Subroutine resource: called CC=2 SCAR=8.4
Pod undocumented
73 169 my $self = shift;
74 169 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 169 169
75 0 $self->{resource} = $_[0];
76 0 return $self;
77 }
78 else {
79 169 return $self->{resource};
80 }
81 }
82  
83 97 ▶sub interface {
Subroutine interface: called CC=2 SCAR=8.4
Pod undocumented
84 97 my $self = shift;
85 97 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 97 97
86 0 $self->{interface} = $_[0];
87 0 return $self;
88 }
89 else {
90 97 return $self->{interface};
91 }
92 }
93  
94 302 ▶sub only_lib_files {
Subroutine only_lib_files: called CC=2 SCAR=8.4
Pod undocumented
95 302 my $self = shift;
96 302 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 302 302
97 0 $self->{only_lib_files} = $_[0];
98 0 return $self;
99 }
100 else {
101 302 return $self->{only_lib_files};
102 }
103 }
104  
105 33 ▶sub no_pm_file {
Subroutine no_pm_file: called CC=2 SCAR=8.4
Pod undocumented
106 33 my $self = shift;
107 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 33 33
108 0 $self->{no_pm_file} = $_[0];
109 0 return $self;
110 }
111 else {
112 33 return $self->{no_pm_file};
113 }
114 }
115  
116 33 ▶sub lib_dir {
Subroutine lib_dir: called CC=2 SCAR=8.4
Pod undocumented
117 33 my $self = shift;
118 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 33 33
119 0 $self->{lib_dir} = $_[0];
120 0 return $self;
121 }
122 else {
123 33 return $self->{lib_dir};
124 }
125 }
126  
127 147 ▶sub user_name {
Subroutine user_name: called CC=2 SCAR=8.4
Pod undocumented
128 147 my $self = shift;
129 147 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 147 147
130 0 $self->{user_name} = $_[0];
131 0 return $self;
132 }
133 else {
134 147 return $self->{user_name};
135 }
136 }
137  
138 61 ▶sub user_email {
Subroutine user_email: called CC=2 SCAR=8.4
Pod undocumented
139 61 my $self = shift;
140 61 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 61 61
141 0 $self->{user_email} = $_[0];
142 0 return $self;
143 }
144 else {
145 61 return $self->{user_email};
146 }
147 }
148  
149 0 ▶sub version_from {
Subroutine version_from: not called CC=2 SCAR=17.9
Pod undocumented
150 0 my $self = shift;
151 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
152 0 $self->{version_from} = $_[0];
153 0 return $self;
154 }
155 else {
156 0 return $self->{version_from};
157 }
158 }
159  
160 # Class methods
161 35 ▶sub new {
Subroutine new: called CC=8 SCAR=21.1
Pod undocumented
162 35 my $class = shift;
163
164 35 my $self = {@_};
165
166 35 bless $self, $class;
167  
168 35 my $class_name = $self->class_name;
169 35 ▶ unless (defined $self->class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->class_name) 0 35 35
170 0 confess("A class name must be specified");
171 }
172
173 35 ▶ if (defined $self->output_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->output_dir) { } 4 31 35
174 # Remove tailing / or \
175 4 my $output_dir = $self->output_dir;
176 4 $output_dir =~ s|[/\\]$||;
177 4 $self->output_dir($output_dir);
178 }
179 else {
180 31 my $default_output_dir = "SPVM::$class_name";
181 31 $default_output_dir =~ s/::/-/g;
182 31 $self->output_dir($default_output_dir);
183 }
184
185 35 my $native = $self->native;
186 35 ▶ if (defined $native && !($native eq 'c' || $native eq 'c++')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native and not $native eq "c" || $native eq "c++") 0 35 35
Condition66%4/6
defined $native and not $native eq "c" || $native eq "c++"
!ll&&!rl&&r
23120
$native eq 'c' || $native eq 'c++'
l!l&&r!l&&!r
840
MC/DC0%0/3
defined $native and not $native eq "c" || $native eq "c++"
defined $native $native eq 'c' $native eq 'c++'
Truth table75%3/4
A and not(B || C)
A= defined $nativeB= $native eq 'c'C= $native eq 'c++'
ABCresult
0XX0
11X0
1010
1001
187 0 confess("Can't support native \"$native\"");
188 }
189
190 35 my $resource = $self->resource;
191 35 ▶ if ($resource && !defined $native) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource and not defined $native) 2 33 35
Condition100%3/3
$resource and not defined $native
!ll&&!rl&&r
3032
MC/DC100%2/2
$resource and not defined $native
$resource not defined $native
Truth table100%3/3
A and not(B)
A= $resourceB= not defined $native
ABresult
0X0
100
111
192 2 $self->native('c');
193 }
194
195 35 return $self;
196 }
197  
198 # Instance methods
199 395 ▶sub create_path {
Subroutine create_path: called CC=2 SCAR=7.1
Pod undocumented
200 395 my ($self, $file_base_name) = @_;
201
202 395 my $output_dir = $self->output_dir;
203
204 395 my $path;
205 395 ▶ if (defined $output_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_dir) { } 395 0 395
206 395 $path = "$output_dir/$file_base_name";
207 }
208 else {
209 0 $path = $file_base_name;
210 }
211
212 395 return $path;
213 }
214  
215 205 ▶sub create_lib_rel_file {
Subroutine create_lib_rel_file: called CC=2 SCAR=6.9
Pod undocumented
216 205 my ($self, $file_base_name) = @_;
217
218 205 my $lib_rel_file;
219
220 205 my $only_lib_files = $self->only_lib_files;
221 205 ▶ if ($only_lib_files) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_lib_files) { } 13 192 205
222 13 $lib_rel_file = $file_base_name;
223 }
224 else {
225 192 $lib_rel_file = "lib/$file_base_name";
226 }
227
228 205 return $lib_rel_file;
229 }
230  
231 395 ▶sub generate_file {
Subroutine generate_file: called CC=3 SCAR=11.0
Pod undocumented
232 395 my ($self, $rel_file, $content) = @_;
233
234 395 my $file = $self->create_path($rel_file);
235 395 my $dir = dirname $file;
236
237 395 $self->generate_dir($dir);
238
239 395 my $force = $self->force;
240 395 ▶ if ($force || !-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force or not -f $file) { } 384 11 395
Condition100%3/3
$force or not -f $file
l!l&&r!l&&!r
2236211
MC/DC100%2/2
$force or not -f $file
$force not -f $file
Truth table100%3/3
A or not(B)
A= $forceB= not -f $file
ABresult
1X1
011
000
241 384 print " [write]$file\n";
242 384 SPVM::Builder::Util::spurt_binary($file, $content);
243 }
244 else {
245 11 print " [exists]$file\n";
246 }
247 }
248  
249 428 ▶sub generate_dir {
Subroutine generate_dir: called CC=2 SCAR=6.9
Pod undocumented
250 428 my ($self, $rel_dir) = @_;
251
252 428 my @created = mkpath $rel_dir;
253 428 ▶ if (@created) {
Branch: 1 branch
BranchTrueFalseTotal
if (@created) 142 286 428
254 142 print " [mkdir]$rel_dir\n";
255 }
256 }
257  
258 33 ▶sub generate_spvm_class_file {
Subroutine generate_spvm_class_file: called CC=6 SCAR=17.9
Pod undocumented
259 33 my ($self) = @_;
260
261 33 my $class_name = $self->class_name;
262
263 # User name
264 33 my $user_name = $self->user_name;
265 33 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 32 1 33
266 32 $user_name = '[--user-name]'
267 }
268
269 # Year
270 33 my $year = $self->_year;
271  
272 33 my $interface = $self->interface;
273
274 33 my $attributes = "";
275 33 ▶ if ($interface) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interface) 1 32 33
276 1 $attributes = ": interface_t ";
277 }
278  
279 33 my $version_decl = 'version "0.001";';
280
281 33 my $only_lib_files = $self->only_lib_files;
282 33 ▶ if ($only_lib_files) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_lib_files) 3 30 33
283 3 $version_decl = '';
284 }
285
286 33 my $version_from = $self->{version_from};
287 33 my $version_from_decl = '';
288 33 ▶ if (length $version_from) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $version_from) 1 32 33
289 1 $version_from_decl = "version_from $version_from;";
290 }
291
292 33 ▶ my $precompile_attribute_part = $self->precompile ? 'precompile ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->precompile ? : 4 29 33
293
294 33 my $spvm_class_content = <<"EOS";
295 # Copyright (c) $year $user_name
296 # MIT License
297  
298 class $class_name ${attributes}{
299 $version_decl$version_from_decl
300
301 ${precompile_attribute_part}static method my_method : void () {
302
303 }
304 }
305 EOS
306
307 # Generate file
308 33 my $spvm_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'spvm');
309 33 my $lib_dir = $self->lib_dir;
310 33 $spvm_class_rel_file = $self->create_lib_rel_file($spvm_class_rel_file);
311 33 $self->generate_file($spvm_class_rel_file, $spvm_class_content);
312 }
313  
314 31 ▶sub generate_perl_class_file {
Subroutine generate_perl_class_file: called CC=12 SCAR=24.9
Pod undocumented
315 31 my ($self) = @_;
316
317 31 my $class_name = $self->class_name;
318
319 # Year
320 31 my $year = $self->_year;
321
322 # User name
323 31 my $user_name = $self->user_name;
324 31 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 30 1 31
325 30 $user_name = '[--user-name]'
326 }
327
328 # User email
329 31 my $user_email = $self->user_email;
330 31 ▶ unless (defined $user_email) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_email) 30 1 31
331 30 $user_email = '[--user-email]'
332 }
333  
334 31 my $interface = $self->interface;
335 31 my $resource = $self->resource;
336
337 # Description
338 31 my $description;
339 my $main_doc;
340 31 ▶ if ($interface) {
Branch: 2 branches
BranchTrueFalseTotal
if ($interface) { } 1 30 31
elsif ($resource) { } 5 25 30
341 1 $description = "$class_name interface in L<SPVM> has interface methods to do someting.";
342 1 $main_doc = <<"EOS";
343 =head1 Usage
344  
345 interface $class_name;
346  
347 =head1 Details
348  
349  
350  
351 =head1 Interface Methods
352  
353  
354  
355 EOS
356 }
357 elsif ($resource) {
358 5 $description = "$class_name class in L<SPVM> is a L<resource|SPVM::Document::Resource> class for something.";
359
360 5 my $native = $self->native;
361 5 my $new_method;
362 5 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 3 2 5
elsif ($native eq 'c++') { } 2 0 2
363 3 $new_method = 'new_c99';
364 }
365 elsif ($native eq 'c++') {
366 2 $new_method = 'new_cpp';
367 }
368
369 5 my $native_module_ext;
370 5 ▶ if (defined $native) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native) 5 0 5
371 5 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 3 2 5
elsif ($native eq 'c++') { } 2 0 2
372 3 $native_module_ext = 'c';
373 }
374 elsif ($native eq 'c++') {
375 2 $native_module_ext = 'cpp';
376 }
377 }
378
379 # extern C for C++
380 5 my $extern_c_start;
381 my $extern_c_end;
382 5 ▶ if ($native eq 'c++') {
Branch: 1 branch
BranchTrueFalseTotal
if ($native eq 'c++') { } 2 3 5
383 2 $extern_c_start = qq(extern "C" {);
384 2 $extern_c_end = "}";
385 }
386 else {
387 3 $extern_c_start = '';
388 3 $extern_c_end = '';
389 }
390
391 5 my $config_ext = SPVM::Builder::Config::Util::get_config_ext();
392
393 5 $main_doc = <<"EOS";
394 =head1 Usage
395  
396 MyClass.$config_ext:
397
398 my \$config = SPVM::Builder::Config->$new_method;
399
400 \$config->use_resource('$class_name');
401
402 \$config;
403  
404 MyClass.$native_module_ext:
405  
406 #include "spvm_native.h"
407 #include "foo.h"
408
409 $extern_c_start
410
411 int32_t SPVM__MyClass__test(SPVM_ENV* env, SPVM_VALUE* stack) {
412
413 // Use functions in foo.h
414
415 return 0;
416 }
417
418 $extern_c_end
419
420 =head1 Details
421  
422  
423  
424 =head1 Original Product
425  
426  
427  
428 =head1 Original Product Version
429  
430  
431  
432 =head1 Language
433  
434  
435  
436 =head1 Language Standard
437  
438  
439  
440 =head1 Required Libraries
441  
442  
443  
444 =head1 Required Linker Flags
445  
446  
447  
448 =head1 Required Resources
449  
450  
451  
452 =head1 Header Files
453  
454  
455  
456 =head1 Source Files
457  
458  
459  
460 =head1 Compiler Flags
461  
462  
463  
464 =head1 How to Create Resource
465  
466  
467  
468 =head2 Donwload
469  
470  
471  
472 =head2 Extracting Source Files
473  
474  
475  
476 =head2 Extracting Header Files
477  
478  
479  
480 EOS
481 }
482 else {
483 25 $description = "$class_name class in L<SPVM> has methods to do someting.";
484 25 $main_doc = <<"EOS";
485 =head1 Usage
486  
487 use $class_name;
488  
489 =head1 Details
490  
491  
492  
493 =head1 Super Class
494  
495  
496  
497 =head1 Interfaces
498  
499  
500  
501 =head1 Enumerations
502  
503  
504  
505 =head1 Fields
506  
507  
508  
509 =head1 Class Methods
510  
511  
512  
513 =head1 Instance Methods
514  
515  
516  
517 =head1 Well Known Child Classes
518  
519  
520  
521 =head1 See Also
522  
523  
524  
525 EOS
526 }
527
528 31 my $version_decl = 'our $VERSION = "0.001";';
529
530 31 my $only_lib_files = $self->only_lib_files;
531 31 ▶ if ($only_lib_files) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_lib_files) 2 29 31
532 2 $version_decl = '';
533 }
534
535 # Content
536 31 my $perl_class_content = "";
537 31 $perl_class_content = <<"EOS";
538 package SPVM::$class_name;
539  
540 $version_decl
541  
542 1;
543  
544 =encoding utf8
545  
546 =head1 Name
547  
548 SPVM::$class_name - Short Description
549  
550 =head1 Description
551  
552 $description
553  
554 $main_doc
555 =head1 Repository
556  
557  
558  
559 =head1 Author
560  
561 $user_name C<$user_email>
562  
563 =head1 Copyright & License
564  
565 Copyright (c) $year $user_name
566  
567 MIT License
568  
569 EOS
570  
571 # Generate file
572 31 my $perl_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'pm');
573 31 $perl_class_rel_file = $self->create_lib_rel_file($perl_class_rel_file);
574 31 $self->generate_file($perl_class_rel_file, $perl_class_content);
575 }
576  
577 14 ▶sub generate_native_config_file {
Subroutine generate_native_config_file: called CC=5 SCAR=16.1
Pod undocumented
578 14 my ($self) = @_;
579
580 14 my $class_name = $self->class_name;
581
582 # C or C++
583 14 my $native = $self->native;
584 14 my $new_method;
585 14 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 10 4 14
elsif ($native eq 'c++') { } 4 0 4
586 10 $new_method = 'new_c99';
587 }
588 elsif ($native eq 'c++') {
589 4 $new_method = 'new_cpp';
590 }
591
592 # User name
593 14 my $user_name = $self->user_name;
594 14 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 14 0 14
595 14 $user_name = '[--user-name]'
596 }
597
598 # Year
599 14 my $year = $self->_year;
600
601 14 my $is_resource = $self->{resource};
602 14 my $is_resource_code = '';
603 14 ▶ if ($is_resource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_resource) 5 9 14
604 5 $is_resource_code = '$config->is_resource(1);';
605 }
606
607 # Content
608 14 my $native_config_content = <<"EOS";
609 # Copyright (c) $year $user_name
610 # MIT License
611  
612 my \$config = SPVM::Builder::Config->$new_method;
613  
614 $is_resource_code
615  
616 \$config;
617 EOS
618  
619 # Generate file
620 14 my $config_ext = SPVM::Builder::Config::Util::get_config_ext();
621 14 my $native_config_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, $config_ext);
622 14 $native_config_rel_file = $self->create_lib_rel_file($native_config_rel_file);
623 14 $self->generate_file($native_config_rel_file, $native_config_content);
624 }
625  
626 9 ▶sub generate_native_class_file {
Subroutine generate_native_class_file: called CC=6 SCAR=17.9
Pod undocumented
627 9 my ($self) = @_;
628  
629 9 my $class_name = $self->class_name;
630
631 # extern C for C++
632 9 my $native = $self->native;
633 9 my $extern_c_start;
634 my $extern_c_end;
635 9 ▶ if ($native eq 'c++') {
Branch: 1 branch
BranchTrueFalseTotal
if ($native eq 'c++') { } 2 7 9
636 2 $extern_c_start = qq(extern "C" {);
637 2 $extern_c_end = "}";
638 }
639 else {
640 7 $extern_c_start = '';
641 7 $extern_c_end = '';
642 }
643  
644 # Generate file
645 9 my $native_module_ext;
646 9 ▶ if (defined $native) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native) 9 0 9
647 9 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 7 2 9
elsif ($native eq 'c++') { } 2 0 2
648 7 $native_module_ext = 'c';
649 }
650 elsif ($native eq 'c++') {
651 2 $native_module_ext = 'cpp';
652 }
653 }
654
655 # Content
656 9 my $native_class_name = $class_name;
657 9 $native_class_name =~ s/::/__/g;
658 9 my $native_class_file = $class_name;
659 9 $native_class_file =~ s/::/\//g;
660 9 $native_class_file .= ".$native_module_ext";
661  
662 # User name
663 9 my $user_name = $self->user_name;
664 9 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 9 0 9
665 9 $user_name = '[--user-name]'
666 }
667
668 # Year
669 9 my $year = $self->_year;
670
671 9 my $native_class_content = <<"EOS";
672 // Copyright (c) $year $user_name
673 // MIT License
674  
675 #include "spvm_native.h"
676  
677 $extern_c_start
678  
679 static const char* FILE_NAME = "$native_class_file";
680  
681 int32_t SPVM__${native_class_name}__foo(SPVM_ENV* env, SPVM_VALUE* stack) {
682
683 return 0;
684 }
685  
686 $extern_c_end
687 EOS
688
689 9 my $native_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, $native_module_ext);
690 9 $native_class_rel_file = $self->create_lib_rel_file($native_class_rel_file);
691 9 $self->generate_file($native_class_rel_file, $native_class_content);
692 }
693  
694 14 ▶sub generate_gitkeep_file_for_native_module_include_dir {
Subroutine generate_gitkeep_file_for_native_module_include_dir: called CC=1 SCAR=0.0
Pod undocumented
695 14 my ($self) = @_;
696  
697 14 my $class_name = $self->class_name;
698
699 # Generate file
700 14 my $gitkeep_rel_file_for_native_module_include_dir = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'native');
701 14 $gitkeep_rel_file_for_native_module_include_dir .= '/include/.gitkeep';
702 14 $gitkeep_rel_file_for_native_module_include_dir = $self->create_lib_rel_file($gitkeep_rel_file_for_native_module_include_dir);
703 14 $self->generate_file($gitkeep_rel_file_for_native_module_include_dir, '');
704 }
705  
706 14 ▶sub generate_gitkeep_file_for_native_module_src_dir {
Subroutine generate_gitkeep_file_for_native_module_src_dir: called CC=1 SCAR=0.0
Pod undocumented
707 14 my ($self) = @_;
708  
709 14 my $class_name = $self->class_name;
710
711 # Generate file
712 14 my $gitkeep_rel_file_for_native_module_include_dir = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'native');
713 14 $gitkeep_rel_file_for_native_module_include_dir .= '/src/.gitkeep';
714 14 $gitkeep_rel_file_for_native_module_include_dir = $self->create_lib_rel_file($gitkeep_rel_file_for_native_module_include_dir);
715 14 $self->generate_file($gitkeep_rel_file_for_native_module_include_dir, '');
716 }
717  
718 30 ▶sub generate_gitignore_file {
Subroutine generate_gitignore_file: called CC=1 SCAR=0.0
Pod undocumented
719 30 my ($self) = @_;
720
721 30 my $gitignore_content = <<'EOS';
722 # ===============================================================
723 # Common
724 # ===============================================================
725  
726 # Perl build
727 /blib/
728 /Makefile
729 *.old
730 *.bs
731 /MYMETA.yml
732 /MYMETA.json
733 /pm_to_blib
734 /_build/
735 /Build
736 /Build.bat
737 /Build.com
738  
739 # C/C++
740 *.o
741 *.a
742 *.out
743 /core
744 /core.*
745  
746 # Temp & archives
747 /SPVM-*
748 .spvm_build/
749 .tmp/
750 *.bak
751 *.BAK
752 *.tmp
753 *.swp
754 *~
755 *.log
756  
757 # Version control
758 .git/
759  
760 # ===============================================================
761 # OS specific
762 # ===============================================================
763  
764 # Windows
765 *.def
766 *.obj
767 *.exe
768 *.dll
769 *.lib
770 *.exp
771 *.pdb
772 *.ilk
773 *.manifest
774 Thumbs.db
775 desktop.ini
776 $RECYCLE.BIN/
777  
778 # macOS / iOS
779 *.dylib
780 .DS_Store
781 .AppleDouble
782 .LSOverride
783 ._*
784  
785 # Linux / Android / UNIX
786 *.so
787 .thumbnails/
788 .cache/
789 EOS
790
791 # Generate file
792 30 my $gitignore_rel_file = '.gitignore';
793 30 $self->generate_file($gitignore_rel_file, $gitignore_content);
794 }
795  
796 30 ▶sub generate_gitattributes_file {
Subroutine generate_gitattributes_file: called CC=1 SCAR=0.0
Pod undocumented
797 30 my ($self) = @_;
798
799 30 my $gitattributes_content = <<'EOS';
800 *.spvm text eol=lf
801 EOS
802
803 # Generate file
804 30 my $gitattributes_rel_file = '.gitattributes';
805 30 $self->generate_file($gitattributes_rel_file, $gitattributes_content);
806 }
807  
808 30 ▶sub generate_manifest_skip_file {
Subroutine generate_manifest_skip_file: called CC=1 SCAR=0.0
Pod undocumented
809 30 my ($self) = @_;
810
811 # Content
812 30 my $manifest_skip_content = <<'EOS';
813 # ===============================================================
814 # Common
815 # ===============================================================
816  
817 # Perl build
818 ^blib/
819 ^Makefile$
820 \.old$
821 \.bs$
822 ^MYMETA\.yml$
823 ^MYMETA\.json$
824 ^pm_to_blib$
825 ^_build/
826 ^Build$
827 ^Build\.bat$
828 ^Build\.com$
829  
830 # C/C++
831 \.o$
832 \.a$
833 \.out$
834 ^core\.
835 ^core$
836  
837 # Temp & archives
838 ^SPVM-
839 \.spvm_build/
840 (^|/)\.tmp/
841 \.bak$
842 \.BAK$
843 \.tmp$
844 \.swp$
845 ~$
846 \.log$
847  
848 # Version control
849 (^|/)\.git/
850 (^|/)\.github/
851  
852 # ===============================================================
853 # OS specific
854 # ===============================================================
855  
856 # Windows
857 \.def$
858 \.obj$
859 \.exe$
860 \.dll$
861 \.lib$
862 \.exp$
863 \.pdb$
864 \.ilk$
865 \.manifest$
866 ^Thumbs\.db$
867 ^desktop\.ini$
868 ^\$RECYCLE\.BIN/
869  
870 # macOS / iOS
871 \.dylib$
872 (^|/)\.DS_Store$
873 ^\.AppleDouble$
874 ^\.LSOverride$
875 ^\._
876  
877 # Linux / Android / UNIX
878 \.so$
879 ^\.thumbnails/
880 ^\.cache/
881 EOS
882  
883 # Generate file
884 30 my $manifest_skip_rel_file = 'MANIFEST.SKIP';
885 30 $self->generate_file($manifest_skip_rel_file, $manifest_skip_content);
886 }
887  
888 30 ▶sub generate_changes_file {
Subroutine generate_changes_file: called CC=1 SCAR=0.0
Pod undocumented
889 30 my ($self) = @_;
890  
891 # Year
892 30 my $today_tp = Time::Piece::localtime;
893 30 my $today = $today_tp->strftime('%Y-%m-%d');
894
895 # Content
896 30 my $changes_content = <<"EOS";
897 0.001 $today
898 [Changes]
899 * First release.
900
901 EOS
902  
903 # Generate file
904 30 my $changes_rel_file = 'Changes';
905 30 $self->generate_file($changes_rel_file, $changes_content);
906 }
907  
908  
909 30 ▶sub generate_readme_markdown_file {
Subroutine generate_readme_markdown_file: called CC=1 SCAR=0.0
Pod undocumented
910 30 my ($self) = @_;
911
912 30 my $class_name = $self->class_name;
913
914 # Content
915 30 my $readme_markdown_content = <<"EOS";
916 # SPVM::$class_name
917  
918 ## Document
919  
920 <a href="https://metacpan.org/pod/SPVM::$class_name">SPVM::$class_name - CPAN</a>
921  
922 ## See Also
923  
924 <a href="https://github.com/yuki-kimoto/SPVM">SPVM - Github</a>
925  
926 EOS
927
928 # Generate file
929 30 my $readme_markdown_rel_file = 'README.md';
930 30 $self->generate_file($readme_markdown_rel_file, $readme_markdown_content);
931 }
932  
933 30 ▶sub generate_makefile_pl_file {
Subroutine generate_makefile_pl_file: called CC=7 SCAR=19.5
Pod undocumented
934 30 my ($self) = @_;
935
936 30 my $class_name = $self->class_name;
937
938 # Resource
939 30 my $resource = $self->resource;
940
941 # Make rule
942 30 ▶ my $native_class_literal
Branch: 2 branches
BranchTrueFalseTotal
$resource ? : 5 25 30
$self->native ? : 7 18 25
943 = $resource ? "'TestCase::$class_name'"
944 : $self->native ? "'$class_name'" : '';
945 30 ▶ my $precompile_class_literal = $self->precompile ? "'$class_name'" : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->precompile ? : 4 26 30
946 30 ▶ my $make_rule_parallel
Branch: 1 branch
BranchTrueFalseTotal
$resource ? : 5 25 30
947 = $resource ? "\$make_rule .= SPVM::Builder::Util::API::create_make_rule_parallel({%\$options, output_dir => \$test_class_search_dir, class_search_dir => [\$test_class_search_dir]});"
948 : "\$make_rule .= SPVM::Builder::Util::API::create_make_rule_parallel(\$options);";
949 30 my $perl_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'pm');
950 30 $perl_class_rel_file = $self->create_lib_rel_file($perl_class_rel_file);
951
952 30 my $spvm_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'spvm');
953 30 $spvm_class_rel_file = $self->create_lib_rel_file($spvm_class_rel_file);
954
955 # User name
956 30 my $user_name = $self->user_name;
957 30 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 29 1 30
958 29 $user_name = '[--user-name]'
959 }
960
961 # User email
962 30 my $user_email = $self->user_email;
963 30 ▶ unless (defined $user_email) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_email) 29 1 30
964 29 $user_email = '[--user-email]'
965 }
966
967 30 my $config_ext = SPVM::Builder::Config::Util::get_config_ext();
968
969 # "Makefile.PL" content
970 30 my $makefile_pl_content = <<"END_OF_STRING";
971 use 5.020;
972 use ExtUtils::MakeMaker;
973 use strict;
974 use warnings;
975 use Config;
976 use Getopt::Long 'GetOptions';
977 use File::Path 'mkpath', 'rmtree';
978  
979 GetOptions(
980 'meta' => \\my \$meta,
981 'no-build-spvm-modules' => \\my \$no_build_spvm_modules,
982 'cc=s' => \\my \$cc,
983 'ccflag=s' => \\my \@ccflags,
984 'define=s' => \\my \@defines,
985 'include-dir=s' => \\my \@include_dirs,
986 'ld=s' => \\my \$ld,
987 'ldflag=s' => \\my \@ldflags,
988 'lib=s' => \\my \@libs,
989 'lib-dir=s' => \\my \@lib_dirs,
990 'debug' => \\my \$debug,
991 'build-type=s' => \\my \$build_type,
992 'asan-on-linux' => \\my \$asan_on_linux,
993 'msvc' => \\my \$msvc,
994 'parallel-make' => \\my \$parallel_make,
995 'parallel-test' => \\my \$parallel_test,
996 'jobs=i' => \\my \$jobs,
997 ) or die 'Invalid command line options are specified.';
998  
999 if (\$meta) {
1000 \$no_build_spvm_modules = 1;
1001 }
1002  
1003 my \$build_dir = '.spvm_build';
1004 mkpath \$build_dir;
1005  
1006 my \$config_global_file = '.spvm_build/global.$config_ext';
1007 generate_config_global_file(\$config_global_file, {
1008 cc => \$cc,
1009 ccflags => \\\@ccflags,
1010 defines => \\\@defines,
1011 include_dirs => \\\@include_dirs,
1012 ld => \$ld,
1013 ldflags => \\\@ldflags,
1014 libs => \\\@libs,
1015 lib_dirs => \\\@lib_dirs,
1016 debug => \$debug,
1017 build_type => \$build_type,
1018 asan_on_linux => \$asan_on_linux,
1019 msvc => \$msvc,
1020 });
1021  
1022 my \$asan_logs_dir = ".tmp/asan_logs";
1023 if (\$asan_on_linux) {
1024 rmtree \$asan_logs_dir;
1025 mkpath \$asan_logs_dir;
1026 }
1027  
1028 unless (\$meta) {
1029 require SPVM::Builder::Util::API;
1030 }
1031  
1032 my \$gnu_make;
1033 unless (\$meta) {
1034 \$gnu_make = SPVM::Builder::Util::API::search_gnu_make_command();
1035 }
1036  
1037 unless (\$meta) {
1038 unless (defined \$jobs) {
1039 my \$cpus = SPVM::Builder::Util::API::get_cpu_count();
1040 \$jobs = \$cpus + 2;
1041 }
1042  
1043 if (\$jobs > 16) {
1044 \$jobs = 16;
1045 }
1046 }
1047 \$jobs //= 1;
1048  
1049 my \@test_clean_files = map { "t/" . join('', map { '*/' } 1 .. \$_) . "*.\$Config{so}" } (1 .. 10);
1050 my \%configure_requires_and_prereq_pm = (
1051 'SPVM' => '$SPVM::VERSION',
1052 );
1053 WriteMakefile(
1054 NAME => 'SPVM::$class_name',
1055 VERSION_FROM => '$perl_class_rel_file',
1056 LICENSE => 'mit',
1057 (\$] >= 5.005 ?
1058 (ABSTRACT_FROM => '$perl_class_rel_file',
1059 AUTHOR => '$user_name<$user_email>') : ()),
1060 test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'},
1061 clean => {FILES => ['.spvm_build', \@test_clean_files]},
1062 META_MERGE => {
1063 'meta-spec' => {
1064 version => 2,
1065 # release_status => 'stable', # stable, testing, or unstable
1066 },
1067 resources => {
1068 repository => {
1069 type => 'git',
1070 url => '',
1071 web => '',
1072 },
1073 },
1074 no_index => {
1075 directory => [],
1076 }
1077 },
1078 MAKE => \$gnu_make,
1079 macro => {
1080 \$parallel_make ? (MAKEFLAGS => "-j\$jobs") : (),
1081 \$parallel_test ? ('override TEST_VERBOSE' => "scalar (eval chr(36) . q(ENV{HARNESS_OPTIONS}='j\$jobs'), 0)") : (),
1082 \$asan_on_linux ? ('override FULLPERL' => qq|LD_PRELOAD=\\\$\\\$(\$Config{cc} -print-file-name=libasan.so) ASAN_OPTIONS="log_path=\$asan_logs_dir/asan.log:exitcode=0" \$^X|) : (),
1083 },
1084 NORECURS => 1,
1085 CONFIGURE_REQUIRES => {
1086 \%configure_requires_and_prereq_pm,
1087 },
1088 PREREQ_PM => {
1089 \%configure_requires_and_prereq_pm,
1090 },
1091 );
1092  
1093 package MY {
1094
1095 sub postamble {
1096 my \$make_rule = '';
1097 unless (\$no_build_spvm_modules) {
1098 my \$options = {};
1099 \$options->{config_global_file} = \$config_global_file;
1100 \$options->{order_only_dependent_files} = ['pm_to_blib'];
1101
1102 \$options->{native_classes} = [
1103 $native_class_literal
1104 ];
1105
1106 \$options->{precompile_classes} = [
1107 $precompile_class_literal
1108 ];
1109
1110 my \$test_class_search_dir = 't/lib';
1111
1112 $make_rule_parallel
1113 }
1114 return \$make_rule;
1115 }
1116 }
1117  
1118 sub generate_config_global_file {
1119 my (\$config_global_file, \$options) = \@_;
1120
1121 my \$cc = \$options->{cc};
1122 my \$ccflags = \$options->{ccflags} // [];
1123 my \$defines = \$options->{defines} // [];
1124 my \$include_dirs = \$options->{include_dirs};
1125 my \$ld = \$options->{ld};
1126 my \$ldflags = \$options->{ldflags} // [];
1127 my \$libs = \$options->{libs};
1128 my \$lib_dirs = \$options->{lib_dirs};
1129 my \$build_type = \$options->{build_type};
1130 my \$debug = \$options->{debug};
1131 my \$asan_on_linux = \$options->{asan_on_linux};
1132 my \$msvc = \$options->{msvc};
1133
1134 if (\$debug) {
1135 \$build_type = 'Debug';
1136 }
1137
1138 if (\$asan_on_linux) {
1139 push \@\$ccflags, "-fsanitize=address", "-fno-omit-frame-pointer";
1140 push \@\$ldflags, "-fsanitize=address";
1141 }
1142
1143 my \$config_global_content = '';
1144
1145 \$config_global_content .= <<"EOS";
1146 my \\\$config_global = SPVM::Builder::Config::Global->new;
1147 EOS
1148
1149 if (\$msvc) {
1150 \$config_global_content .= <<"EOS";
1151 use SPVM::Builder::Config::Global::MSVC;
1152 \\\$config_global = SPVM::Builder::Config::Global::MSVC->new;
1153 EOS
1154 }
1155
1156 if (defined \$build_type) {
1157 \$config_global_content .= <<"EOS";
1158 \\\$config_global->build_type('\$build_type');
1159 EOS
1160 }
1161
1162 if (defined \$cc) {
1163 \$config_global_content .= <<"EOS";
1164 \\\$config_global->build_rule_any({'cc' => '\$cc'});
1165 EOS
1166 }
1167
1168 for my \$ccflag (\@\$ccflags) {
1169 \$config_global_content .= <<"EOS";
1170 \\\$config_global->build_rule_any({'+ccflags' => ['\$ccflag']});
1171 EOS
1172 }
1173
1174 for my \$define (\@\$defines) {
1175 \$config_global_content .= <<"EOS";
1176 \\\$config_global->build_rule_any({'+defines' => ['\$define']});
1177 EOS
1178 }
1179
1180 for my \$include_dir (\@\$include_dirs) {
1181 \$config_global_content .= <<"EOS";
1182 \\\$config_global->build_rule_any({'+include_dirs' => ['\$include_dir']});
1183 EOS
1184 }
1185
1186 if (defined \$ld) {
1187 \$config_global_content .= <<"EOS";
1188 \\\$config_global->build_rule_any({'ld' => '\$ld'});
1189 EOS
1190 }
1191
1192 for my \$ldflag (\@\$ldflags) {
1193 \$config_global_content .= <<"EOS";
1194 \\\$config_global->build_rule_any({'+ldflags' => ['\$ldflag']});
1195 EOS
1196 }
1197
1198 for my \$lib (\@\$libs) {
1199 \$config_global_content .= <<"EOS";
1200 \\\$config_global->build_rule_any({'+libs' => ['\$lib']});
1201 EOS
1202 }
1203
1204 for my \$lib_dir (\@\$lib_dirs) {
1205 \$config_global_content .= <<"EOS";
1206 \\\$config_global->build_rule_any({'+lib_dirs' => ['\$lib_dir']});
1207 EOS
1208 }
1209
1210 \$config_global_content .= <<"EOS";
1211 \\\$config_global;
1212 EOS
1213
1214 open my \$fh, '>', \$config_global_file or die "Can't open file '\$config_global_file': \$!";
1215 print \$fh \$config_global_content;
1216 }
1217  
1218 1;
1219  
1220 =head1 Name
1221  
1222 SPVM::$class_name Makefile.PL
1223  
1224 =head1 Description
1225  
1226 Makefile.PL for L<SPVM::$class_name> build.
1227  
1228 =head1 Command Line Options
1229  
1230 See the following URL for the command line options:
1231  
1232 L<https://github.com/yuki-kimoto/SPVM/blob/master/Makefile.PL>
1233  
1234 =cut
1235 END_OF_STRING
1236  
1237 # Generate file
1238 30 my $makefile_pl_rel_file = 'Makefile.PL';
1239 30 $self->generate_file($makefile_pl_rel_file, $makefile_pl_content);
1240 }
1241  
1242 30 ▶sub generate_basic_test_file {
Subroutine generate_basic_test_file: called CC=1 SCAR=0.0
Pod undocumented
1243 30 my ($self) = @_;
1244
1245 30 my $class_name = $self->class_name;
1246
1247 30 my $spvm_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($class_name, 'spvm');
1248 30 $spvm_class_rel_file = $self->create_lib_rel_file($spvm_class_rel_file);
1249
1250 # Content
1251 30 my $basic_test_content = <<"EOS";
1252 use Test::More;
1253  
1254 use strict;
1255 use warnings;
1256 use FindBin;
1257 use lib "\$FindBin::Bin/lib";
1258  
1259 use SPVM 'TestCase::$class_name';
1260  
1261 use SPVM '$class_name';
1262 use SPVM::$class_name;
1263  
1264 my \$api = SPVM::api();
1265  
1266 my \$start_memory_blocks_count = \$api->get_memory_blocks_count;
1267  
1268 ok(SPVM::TestCase::$class_name->test);
1269  
1270 # Version check
1271 is(\$SPVM::${class_name}::VERSION, \$api->get_version_string("$class_name"));
1272  
1273 \$api->destroy_runtime_permanent_vars;
1274  
1275 my \$end_memory_blocks_count = \$api->get_memory_blocks_count;
1276 is(\$end_memory_blocks_count, \$start_memory_blocks_count);
1277  
1278 done_testing;
1279 EOS
1280
1281 # Generate file
1282 30 my $basic_test_rel_file = 't/basic.t';
1283 30 $self->generate_file($basic_test_rel_file, $basic_test_content);
1284 }
1285  
1286 30 ▶sub generate_license_file {
Subroutine generate_license_file: called CC=2 SCAR=6.9
Pod undocumented
1287 30 my ($self) = @_;
1288
1289 30 my $class_name = $self->class_name;
1290
1291 # User name
1292 30 my $user_name = $self->user_name;
1293 30 ▶ unless (defined $user_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_name) 29 1 30
1294 29 $user_name = '[--user-name]'
1295 }
1296
1297 # Year
1298 30 my $year = $self->_year;
1299
1300 # Content
1301 30 my $license_content = <<"EOS";
1302 MIT License
1303  
1304 Copyright (c) $year $user_name
1305  
1306 Permission is hereby granted, free of charge, to any person obtaining a copy
1307 of this software and associated documentation files (the "Software"), to deal
1308 in the Software without restriction, including without limitation the rights
1309 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1310 copies of the Software, and to permit persons to whom the Software is
1311 furnished to do so, subject to the following conditions:
1312  
1313 The above copyright notice and this permission notice shall be included in all
1314 copies or substantial portions of the Software.
1315  
1316 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1317 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1318 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1319 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1320 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1321 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1322 SOFTWARE.
1323 EOS
1324
1325 # Generate file
1326 30 my $license_rel_file = 'LICENSE';
1327 30 $self->generate_file($license_rel_file, $license_content);
1328 }
1329  
1330 30 ▶sub generate_basic_test_spvm_class_file {
Subroutine generate_basic_test_spvm_class_file: called CC=2 SCAR=6.9
Pod undocumented
1331 30 my ($self) = @_;
1332
1333 30 my $class_name = $self->class_name;
1334
1335 # Resource
1336 30 my $resource = $self->resource;
1337
1338 # Content
1339 30 my $basic_test_spvm_class_content;
1340
1341 30 ▶ if ($resource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource) { } 5 25 30
1342 5 $basic_test_spvm_class_content = <<"EOS";
1343 class TestCase::$class_name {
1344 use $class_name;
1345 native static method test : int ();
1346 }
1347 EOS
1348 }
1349 else {
1350 25 $basic_test_spvm_class_content = <<"EOS";
1351 class TestCase::$class_name {
1352 use $class_name;
1353 static method test : int () {
1354
1355 return 1;
1356 }
1357 }
1358 EOS
1359 }
1360
1361 # Generate file
1362 30 my $basic_test_spvm_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file("TestCase::$class_name", 'spvm');
1363 30 $basic_test_spvm_class_rel_file = "t/lib/$basic_test_spvm_class_rel_file";
1364 30 $self->generate_file($basic_test_spvm_class_rel_file, $basic_test_spvm_class_content);
1365 }
1366  
1367 5 ▶sub generate_basic_test_native_config_file {
Subroutine generate_basic_test_native_config_file: called CC=3 SCAR=11.0
Pod undocumented
1368 5 my ($self) = @_;
1369
1370 5 my $class_name = $self->class_name;
1371
1372 # Resource
1373 5 my $resource = $self->resource;
1374  
1375 # C or C++
1376 5 my $native = $self->native;
1377 5 my $new_method;
1378 5 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 3 2 5
elsif ($native eq 'c++') { } 2 0 2
1379 3 $new_method = 'new_c99';
1380 }
1381 elsif ($native eq 'c++') {
1382 2 $new_method = 'new_cpp';
1383 }
1384
1385 # Content
1386 5 my $basic_test_native_config_content = <<"EOS";
1387 my \$config = SPVM::Builder::Config->$new_method;
1388  
1389 \$config->use_resource('$class_name');
1390  
1391 \$config;
1392 EOS
1393
1394 # Generate file
1395 5 my $config_ext = SPVM::Builder::Config::Util::get_config_ext();
1396 5 my $basic_test_native_config_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file("TestCase::$class_name", $config_ext);
1397 5 $basic_test_native_config_rel_file = "t/lib/$basic_test_native_config_rel_file";
1398 5 $self->generate_file($basic_test_native_config_rel_file, $basic_test_native_config_content);
1399 }
1400  
1401 5 ▶sub generate_basic_test_native_class_file {
Subroutine generate_basic_test_native_class_file: called CC=5 SCAR=16.1
Pod undocumented
1402 5 my ($self) = @_;
1403
1404 5 my $class_name = $self->class_name;
1405
1406 # Resource
1407 5 my $resource = $self->resource;
1408  
1409 # extern C for C++
1410 5 my $native = $self->native;
1411 5 my $extern_c_start;
1412 my $extern_c_end;
1413 5 ▶ if ($native eq 'c++') {
Branch: 1 branch
BranchTrueFalseTotal
if ($native eq 'c++') { } 2 3 5
1414 2 $extern_c_start = qq(extern "C" {);
1415 2 $extern_c_end = "}";
1416 }
1417 else {
1418 3 $extern_c_start = '';
1419 3 $extern_c_end = '';
1420 }
1421
1422 # Content
1423 5 my $native_class_name = $class_name;
1424 5 $native_class_name =~ s/::/__/g;
1425 5 my $basic_test_native_class_content = <<"EOS";
1426 #include "spvm_native.h"
1427  
1428 $extern_c_start
1429  
1430 int32_t SPVM__TestCase__${native_class_name}__test(SPVM_ENV* env, SPVM_VALUE* stack) {
1431
1432 stack[0].ival = 1;
1433
1434 return 0;
1435 }
1436  
1437 $extern_c_end
1438 EOS
1439
1440 # Generate file
1441 5 my $native_module_ext;
1442 5 ▶ if (defined $native) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $native) 5 0 5
1443 5 ▶ if ($native eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if ($native eq 'c') { } 3 2 5
elsif ($native eq 'c++') { } 2 0 2
1444 3 $native_module_ext = 'c';
1445 }
1446 elsif ($native eq 'c++') {
1447 2 $native_module_ext = 'cpp';
1448 }
1449 }
1450 5 my $basic_test_native_class_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file("TestCase::$class_name", $native_module_ext);
1451 5 $basic_test_native_class_rel_file = "t/lib/$basic_test_native_class_rel_file";
1452 5 $self->generate_file($basic_test_native_class_rel_file, $basic_test_native_class_content);
1453 }
1454  
1455 35 ▶sub generate_dist {
Subroutine generate_dist: called CC=10 SCAR=23.0
Pod undocumented
1456 35 my ($self) = @_;
1457
1458 35 my $class_name = $self->class_name;
1459
1460 35 ▶ unless (length $class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $class_name) 1 34 35
1461 1 confess("A class name must be specified");
1462 }
1463
1464 34 ▶ if ($class_name =~ /-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name =~ /-/) 1 33 34
1465 1 confess("The class name \"$class_name\" cannnot contain \"-\"");
1466 }
1467
1468 33 my $native = $self->native;
1469 33 my $interface = $self->interface;
1470 33 my $resource = $self->resource;
1471
1472 33 ▶ if ($interface && $resource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interface and $resource) 0 33 33
Condition66%2/3
$interface and $resource
!ll&&!rl&&r
3210
MC/DC0%0/2
$interface and $resource
$interface $resource
Truth table66%2/3
A and B
A= $interfaceB= $resource
ABresult
0X0
100
111
1473 0 die "--interface option and --resource option cannot be specified at the same time"
1474 }
1475
1476 33 my $class_name_rel_file = $class_name;
1477 33 $class_name_rel_file =~ s|::|/|g;
1478
1479 # Generate output directory
1480 33 my $output_dir = $self->output_dir;
1481 33 $self->generate_dir($output_dir);
1482
1483 # Generate SPVM class file
1484 33 $self->generate_spvm_class_file;
1485
1486 # Generate Perl class file
1487 33 my $no_pm_file = $self->no_pm_file;
1488 33 ▶ unless ($no_pm_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_pm_file) 31 2 33
1489 31 $self->generate_perl_class_file;
1490 }
1491
1492 33 ▶ if ($native) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native) 14 19 33
1493 # Generate native config file
1494 14 $self->generate_native_config_file;
1495
1496 # Generate native class file
1497 14 ▶ unless ($resource) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resource) 9 5 14
1498 9 $self->generate_native_class_file;
1499 }
1500
1501 # Generate ".gitkeep" file for native class include directory
1502 14 $self->generate_gitkeep_file_for_native_module_include_dir;
1503
1504 # Generate ".gitkeep" file for native class src directory
1505 14 $self->generate_gitkeep_file_for_native_module_src_dir;
1506 }
1507
1508 33 my $only_lib_files = $self->only_lib_files;
1509 33 ▶ unless ($only_lib_files) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($only_lib_files) 30 3 33
1510
1511 # Generate .gitignore file
1512 30 $self->generate_gitignore_file;
1513
1514 # Generate .gitattributes file
1515 30 $self->generate_gitattributes_file;
1516
1517 # Generate MANIFEST.SKIP file
1518 30 $self->generate_manifest_skip_file;
1519
1520 # Generate Changes file
1521 30 $self->generate_changes_file;
1522
1523 # Generate README.md file
1524 30 $self->generate_readme_markdown_file;
1525
1526 # Generate Makefile.PL file
1527 30 $self->generate_makefile_pl_file;
1528
1529 # Generate basic test file
1530 30 $self->generate_basic_test_file;
1531  
1532 # Generate basic test SPVM class file
1533 30 $self->generate_basic_test_spvm_class_file;
1534  
1535 # Generate license file
1536 30 $self->generate_license_file;
1537
1538 30 ▶ if ($resource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource) 5 25 30
1539 # Generate basic test native class file
1540 5 $self->generate_basic_test_native_class_file;
1541  
1542 # Generate basic test native config file
1543 5 $self->generate_basic_test_native_config_file;
1544 }
1545 }
1546 }
1547  
1548 117 ▶sub _year {
Subroutine _year: called CC=1 SCAR=0.0
1549 117 my ($self) = @_;
1550
1551 # Year
1552 117 my $today_tp = Time::Piece::localtime;
1553 117 my $year = $today_tp->year;
1554
1555 117 return $year;
1556 }
1557  
1558 37 1;
1559  
1560 =head1 Name
1561  
1562 SPVM::Dist - Generating SPVM Distrubution
1563  
1564 =head2 Description
1565  
1566 SPVM::Dist class has methods to generate an SPVM Distrubution.
1567  
1568 =head2 Usage
1569  
1570 my $dist = SPVM::Dist->new(
1571 class_name => 'Math',
1572 );
1573
1574 $dist->generate_dist;
1575  
1576 =head1 Copyright & License
1577  
1578 Copyright (c) 2023 Yuki Kimoto
1579  
1580 MIT License
« blib/lib/SPVM/Builder/Exe.pm ↑ Summary blib/lib/SPVM/Builder/Native/Method.pm »