lib/App/Briefing/Filesystem.pm

filter: Statementstmt 43.1% 158 / 366 Branchbran 26.9% 70 / 260 Conditioncond 20.8% 20 / 96 MC/DCmcdc 15.0% 9 / 60 Subroutinesub 53.3% 32 / 60 Podpod 100% 45 / 45 totaltotal 37.6% 334 / 887 CC 171 SCAR 34.3
CC
171
Cov
34%
normalize
140.8
normalize
140.8
make_path
41.7
CRAP 30.7
« lib/App/Briefing/CLI.pm ↑ Summary lib/App/Briefing.pm »
1 package App::Briefing::Filesystem;
2 # ABSTRACT: Unicode-safe filesystem access for App::Briefing
3  
4 134 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 134 ▶use Encode qw( FB_CROAK decode encode );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 134 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 134 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 134 ▶use if $^O eq 'MSWin32', 'Win32';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 134 ▶use if $^O eq 'MSWin32', 'Win32::LongPath';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 134 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 134 our $VERSION = '0.006000';
13  
14 6300 ▶sub is_windows { $^O eq 'MSWin32' }
Subroutine is_windows: called CC=1 SCAR=0.0
Pod documented
15  
16  
17 717 ▶sub decode_path {
Subroutine decode_path: called CC=4 SCAR=18.8
Pod documented
18 0 ▶ my ( $self, $value ) = @_;
Subroutine decode_path: not called CC=4 SCAR=18.8
Pod documented
19 0 ▶ return $value unless defined $value;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value 0 717 717
unless defined $value 0 0 0
20 0 ▶ return $value if utf8::is_utf8($value);
Branch: 2 branches
BranchTrueFalseTotal
if utf8::is_utf8($value) 181 536 717
if utf8::is_utf8($value) 0 0 0
21  
22 0 my $decoded = eval { decode( 'UTF-8', $value, FB_CROAK ) };
23 0 ▶ return $@ ? $value : $decoded;
Branch: 2 branches
BranchTrueFalseTotal
$@ ? : 1 535 536
$@ ? : 0 0 0
24 }
25  
26  
27 257 ▶sub environment_value {
Subroutine environment_value: called CC=6 SCAR=24.2
Pod documented
28 0 ▶ my ( $self, $name ) = @_;
Subroutine environment_value: not called CC=6 SCAR=24.2
Pod documented
29 0 my $value = $ENV{$name};
30 0 ▶ return unless defined $value && length $value;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value and length $value 7 250 257
unless defined $value and length $value 0 0 0
Condition50%3/6
defined $value and length $value
!ll&&!rl&&r
61250
defined $value and length $value
!ll&&!rl&&r
000
MC/DC100%2/2
defined $value and length $value
defined $value length $value
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table100%3/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
31  
32 0 ▶ if ($self->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_windows) 12 238 250
if ($self->is_windows) 0 0 0
33 0 my $wide = $self->_wide_environment_value($name);
34 0 ▶ return $wide if defined $wide && length $wide;
Branch: 2 branches
BranchTrueFalseTotal
if defined $wide and length $wide 6 6 12
if defined $wide and length $wide 0 0 0
Condition33%2/6
defined $wide and length $wide
!ll&&!rl&&r
606
defined $wide and length $wide
!ll&&!rl&&r
000
MC/DC50%1/2
defined $wide and length $wide
defined $wide length $wide
MC/DC0%0/2
defined $wide and length $wide
defined $wide length $wide
Truth table66%2/3
A and B
A= defined $wideB= length $wide
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $wideB= length $wide
ABresult
0X0
100
111
35 }
36 0 return $self->decode_path($value);
37 }
38  
39  
40 12 ▶sub _wide_environment_value {
Subroutine _wide_environment_value: called CC=5 SCAR=20.9
41 0 ▶ my ( $self, $name ) = @_;
Subroutine _wide_environment_value: not called CC=5 SCAR=20.9
42 # Win32::ExpandEnvironmentStrings expands against the wide environment and
43 # returns ANSI code page bytes when every character fits that code page, a
44 # UTF-8 character string otherwise (wstr_to_sv in Win32.xs, Win32 0.59). The
45 # leading noncharacter U+FFFF fits no ANSI code page, so a usable result is
46 # always the character string. An unset variable stays unexpanded; under the
47 # UTF-8 code page 65001 the result is undef or bytes, and %ENV, which holds
48 # UTF-8 there, is used instead.
49 0 my $reference = "\x{FFFF}".'%'.$name.'%';
50 0 my $expanded = Win32::ExpandEnvironmentStrings($reference);
51 0 ▶ return unless defined $expanded && utf8::is_utf8($expanded);
Branch: 2 branches
BranchTrueFalseTotal
unless defined $expanded and utf8::is_utf8($expanded) 2 10 12
unless defined $expanded and utf8::is_utf8($expanded) 0 0 0
Condition50%3/6
defined $expanded and utf8::is_utf8($expanded)
!ll&&!rl&&r
1110
defined $expanded and utf8::is_utf8($expanded)
!ll&&!rl&&r
000
MC/DC100%2/2
defined $expanded and utf8::is_utf8($expanded)
defined $expanded utf8::is_utf8($expanded)
MC/DC0%0/2
defined $expanded and utf8::is_utf8($expanded)
defined $expanded utf8::is_utf8($expanded)
Truth table100%3/3
A and B
A= defined $expandedB= utf8::is_utf8($expanded)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $expandedB= utf8::is_utf8($expanded)
ABresult
0X0
100
111
52 0 ▶ return if $expanded eq $reference;
Branch: 2 branches
BranchTrueFalseTotal
if $expanded eq $reference 3 7 10
if $expanded eq $reference 0 0 0
53 0 ▶ return unless $expanded =~ s/\A\x{FFFF}//;
Branch: 2 branches
BranchTrueFalseTotal
unless $expanded =~ s/\A\x{FFFF}// 1 6 7
unless $expanded =~ s/\A\x{FFFF}// 0 0 0
54 0 return $expanded;
55 }
56  
57 236 ▶sub _native_path {
Subroutine _native_path: called CC=5 SCAR=24.3
58 0 ▶ my ( $self, $value ) = @_;
Subroutine _native_path: not called CC=5 SCAR=24.3
59 0 ▶ return $value
Branch: 2 branches
BranchTrueFalseTotal
if $self->is_windows or not defined $value or not utf8::is_utf8($value) 13 223 236
if $self->is_windows or not defined $value or not utf8::is_utf8($value) 0 0 0
Condition25%3/12
$self->is_windows or not defined $value or not utf8::is_utf8($value)
l!l&&r!l&&!r
013223
$self->is_windows or not defined $value
l!l&&r!l&&!r
00236
$self->is_windows or not defined $value or not utf8::is_utf8($value)
l!l&&r!l&&!r
000
$self->is_windows or not defined $value
l!l&&r!l&&!r
000
MC/DC33%1/3
$self->is_windows or not defined $value or not utf8::is_utf8($value)
$self->is_windows not defined $value not utf8::is_utf8($value)
MC/DC0%0/3
$self->is_windows or not defined $value or not utf8::is_utf8($value)
$self->is_windows not defined $value not utf8::is_utf8($value)
Truth table50%2/4
A or not(B) or not(C)
A= $self->is_windowsB= not defined $valueC= not utf8::is_utf8($value)
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or not(B) or not(C)
A= $self->is_windowsB= not defined $valueC= not utf8::is_utf8($value)
ABCresult
1XX1
01X1
0011
0000
60 if $self->is_windows || !defined $value || !utf8::is_utf8($value);
61  
62 0 my $encoded = eval { encode( 'UTF-8', $value, FB_CROAK ) };
63 0 ▶ return $@ ? $value : $encoded;
Branch: 2 branches
BranchTrueFalseTotal
$@ ? : 0 223 223
$@ ? : 0 0 0
64 }
65  
66 2379 ▶sub join_path {
Subroutine join_path: called CC=6 SCAR=27.8
Pod documented
67 0 ▶ my ( $self, @parts ) = @_;
Subroutine join_path: not called CC=6 SCAR=27.8
Pod documented
68 0 ▶ return '' unless @parts;
Branch: 2 branches
BranchTrueFalseTotal
unless @parts 0 2379 2379
unless @parts 0 0 0
69  
70 0 my $joined = shift @parts;
71 0 for my $part (@parts) {
72 0 ▶ next unless defined $part && length $part;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $part and length $part 0 4216 4216
unless defined $part and length $part 0 0 0
Condition16%1/6
defined $part and length $part
!ll&&!rl&&r
004216
defined $part and length $part
!ll&&!rl&&r
000
MC/DC0%0/2
defined $part and length $part
defined $part length $part
MC/DC0%0/2
defined $part and length $part
defined $part length $part
Truth table33%1/3
A and B
A= defined $partB= length $part
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $partB= length $part
ABresult
0X0
100
111
73 0 ▶ $joined = path($part)->is_absolute
Branch: 2 branches
BranchTrueFalseTotal
path($part)->is_absolute ? : 0 4216 4216
path($part)->is_absolute ? : 0 0 0
74 ? $part
75 : path( $joined, $part )->stringify;
76 }
77 0 return path($joined)->stringify;
78 }
79  
80  
81 243 ▶sub parent {
Subroutine parent: called CC=1 SCAR=1.2
Pod documented
82 0 ▶ my ( $self, $file ) = @_;
Subroutine parent: not called CC=1 SCAR=1.2
Pod documented
83 0 return path($file)->parent->stringify;
84 }
85  
86  
87 11 ▶sub basename {
Subroutine basename: called CC=1 SCAR=1.2
Pod documented
88 0 ▶ my ( $self, $file ) = @_;
Subroutine basename: not called CC=1 SCAR=1.2
Pod documented
89 0 return path($file)->basename;
90 }
91  
92  
93 0 ▶sub is_absolute {
Subroutine is_absolute: not called CC=2 SCAR=17.9
Pod documented
94 0 ▶ my ( $self, $file ) = @_;
Subroutine is_absolute: not called CC=2 SCAR=17.9
Pod documented
95 0 ▶ return path($file)->is_absolute ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
path($file)->is_absolute ? : 0 0 0
path($file)->is_absolute ? : 0 0 0
96 }
97  
98  
99 0 ▶sub current_dir {
Subroutine current_dir: not called CC=2 SCAR=17.9
Pod documented
100 0 ▶ my ( $self ) = @_;
Subroutine current_dir: not called CC=2 SCAR=17.9
Pod documented
101 0 ▶ my $directory = $self->is_windows
Branch: 2 branches
BranchTrueFalseTotal
$self->is_windows ? : 0 0 0
$self->is_windows ? : 0 0 0
102 ? Win32::LongPath::getcwdL()
103 : path('.')->absolute->stringify;
104 0 return $self->decode_path($directory);
105 }
106  
107  
108 280 ▶sub absolute {
Subroutine absolute: called CC=2 SCAR=10.5
Pod documented
109 0 ▶ my ( $self, $file ) = @_;
Subroutine absolute: not called CC=2 SCAR=10.5
Pod documented
110 0 ▶ my $absolute = $self->is_windows
Branch: 2 branches
BranchTrueFalseTotal
$self->is_windows ? : 0 280 280
$self->is_windows ? : 0 0 0
111 ? Win32::LongPath::abspathL($file)
112 : $self->normalize( path($file)->absolute->stringify );
113 0 return $self->decode_path($absolute);
114 }
115  
116  
117 42 ▶sub exists {
Subroutine exists: called CC=4 SCAR=21.7
Pod documented
118 0 ▶ my ( $self, $file ) = @_;
Subroutine exists: not called CC=4 SCAR=21.7
Pod documented
119 0 ▶ return Win32::LongPath::testL( 'e', $file ) ? 1 : 0
Branch: 4 branches
BranchTrueFalseTotal
if $self->is_windows 0 42 42
Win32::LongPath::testL('e', $file) ? : 0 0 0
if $self->is_windows 0 0 0
Win32::LongPath::testL('e', $file) ? : 0 0 0
120 if $self->is_windows;
121 0 ▶ return path($file)->exists ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
path($file)->exists ? : 3 39 42
path($file)->exists ? : 0 0 0
122 }
123  
124  
125 2126 ▶sub is_file {
Subroutine is_file: called CC=4 SCAR=21.7
Pod documented
126 0 ▶ my ( $self, $file ) = @_;
Subroutine is_file: not called CC=4 SCAR=21.7
Pod documented
127 0 ▶ return Win32::LongPath::testL( 'f', $file ) ? 1 : 0
Branch: 4 branches
BranchTrueFalseTotal
if $self->is_windows 0 2126 2126
Win32::LongPath::testL('f', $file) ? : 0 0 0
if $self->is_windows 0 0 0
Win32::LongPath::testL('f', $file) ? : 0 0 0
128 if $self->is_windows;
129 0 ▶ return path($file)->is_file ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
path($file)->is_file ? : 1974 152 2126
path($file)->is_file ? : 0 0 0
130 }
131  
132  
133 714 ▶sub is_dir {
Subroutine is_dir: called CC=4 SCAR=21.7
Pod documented
134 0 ▶ my ( $self, $file ) = @_;
Subroutine is_dir: not called CC=4 SCAR=21.7
Pod documented
135 0 ▶ return Win32::LongPath::testL( 'd', $file ) ? 1 : 0
Branch: 4 branches
BranchTrueFalseTotal
if $self->is_windows 0 714 714
Win32::LongPath::testL('d', $file) ? : 0 0 0
if $self->is_windows 0 0 0
Win32::LongPath::testL('d', $file) ? : 0 0 0
136 if $self->is_windows;
137 0 ▶ return path($file)->is_dir ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
path($file)->is_dir ? : 492 222 714
path($file)->is_dir ? : 0 0 0
138 }
139  
140  
141 147 ▶sub is_dangling_symlink {
Subroutine is_dangling_symlink: called CC=4 SCAR=18.9
Pod documented
142 0 ▶ my ( $self, $file ) = @_;
Subroutine is_dangling_symlink: not called CC=4 SCAR=18.9
Pod documented
143 0 ▶ return 0 if $self->is_windows;
Branch: 2 branches
BranchTrueFalseTotal
if $self->is_windows 0 147 147
if $self->is_windows 0 0 0
144 0 my $native = $self->_native_path($file);
145 0 ▶ return -l $native && !-e $native ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
-l $native && !(-e $native) ? : 4 143 147
-l $native && !(-e $native) ? : 0 0 0
Condition50%3/6
-l $native and not -e $native
!ll&&!rl&&r
14214
-l $native and not -e $native
!ll&&!rl&&r
000
MC/DC100%2/2
-l $native and not -e $native
-l $native not -e $native
MC/DC0%0/2
-l $native and not -e $native
-l $native not -e $native
Truth table100%3/3
A and not(B)
A= -l $nativeB= not -e $native
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= -l $nativeB= not -e $native
ABresult
0X0
100
111
146 }
147  
148  
149 698 ▶sub is_readable_file {
Subroutine is_readable_file: called CC=5 SCAR=23.7
Pod documented
150 0 ▶ my ( $self, $file ) = @_;
Subroutine is_readable_file: not called CC=5 SCAR=23.7
Pod documented
151 0 ▶ return 0 unless $self->is_file($file);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_file($file) 69 629 698
unless $self->is_file($file) 0 0 0
152  
153 0 my $fh;
154 my $opened = $self->is_windows
155 ? Win32::LongPath::openL( \$fh, '<:encoding(UTF-8)', $file )
156 0 ▶ : eval { $fh = path($file)->openr_utf8; 1 };
Branch: 2 branches
BranchTrueFalseTotal
$self->is_windows ? : 0 629 629
$self->is_windows ? : 0 0 0
157 0 ▶ return 0 unless $opened && $fh;
Branch: 2 branches
BranchTrueFalseTotal
unless $opened and $fh 0 629 629
unless $opened and $fh 0 0 0
Condition16%1/6
$opened and $fh
!ll&&!rl&&r
00629
$opened and $fh
!ll&&!rl&&r
000
MC/DC0%0/2
$opened and $fh
$opened $fh
MC/DC0%0/2
$opened and $fh
$opened $fh
Truth table33%1/3
A and B
A= $openedB= $fh
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $openedB= $fh
ABresult
0X0
100
111
158 0 close $fh;
159 0 return 1;
160 }
161  
162  
163 1157 ▶sub _universal_newlines {
Subroutine _universal_newlines: called CC=2 SCAR=10.3
164 0 ▶ my ( $self, $text ) = @_;
Subroutine _universal_newlines: not called CC=2 SCAR=10.3
165 0 ▶ $text = '' unless defined $text;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $text 0 1157 1157
unless defined $text 0 0 0
166 0 $text =~ s/\r\n?/\n/g;
167 0 return $text;
168 }
169  
170 1230 ▶sub slurp_utf8 {
Subroutine slurp_utf8: called CC=4 SCAR=23.7
Pod documented
171 0 ▶ my ( $self, $file ) = @_;
Subroutine slurp_utf8: not called CC=4 SCAR=23.7
Pod documented
172 0 ▶ return '' unless $self->is_file($file);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_file($file) 73 1157 1230
unless $self->is_file($file) 0 0 0
173  
174 0 ▶ if ($self->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_windows) 0 1157 1157
if ($self->is_windows) 0 0 0
175 0 my $fh;
176 0 ▶ return '' unless Win32::LongPath::openL(
Branch: 2 branches
BranchTrueFalseTotal
unless Win32::LongPath::openL(\$fh, "<:encoding(UTF-8)", $file) 0 0 0
unless Win32::LongPath::openL(\$fh, "<:encoding(UTF-8)", $file) 0 0 0
177 \$fh,
178 '<:encoding(UTF-8)',
179 $file,
180 );
181 0 local $/;
182 0 my $text = <$fh>;
183 0 close $fh;
184 0 return $self->_universal_newlines($text);
185 }
186  
187 0 my $text = eval { path($file)->slurp_utf8 };
188 0 return $self->_universal_newlines($text);
189 }
190  
191  
192 11 ▶sub spew_utf8 {
Subroutine spew_utf8: called CC=6 SCAR=32.5
Pod documented
193 0 ▶ my ( $self, $file, $text ) = @_;
Subroutine spew_utf8: not called CC=6 SCAR=32.5
Pod documented
194  
195 0 ▶ if ($self->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_windows) 0 11 11
if ($self->is_windows) 0 0 0
196 0 my $fh;
197 # openL keeps the default :crlf layer; :raw matches Path::Tiny's LF bytes.
198 0 ▶ return 0 unless Win32::LongPath::openL(
Branch: 2 branches
BranchTrueFalseTotal
unless Win32::LongPath::openL(\$fh, ">:raw:encoding(UTF-8)", $file) 0 0 0
unless Win32::LongPath::openL(\$fh, ">:raw:encoding(UTF-8)", $file) 0 0 0
199 \$fh,
200 '>:raw:encoding(UTF-8)',
201 $file,
202 );
203 0 my $ok = print {$fh} $text;
204 0 ▶ $ok = close($fh) && $ok;
Condition0%0/6
close $fh && $ok
!ll&&!rl&&r
000
close $fh && $ok
!ll&&!rl&&r
000
MC/DC0%0/2
close $fh && $ok
close $fh $ok
MC/DC0%0/2
close $fh && $ok
close $fh $ok
Truth table0%0/3
A && B
A= close $fhB= $ok
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= close $fhB= $ok
ABresult
0X0
100
111
205 0 ▶ return $ok ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 0 0 0
$ok ? : 0 0 0
206 }
207  
208 0 ▶ return eval { path($file)->spew_utf8($text); 1 } ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
eval { do { path($file)->spew_utf8($text); 1 } } ? : 9 2 11
eval { do { path($file)->spew_utf8($text); 1 } } ? : 0 0 0
209 }
210  
211  
212 11 ▶sub make_path {
Subroutine make_path: called CC=8 SCAR=37.3
Pod documented
213 0 ▶ my ( $self, $directory ) = @_;
Subroutine make_path: not called CC=8 SCAR=37.3
Pod documented
214 0 ▶ return 1 if $self->is_dir($directory);
Branch: 2 branches
BranchTrueFalseTotal
if $self->is_dir($directory) 2 9 11
if $self->is_dir($directory) 0 0 0
215  
216 0 ▶ if ($self->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_windows) 0 9 9
if ($self->is_windows) 0 0 0
217 0 my $parent = $self->parent($directory);
218 0 ▶ return 0
Branch: 2 branches
BranchTrueFalseTotal
if $parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent) 0 0 0
if $parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent) 0 0 0
Condition0%0/12
$parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent)
!ll&&!rl&&r
000
$parent ne $directory and not $self->is_dir($parent)
!ll&&!rl&&r
000
$parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent)
!ll&&!rl&&r
000
$parent ne $directory and not $self->is_dir($parent)
!ll&&!rl&&r
000
MC/DC0%0/3
$parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent)
$parent ne $directory not $self->is_dir($parent) not $self->make_path($parent)
MC/DC0%0/3
$parent ne $directory and not $self->is_dir($parent) and not $self->make_path($parent)
$parent ne $directory not $self->is_dir($parent) not $self->make_path($parent)
Truth table0%0/4
A and not(B) and not(C)
A= $parent ne $directoryB= not $self->is_dir($parent)C= not $self->make_path($parent)
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and not(C)
A= $parent ne $directoryB= not $self->is_dir($parent)C= not $self->make_path($parent)
ABCresult
0XX0
10X0
1100
1111
219 if $parent ne $directory
220 && !$self->is_dir($parent)
221 && !$self->make_path($parent);
222 0 ▶ return 1 if Win32::LongPath::mkdirL($directory);
Branch: 2 branches
BranchTrueFalseTotal
if Win32::LongPath::mkdirL($directory) 0 0 0
if Win32::LongPath::mkdirL($directory) 0 0 0
223 0 return $self->is_dir($directory);
224 }
225  
226 0 ▶ return eval { path($directory)->mkpath; 1 } ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
eval { do { path($directory)->mkpath; 1 } } ? : 9 0 9
eval { do { path($directory)->mkpath; 1 } } ? : 0 0 0
227 }
228  
229  
230 90 ▶sub children {
Subroutine children: called CC=6 SCAR=30.8
Pod documented
231 0 ▶ my ( $self, $directory ) = @_;
Subroutine children: not called CC=6 SCAR=30.8
Pod documented
232 0 ▶ return [] unless $self->is_dir($directory);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_dir($directory) 1 89 90
unless $self->is_dir($directory) 0 0 0
233  
234 0 ▶ if ($self->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_windows) 0 89 89
if ($self->is_windows) 0 0 0
235 0 my $dir = Win32::LongPath->new;
236 0 ▶ return [] unless $dir->opendirL($directory);
Branch: 2 branches
BranchTrueFalseTotal
unless $dir->opendirL($directory) 0 0 0
unless $dir->opendirL($directory) 0 0 0
237 0 my @entries = $dir->readdirL;
238 0 $dir->closedirL;
239 return [
240 sort
241 0 map { $self->decode_path($_) }
242 0 ▶ grep { $_ ne '.' && $_ ne '..' }
Condition0%0/6
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
000
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
243 @entries
244 ];
245 }
246  
247 0 my $native_directory = $self->_native_path($directory);
248 0 my @children = eval { path($native_directory)->children };
249 0 ▶ return [] if $@;
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 89 89
if $@ 0 0 0
250 0 return [ sort map { $self->decode_path( $_->basename ) } @children ];
251 }
252  
253  
254 8 ▶sub child_directories {
Subroutine child_directories: called CC=1 SCAR=1.2
Pod documented
255 0 ▶ my ( $self, $directory ) = @_;
Subroutine child_directories: not called CC=1 SCAR=1.2
Pod documented
256 return [
257 0 grep { $self->is_dir($_) }
258 0 map { $self->join_path( $directory, $_ ) }
259 0 @{ $self->children($directory) }
260 ];
261 }
262  
263  
264 13 ▶sub walk_files {
Subroutine walk_files: called CC=2 SCAR=10.1
Pod documented
265 0 ▶ my ( $self, $root, $suffix ) = @_;
Subroutine walk_files: not called CC=2 SCAR=10.1
Pod documented
266 0 ▶ return [] unless $self->is_dir($root);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_dir($root) 0 13 13
unless $self->is_dir($root) 0 0 0
267  
268 0 my @files;
269 0 $self->_walk_files_into( \@files, $root, $suffix );
270 0 return \@files;
271 }
272  
273  
274 14 ▶sub _walk_files_into {
Subroutine _walk_files_into: called CC=6 SCAR=24.2
275 0 ▶ my ( $self, $files, $directory, $suffix ) = @_;
Subroutine _walk_files_into: not called CC=6 SCAR=24.2
276 0 my @directories;
277 0 for my $name (@{ $self->children($directory) }) {
278 0 my $entry = $self->join_path( $directory, $name );
279 0 ▶ if ($self->is_dir($entry)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->is_dir($entry)) { } 1 37 38
elsif ($self->is_file($entry) and $name =~ /\Q$suffix\E\z/) { } 36 1 37
if ($self->is_dir($entry)) { } 0 0 0
elsif ($self->is_file($entry) and $name =~ /\Q$suffix\E\z/) { } 0 0 0
280 0 push @directories, $entry;
281 }
282 ▶ elsif ($self->is_file($entry) && $name =~ /\Q$suffix\E\z/) {
Condition33%2/6
$self->is_file($entry) and $name =~ /\Q$suffix\E\z/
!ll&&!rl&&r
0136
$self->is_file($entry) and $name =~ /\Q$suffix\E\z/
!ll&&!rl&&r
000
MC/DC50%1/2
$self->is_file($entry) and $name =~ /\Q$suffix\E\z/
$self->is_file($entry) $name =~ /\Q$suffix\E\z/
MC/DC0%0/2
$self->is_file($entry) and $name =~ /\Q$suffix\E\z/
$self->is_file($entry) $name =~ /\Q$suffix\E\z/
Truth table66%2/3
A and B
A= $self->is_file($entry)B= $name =~ /\Q$suffix\E\z/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->is_file($entry)B= $name =~ /\Q$suffix\E\z/
ABresult
0X0
100
111
283 0 push @{$files}, $entry;
284 }
285 }
286 0 $self->_walk_files_into( $files, $_, $suffix ) for @directories;
287 0 return;
288 }
289  
290 298 ▶sub normalize {
Subroutine normalize: called CC=16 SCAR=49.5
Pod documented
291 0 ▶ my ( $self, $file ) = @_;
Subroutine normalize: not called CC=16 SCAR=49.5
Pod documented
292 0 ▶ my $value = defined $file ? $file : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $file ? : 298 0 298
defined $file ? : 0 0 0
293  
294 0 my $prefix = '';
295 0 ▶ if ($self->is_windows) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->is_windows) { } 0 298 298
elsif ($value =~ s[\A/+][]) { } 298 0 298
if ($self->is_windows) { } 0 0 0
elsif ($value =~ s[\A/+][]) { } 0 0 0
296 0 $value =~ tr{\\}{/};
297 0 ▶ if ($value =~ s{\A([A-Za-z]:)(?:/+)?}{}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($value =~ s[\A([A-Za-z]:)(?:/+)?][]) { } 0 0 0
elsif ($value =~ s[\A/+][]) { } 0 0 0
if ($value =~ s[\A([A-Za-z]:)(?:/+)?][]) { } 0 0 0
elsif ($value =~ s[\A/+][]) { } 0 0 0
298 0 $prefix = $1.'/';
299 }
300 elsif ($value =~ s{\A/+}{}) {
301 0 $prefix = '/';
302 }
303 }
304 elsif ($value =~ s{\A/+}{}) {
305 0 $prefix = '/';
306 }
307  
308 0 my @parts;
309 0 for my $part (split m{/+}, $value) {
310 0 ▶ next if $part eq '' || $part eq '.';
Branch: 2 branches
BranchTrueFalseTotal
if $part eq "" or $part eq "." 0 1633 1633
if $part eq "" or $part eq "." 0 0 0
Condition16%1/6
$part eq "" or $part eq "."
l!l&&r!l&&!r
001633
$part eq "" or $part eq "."
l!l&&r!l&&!r
000
MC/DC0%0/2
$part eq "" or $part eq "."
$part eq "" $part eq "."
MC/DC0%0/2
$part eq "" or $part eq "."
$part eq "" $part eq "."
Truth table33%1/3
A or B
A= $part eq ""B= $part eq "."
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $part eq ""B= $part eq "."
ABresult
1X1
011
000
311 0 ▶ if ($part eq '..') {
Branch: 2 branches
BranchTrueFalseTotal
if ($part eq "..") 0 1633 1633
if ($part eq "..") 0 0 0
312 0 ▶ if (@parts && $parts[-1] ne '..') {
Branch: 2 branches
BranchTrueFalseTotal
if (@parts and $parts[-1] ne "..") 0 0 0
if (@parts and $parts[-1] ne "..") 0 0 0
Condition0%0/6
@parts and $parts[-1] ne ".."
!ll&&!rl&&r
000
@parts and $parts[-1] ne ".."
!ll&&!rl&&r
000
MC/DC0%0/2
@parts and $parts[-1] ne ".."
@parts $parts[-1] ne ".."
MC/DC0%0/2
@parts and $parts[-1] ne ".."
@parts $parts[-1] ne ".."
Truth table0%0/3
A and B
A= @partsB= $parts[-1] ne ".."
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @partsB= $parts[-1] ne ".."
ABresult
0X0
100
111
313 0 pop @parts;
314 0 next;
315 }
316 0 ▶ push @parts, $part unless $prefix;
Branch: 2 branches
BranchTrueFalseTotal
unless $prefix 0 0 0
unless $prefix 0 0 0
317 0 next;
318 }
319 0 push @parts, $part;
320 }
321  
322 0 my $normalized = $prefix.join '/', @parts;
323 0 ▶ $normalized = '/' if $normalized eq '' && $prefix eq '/';
Branch: 2 branches
BranchTrueFalseTotal
if $normalized eq "" and $prefix eq "/" 0 298 298
if $normalized eq "" and $prefix eq "/" 0 0 0
Condition16%1/6
$normalized eq "" and $prefix eq "/"
!ll&&!rl&&r
29800
$normalized eq "" and $prefix eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
$normalized eq "" and $prefix eq "/"
$normalized eq "" $prefix eq "/"
MC/DC0%0/2
$normalized eq "" and $prefix eq "/"
$normalized eq "" $prefix eq "/"
Truth table33%1/3
A and B
A= $normalized eq ""B= $prefix eq "/"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $normalized eq ""B= $prefix eq "/"
ABresult
0X0
100
111
324 0 ▶ $normalized = lc $normalized if $self->is_windows;
Branch: 2 branches
BranchTrueFalseTotal
if $self->is_windows 0 298 298
if $self->is_windows 0 0 0
325 0 return $normalized;
326 }
327  
328  
329 9 ▶sub within {
Subroutine within: called CC=4 SCAR=20.7
Pod documented
330 0 ▶ my ( $self, $file, $root ) = @_;
Subroutine within: not called CC=4 SCAR=20.7
Pod documented
331 0 my $normalized_file = $self->normalize($file);
332 0 my $normalized_root = $self->normalize($root);
333 0 ▶ return 1 if $normalized_file eq $normalized_root;
Branch: 2 branches
BranchTrueFalseTotal
if $normalized_file eq $normalized_root 0 9 9
if $normalized_file eq $normalized_root 0 0 0
334 0 ▶ my $prefix = $normalized_root eq '/' ? '/' : $normalized_root.'/';
Branch: 2 branches
BranchTrueFalseTotal
$normalized_root eq '/' ? : 0 9 9
$normalized_root eq '/' ? : 0 0 0
335 0 ▶ return index( $normalized_file, $prefix ) == 0 ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
index($normalized_file, $prefix) == 0 ? : 9 0 9
index($normalized_file, $prefix) == 0 ? : 0 0 0
336 }
337  
338  
339 1 ▶sub relative {
Subroutine relative: called CC=1 SCAR=1.2
Pod documented
340 0 ▶ my ( $self, $file, $root ) = @_;
Subroutine relative: not called CC=1 SCAR=1.2
Pod documented
341 0 return path($file)->relative($root)->stringify;
342 }
343  
344  
345  
346 134 1;
347  
348 __END__
« lib/App/Briefing/CLI.pm ↑ Summary lib/App/Briefing.pm »