blib/lib/YATT/Lite/Walker.pm

filter: Statementstmt 25.4% 30 / 118 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 37 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 52.9% 9 / 17 Podpod 0.0% 0 / 2 totaltotal 16.2% 39 / 240 CC 41 SCAR 49.6
CC
41
Cov
15%
__ANON__
306.0
__ANON__
156.0
walk
90.0
CRAP 143.0
« blib/lib/YATT/Lite/LanguageServer/Spec2Types.pm ↑ Summary blib/lib/YATT/Lite/LanguageServer/SpecParser.pm »
1 package YATT::Lite::Walker;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use YATT::Lite::Breakpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 sub MY () {__PACKAGE__}
7 6 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 our @EXPORT = qw/walk/;
11 6 our @EXPORT_OK = (@EXPORT, qw/walk_vfs_folders/);
12  
13 6 ▶use YATT::Lite::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use YATT::Lite::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use YATT::Lite::Util qw/lexpand/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub walk {
Subroutine walk: not called CC=9 SCAR=45.0
Pod undocumented
18 0 (my %opts) = @_;
19  
20 0 ▶ my YATT::Lite::Factory $self = delete $opts{factory} or Carp::croak "factory is missing!";
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Factory $self = delete $opts{"factory"} or Carp::croak("factory is missing!") 0 0 0
21 0 ▶ my $fromList = delete $opts{from} // $self->{doc_root};
Condition0%0/3
delete $opts{"from"} // $self->{"doc_root"}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{"from"} // $self->{"doc_root"}
delete $opts{"from"} $self->{"doc_root"}
Truth table0%0/3
A // B
A= delete $opts{"from"}B= $self->{"doc_root"}
ABresult
1X1
011
000
22 0 my $nameRe = delete $opts{name_match};
23 0 my $noSymlink = delete $opts{ignore_symlink};
24  
25 0 my ($forWidget) = grep {defined} (delete $opts{widget}, delete $opts{part});
26 0 ▶ $forWidget //= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 my ($args) = @_;
28 0 print $args->{widget}, "\n";
29 0 ▶ };
Condition0%0/3
$forWidget //= sub { my($args) = @_; print $args->{"widget"}, "\n"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$forWidget //= sub { my($args) = @_; print $args->{"widget"}, "\n"; }
$forWidget sub { my($args) = @_; print $args->{"widget"}, "\n"; }
Truth table0%0/3
A //= B
A= $forWidgetB= sub { my($args) = @_; print $args->{"widget"}, "\n"; }
ABresult
1X1
011
000
30 0 ▶ my $forItem = delete $opts{item} // sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 my ($args) = @_;
32 0 print "# ", $args->{tree}->cget('path'), "\n";
33 0 ▶ };
Condition0%0/3
delete $opts{"item"} // sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{"item"} // sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
delete $opts{"item"} sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
Truth table0%0/3
A // B
A= delete $opts{"item"}B= sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
ABresult
1X1
011
000
34  
35 0 ▶ if (%opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%opts) 0 0 0
36 0 Carp::croak "Unknown options for traverse: ".join(", ", sort keys %opts);
37 }
38  
39 0 my %seen;
40 0 ▶ my $walk; $walk = sub {
Subroutine __ANON__: not called CC=17 SCAR=57.2
41 0 my ($vfs, $tree, $prefix) = @_;
42 0 $forItem->({tree => $tree, vfs => $vfs});
43 0 my $path = $tree->cget('path');
44 0 ▶ return if -l $path and $noSymlink;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path and $noSymlink 0 0 0
Condition0%0/3
-l $path and $noSymlink
!ll&&!rl&&r
000
MC/DC0%0/2
-l $path and $noSymlink
-l $path $noSymlink
Truth table0%0/3
A and B
A= -l $pathB= $noSymlink
ABresult
0X0
100
111
45 0 ▶ if ($tree->can_generate_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->can_generate_code) { } 0 0 0
46 # Template
47 0 $seen{$path}++;
48 0 foreach my YATT::Lite::Core::Part $part ($tree->list_parts) {
49 0 my $partName = $part->cget('name');
50 0 ▶ my @path = (@{$prefix // []}, $partName || ());
Condition0%0/5
$prefix // []
l!l
00
$partName || ()
l!l&&r!l&&!r
000
MC/DC0%0/1
$prefix // []
$prefix
MC/DC0%0/2
$partName || ()
$partName ()
Truth table0%0/2
A
A= $prefix
Aresult
11
00
Truth table0%0/3
A || B
A= $partNameB= ()
ABresult
1X1
011
000
51 0 ▶ next unless @path;
Branch: 1 branch
BranchTrueFalseTotal
unless @path 0 0 0
52 0 my $wname = do {
53 0 ▶ if (UNIVERSAL::isa($part, 'YATT::Lite::Core::Widget')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($part, 'YATT::Lite::Core::Widget')) { } 0 0 0
54 0 join(":", @path);
55 } else {
56 0 $partName;
57 }
58 };
59 0 ▶ if ($nameRe and $wname !~ $nameRe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nameRe and not $wname =~ /$nameRe/) 0 0 0
Condition0%0/3
$nameRe and not $wname =~ /$nameRe/
!ll&&!rl&&r
000
MC/DC0%0/2
$nameRe and not $wname =~ /$nameRe/
$nameRe not $wname =~ /$nameRe/
Truth table0%0/3
A and not(B)
A= $nameReB= not $wname =~ /$nameRe/
ABresult
0X0
100
111
60 0 next;
61 }
62 0 $forWidget->({part => $part, name => $wname, kind => $part->{kind}});
63 }
64 } else {
65 # Dir
66 0 foreach my $itemName ($tree->list_all_names($vfs)) {
67 0 ▶ my YATT::Lite::VFS::Folder $subtree = $tree->lookup_1($vfs, $itemName)
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::VFS::Folder $subtree = $tree->lookup_1($vfs, $itemName) or next 0 0 0
68 or next;
69 0 ▶ next if $seen{$subtree->{path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$subtree->{"path"}}++ 0 0 0
70 0 ▶ $walk->($vfs, $subtree, [@{$prefix // []}, $itemName]);
Condition0%0/2
$prefix // []
l!l
00
MC/DC0%0/1
$prefix // []
$prefix
Truth table0%0/2
A
A= $prefix
Aresult
11
00
71 }
72 }
73  
74 0 foreach my YATT::Lite::VFS::Folder $superItem ($tree->list_base) {
75 0 ▶ next if $seen{$superItem->{path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$superItem->{"path"}}++ 0 0 0
76 0 $walk->($vfs, $superItem);
77 }
78 0 };
79  
80 0 foreach my $fromPath (lexpand($fromList)) {
81 0 my ($dir, $rootName) = do {
82 0 ▶ if (-d $fromPath) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $fromPath) { } 0 0 0
83 0 ($fromPath, '')
84 } else {
85 0 my ($fn, $dn, $ext)
86 = File::Basename::fileparse($fromPath, qr{\.\w+\z});
87 0 ($dn, $fn, $ext);
88 }
89 };
90  
91 0 my $yatt = $self->load_yatt($dir);
92 0 my YATT::Lite::Core $vfs = $yatt->get_trans;
93  
94 my $rootPart = $rootName
95 ? $vfs->find_file($rootName)
96 0 ▶ : $vfs->{_root};
Branch: 1 branch
BranchTrueFalseTotal
$rootName ? : 0 0 0
97  
98 0 $walk->($vfs, $rootPart);
99 }
100 }
101  
102 0 ▶sub walk_vfs_folders {
Subroutine walk_vfs_folders: not called CC=6 SCAR=37.4
Pod undocumented
103 0 (my %opts) = @_;
104  
105 0 ▶ my YATT::Lite::Factory $self = delete $opts{factory} or Carp::croak "factory is missing!";
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Factory $self = delete $opts{"factory"} or Carp::croak("factory is missing!") 0 0 0
106 0 ▶ my $fromList = delete $opts{from} // $self->{_tmpldirs};
Condition0%0/3
delete $opts{"from"} // $self->{"_tmpldirs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{"from"} // $self->{"_tmpldirs"}
delete $opts{"from"} $self->{"_tmpldirs"}
Truth table0%0/3
A // B
A= delete $opts{"from"}B= $self->{"_tmpldirs"}
ABresult
1X1
011
000
107 0 my $noSymlink = delete $opts{ignore_symlink};
108  
109 0 ▶ my $dirAction = delete $opts{dir} // sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 my ($dir, $vfs) = @_;
111 # print join("\t", dir => $yatt->cget('dir'), $yatt->EntNS), "\n";
112 0 print join("\t", dir => $dir->cget('path'), $dir->cget('entns')), "\n";
113 0 ▶ };
Condition0%0/3
delete $opts{"dir"} // sub { my($dir, $vfs) = @_; print join("\t", "dir", $dir->cget("path"), $dir->cget("entns")), "\n"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{"dir"} // sub { my($dir, $vfs) = @_; print join("\t", "dir", $dir->cget("path"), $dir->cget("entns")), "\n"; }
delete $opts{"dir"} sub { my($dir, $vfs) = @_; print join("\t", "dir", $dir->cget("path"), $dir->cget("entns")), "\n"; }
Truth table0%0/3
A // B
A= delete $opts{"dir"}B= sub { my($dir, $vfs) = @_; print join("\t", "dir", $dir->cget("path"), $dir->cget("entns")), "\n"; }
ABresult
1X1
011
000
114  
115 0 ▶ my $fileAction = delete $opts{file} // sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 my ($tmpl) = @_;
117 0 print join("\t", file => $tmpl->cget('path'), $tmpl->cget('entns')), "\n";
118 0 ▶ };
Condition0%0/3
delete $opts{"file"} // sub { my($tmpl) = @_; print join("\t", "file", $tmpl->cget("path"), $tmpl->cget("entns")), "\n"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{"file"} // sub { my($tmpl) = @_; print join("\t", "file", $tmpl->cget("path"), $tmpl->cget("entns")), "\n"; }
delete $opts{"file"} sub { my($tmpl) = @_; print join("\t", "file", $tmpl->cget("path"), $tmpl->cget("entns")), "\n"; }
Truth table0%0/3
A // B
A= delete $opts{"file"}B= sub { my($tmpl) = @_; print join("\t", "file", $tmpl->cget("path"), $tmpl->cget("entns")), "\n"; }
ABresult
1X1
011
000
119  
120 0 ▶ if (%opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%opts) 0 0 0
121 0 Carp::croak "Unknown options for traverse: ".join(", ", sort keys %opts);
122 }
123  
124 0 my %seen;
125 0 ▶ my $walk; $walk = sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
126 0 my (@dirName) = @_;
127 0 foreach my $dirName (@dirName) {
128 0 ▶ next if $seen{$dirName}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$dirName}++ 0 0 0
129 0 ▶ next if -l $dirName and $noSymlink;
Branch: 1 branch
BranchTrueFalseTotal
if -l $dirName and $noSymlink 0 0 0
Condition0%0/3
-l $dirName and $noSymlink
!ll&&!rl&&r
000
MC/DC0%0/2
-l $dirName and $noSymlink
-l $dirName $noSymlink
Truth table0%0/3
A and B
A= -l $dirNameB= $noSymlink
ABresult
0X0
100
111
130 0 my $yatt = $self->load_yatt($dirName);
131 0 my $vfs = $yatt->get_vfs;
132 0 $dirAction->($vfs->root, $yatt);
133 0 my @subDir;
134 0 foreach my $name ($vfs->list_all_names) {
135 0 my $path = "$dirName/$name";
136 0 ▶ next unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
137 0 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 0 0 0
138 0 push @subDir, $path;
139 } else {
140 0 ▶ next if $seen{$path}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$path}++ 0 0 0
141 0 my $tmpl = $yatt->find_part($name);
142 0 my $realFn = $tmpl->cget('path');
143 0 ▶ next if -l $realFn and $noSymlink;
Branch: 1 branch
BranchTrueFalseTotal
if -l $realFn and $noSymlink 0 0 0
Condition0%0/3
-l $realFn and $noSymlink
!ll&&!rl&&r
000
MC/DC0%0/2
-l $realFn and $noSymlink
-l $realFn $noSymlink
Truth table0%0/3
A and B
A= -l $realFnB= $noSymlink
ABresult
0X0
100
111
144 0 $fileAction->($tmpl, $yatt);
145 }
146 }
147  
148 0 ▶ $walk->(@subDir) if @subDir;
Branch: 1 branch
BranchTrueFalseTotal
if @subDir 0 0 0
149  
150 0 $walk->($yatt->list_base);
151 }
152 0 };
153  
154 0 $walk->(lexpand($fromList));
155 }
156  
157 6 1;
« blib/lib/YATT/Lite/LanguageServer/Spec2Types.pm ↑ Summary blib/lib/YATT/Lite/LanguageServer/SpecParser.pm »