blib/lib/YATT/Lite/Walker.pm

filter: Statementstmt 62.7% 74 / 118 Branchbran 35.7% 15 / 42 Conditioncond 24.3% 9 / 37 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 2 totaltotal 45.4% 109 / 240 CC 41 SCAR 38.3
CC
41
Cov
50%
__ANON__
156.0
walk_vfs_folders
42.0
__ANON__
21.8
CRAP 45.9
« blib/lib/YATT/Lite/Util/CmdLine.pm ↑ Summary blib/lib/YATT/Lite/LanguageServer/Generic.pm »
1 package YATT::Lite::Walker;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use YATT::Lite::Breakpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 sub MY () {__PACKAGE__}
7 13 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 our @EXPORT = qw/walk/;
11 13 our @EXPORT_OK = (@EXPORT, qw/walk_vfs_folders/);
12  
13 13 ▶use YATT::Lite::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use YATT::Lite::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use YATT::Lite::Util qw/lexpand/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶sub walk {
Subroutine walk: called CC=9 SCAR=24.4
Pod undocumented
18 3 (my %opts) = @_;
19  
20 3 ▶ 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!") 3 0 3
21 3 ▶ my $fromList = delete $opts{from} // $self->{doc_root};
Condition33%1/3
delete $opts{"from"} // $self->{"doc_root"}
l!l&&r!l&&!r
300
MC/DC0%0/2
delete $opts{"from"} // $self->{"doc_root"}
delete $opts{"from"} $self->{"doc_root"}
Truth table33%1/3
A // B
A= delete $opts{"from"}B= $self->{"doc_root"}
ABresult
1X1
011
000
22 3 my $nameRe = delete $opts{name_match};
23 3 my $noSymlink = delete $opts{ignore_symlink};
24  
25 3 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 3 ▶ };
Condition33%1/3
$forWidget //= sub { my($args) = @_; print $args->{"widget"}, "\n"; }
l!l&&r!l&&!r
300
MC/DC0%0/2
$forWidget //= sub { my($args) = @_; print $args->{"widget"}, "\n"; }
$forWidget sub { my($args) = @_; print $args->{"widget"}, "\n"; }
Truth table33%1/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 3 ▶ };
Condition33%1/3
delete $opts{"item"} // sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
l!l&&r!l&&!r
300
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 table33%1/3
A // B
A= delete $opts{"item"}B= sub { my($args) = @_; print "# ", $args->{"tree"}->cget("path"), "\n"; }
ABresult
1X1
011
000
34  
35 3 ▶ if (%opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%opts) 0 3 3
36 0 Carp::croak "Unknown options for traverse: ".join(", ", sort keys %opts);
37 }
38  
39 3 my %seen;
40 18 ▶ my $walk; $walk = sub {
Subroutine __ANON__: called CC=17 SCAR=30.8
41 18 my ($vfs, $tree, $prefix) = @_;
42 18 $forItem->({tree => $tree, vfs => $vfs});
43 18 my $path = $tree->cget('path');
44 18 ▶ return if -l $path and $noSymlink;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path and $noSymlink 0 18 18
Condition33%1/3
-l $path and $noSymlink
!ll&&!rl&&r
1800
MC/DC0%0/2
-l $path and $noSymlink
-l $path $noSymlink
Truth table33%1/3
A and B
A= -l $pathB= $noSymlink
ABresult
0X0
100
111
45 18 ▶ if ($tree->can_generate_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->can_generate_code) { } 9 9 18
46 # Template
47 9 $seen{$path}++;
48 9 foreach my YATT::Lite::Core::Part $part ($tree->list_parts) {
49 12 my $partName = $part->cget('name');
50 12 ▶ my @path = (@{$prefix // []}, $partName || ());
Condition60%3/5
$prefix // []
l!l
120
$partName || ()
l!l&&r!l&&!r
390
MC/DC0%0/1
$prefix // []
$prefix
MC/DC0%0/2
$partName || ()
$partName ()
Truth table50%1/2
A
A= $prefix
Aresult
11
00
Truth table66%2/3
A || B
A= $partNameB= ()
ABresult
1X1
011
000
51 12 ▶ next unless @path;
Branch: 1 branch
BranchTrueFalseTotal
unless @path 0 12 12
52 12 my $wname = do {
53 12 ▶ if (UNIVERSAL::isa($part, 'YATT::Lite::Core::Widget')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($part, 'YATT::Lite::Core::Widget')) { } 12 0 12
54 12 join(":", @path);
55 } else {
56 0 $partName;
57 }
58 };
59 12 ▶ if ($nameRe and $wname !~ $nameRe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nameRe and not $wname =~ /$nameRe/) 0 12 12
Condition33%1/3
$nameRe and not $wname =~ /$nameRe/
!ll&&!rl&&r
1200
MC/DC0%0/2
$nameRe and not $wname =~ /$nameRe/
$nameRe not $wname =~ /$nameRe/
Truth table33%1/3
A and not(B)
A= $nameReB= not $wname =~ /$nameRe/
ABresult
0X0
100
111
60 0 next;
61 }
62 12 $forWidget->({part => $part, name => $wname, kind => $part->{kind}});
63 }
64 } else {
65 # Dir
66 9 foreach my $itemName ($tree->list_all_names($vfs)) {
67 15 ▶ 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 15 0 15
68 or next;
69 15 ▶ next if $seen{$subtree->{path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$subtree->{"path"}}++ 6 9 15
70 9 ▶ $walk->($vfs, $subtree, [@{$prefix // []}, $itemName]);
Condition50%1/2
$prefix // []
l!l
09
MC/DC0%0/1
$prefix // []
$prefix
Truth table50%1/2
A
A= $prefix
Aresult
11
00
71 }
72 }
73  
74 18 foreach my YATT::Lite::VFS::Folder $superItem ($tree->list_base) {
75 15 ▶ next if $seen{$superItem->{path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$superItem->{"path"}}++ 9 6 15
76 6 $walk->($vfs, $superItem);
77 }
78 3 };
79  
80 3 foreach my $fromPath (lexpand($fromList)) {
81 3 my ($dir, $rootName) = do {
82 3 ▶ if (-d $fromPath) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $fromPath) { } 3 0 3
83 3 ($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 3 my $yatt = $self->load_yatt($dir);
92 3 my YATT::Lite::Core $vfs = $yatt->get_trans;
93  
94 my $rootPart = $rootName
95 ? $vfs->find_file($rootName)
96 3 ▶ : $vfs->{_root};
Branch: 1 branch
BranchTrueFalseTotal
$rootName ? : 0 3 3
97  
98 3 $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 13 1;
« blib/lib/YATT/Lite/Util/CmdLine.pm ↑ Summary blib/lib/YATT/Lite/LanguageServer/Generic.pm »