blib/lib/YATT/Lite/CLI/GenPerl.pm

filter: Statementstmt 93.0% 40 / 43 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 92.3% 60 / 65 CC 7 SCAR 10.5
CC
7
Cov
93%
main
5.0
__ANON__
3.0
BEGIN
1.0
CRAP 2.9
« blib/lib/YATT/Lite/VarMaker.pm ↑ Summary blib/lib/YATT/Lite/Util/CycleDetector.pm »
1 package YATT::Lite::CLI::GenPerl; sub MY () {__PACKAGE__}
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw(YATT::Lite::CLI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use YATT::Lite::MFields qw/all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use YATT::Lite::Entities qw/*SYS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 require File::Spec;
12  
13 #========================================
14 # yatt.genperl [--all] FILE...
15 #
16 # Emits the perl code YATT::Lite generates for each template
17 # (the jspc-style offline entry to the transpiler).
18 # --all also emits the generated code of dependencies (base templates,
19 # widgets in other files); by default only the target (depth == 1).
20 #
21 # Note: open_trans/find_product are still VFS-internal API. They are
22 # shared with the language server (Inspector), so they are candidates
23 # for a future $site->compile facade - tracked in GH-270.
24 #========================================
25  
26 4 ▶sub main {
Subroutine main: called CC=5 SCAR=16.2
Pod undocumented
27 4 my ($self, @files) = @_;
28 4 my $nerror = 0;
29 4 foreach my $fn (@files) {
30 4 my $abs = YATT::Lite::Util::normalize_fs_path(File::Spec->rel2abs($fn));
31 4 ▶ unless (-e $abs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $abs) 1 3 4
32 # Note: VFS find_file would lazily create a Template object even
33 # for a missing file, so test the filesystem here.
34 1 warn "No such file: $fn\n";
35 1 $nerror++;
36 1 next;
37 }
38 3 my $site = $self->site_for($abs);
39 3 local $SYS = $site;
40 3 my ($dh, $name) = $site->resolve_file($abs);
41 3 $dh->fconfigure_encoding(\*STDOUT, \*STDERR);
42 3 my $trans = $dh->open_trans;
43 3 ▶ my $tmpl = $trans->find_file($name) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $tmpl = $trans->find_file($name) or do { warn "No such file: $fn\n"; ++$nerror; next } 3 0 3
44 0 warn "No such file: $fn\n";
45 0 $nerror++;
46 0 next;
47 };
48 $trans->find_product
49 6 ▶ (perl => $tmpl, sink => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
50 6 my ($info, @script) = @_;
51 6 ▶ print @script if $self->{all} || $info->{depth} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"all"} or $info->{"depth"} == 1 4 2 6
Condition100%3/3
$self->{"all"} or $info->{"depth"} == 1
l!l&&r!l&&!r
222
MC/DC100%2/2
$self->{"all"} or $info->{"depth"} == 1
$self->{"all"} $info->{"depth"} == 1
Truth table100%3/3
A or B
A= $self->{"all"}B= $info->{"depth"} == 1
ABresult
1X1
011
000
52 6 eval {
53 # Generated scripts must be evaluated even when not printed,
54 # so that entity definitions materialize for dependent
55 # templates. Errors in generated code are yatt.lint's job,
56 # not ours - hence the bare eval.
57 6 YATT::Lite::Util::ckeval(@script);
58 };
59 3 });
60 }
61 4 ▶ $nerror ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$nerror ? : 1 3 4
62 }
63  
64 3 1;
« blib/lib/YATT/Lite/VarMaker.pm ↑ Summary blib/lib/YATT/Lite/Util/CycleDetector.pm »