Venus/Path.pm

filter: Statementstmt 84.1% 217 / 258 Branchbran 71.7% 56 / 78 Conditioncond 50.0% 14 / 28 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 100% 46 / 46 Podpod 100% 37 / 37 totaltotal 80.9% 375 / 463 CC 52 SCAR 13.7
CC
52
Cov
79%
read
12.0
write
11.6
find
5.2
CRAP 3.9
« Venus/Hash.pm ↑ Summary Venus/Box.pm »
1 package Venus::Path;
2  
3 61 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 61 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 61 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 61 base 'Venus::Kind::Utility';
11  
12 61 with 'Venus::Role::Accessible';
13 61 with 'Venus::Role::Explainable';
14  
15 use overload (
16 '""' => 'explain',
17 1 ▶ '.' => sub{$_[0]->value . "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
18 1 ▶ 'eq' => sub{$_[0]->value eq "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 ▶ 'ne' => sub{$_[0]->value ne "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶ 'qr' => sub{qr/@{[quotemeta($_[0]->value)]}/},
Subroutine __ANON__: called CC=1 SCAR=0.0
21 61 '~~' => 'explain',
22 fallback => 1,
23 61 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # METHODS
26  
27 sub absolute {
28 24 ▶ my ($self) = @_;
Subroutine absolute: called CC=1 SCAR=0.0
Pod documented
29  
30 24 require File::Spec;
31  
32 24 return $self->class->new(File::Spec->rel2abs($self->get));
33 }
34  
35 sub basename {
36 1 ▶ my ($self) = @_;
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
37  
38 1 require File::Basename;
39  
40 1 return File::Basename::basename($self->get);
41 }
42  
43 sub child {
44 8 ▶ my ($self, $path) = @_;
Subroutine child: called CC=1 SCAR=0.0
Pod documented
45  
46 8 require File::Spec;
47  
48 8 my @parts = File::Spec->splitdir($path);
49  
50 8 return $self->class->new(File::Spec->catfile($self->get, @parts));
51 }
52  
53 sub chmod {
54 1 ▶ my ($self, $mode) = @_;
Subroutine chmod: called CC=1 SCAR=0.0
Pod documented
55  
56 1 my $path = $self->get;
57  
58 1 CORE::chmod($mode, $path);
59  
60 1 return $self;
61 }
62  
63 sub chown {
64 1 ▶ my ($self, @args) = @_;
Subroutine chown: called CC=2 SCAR=7.0
Pod documented
65  
66 1 my $path = $self->get;
67  
68 1 ▶ CORE::chown((map $_||-1, @args[0,1]), $path);
Condition50%1/2
$_ || -1
l!l
20
MC/DC0%0/1
$_ || -1
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
69  
70 1 return $self;
71 }
72  
73 sub children {
74 9 ▶ my ($self) = @_;
Subroutine children: called CC=2 SCAR=6.9
Pod documented
75  
76 9 require File::Spec;
77  
78 9 my @paths = map $self->glob($_), '.??*', '*';
79  
80 9 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 1 9
81 }
82  
83 sub default {
84 4 ▶ require Cwd;
Subroutine default: called CC=1 SCAR=0.0
Pod documented
85  
86 4 return Cwd::getcwd();
87 }
88  
89 sub directories {
90 1 ▶ my ($self) = @_;
Subroutine directories: called CC=2 SCAR=7.1
Pod documented
91  
92 1 my @paths = grep -d, $self->children;
93  
94 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
95 }
96  
97 sub exists {
98 24 ▶ my ($self) = @_;
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
99  
100 24 return int!!-e $self->get;
101 }
102  
103 sub explain {
104 234 ▶ my ($self) = @_;
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
105  
106 234 return $self->get;
107 }
108  
109 sub find {
110 3 ▶ my ($self, $expr) = @_;
Subroutine find: called CC=5 SCAR=16.4
Pod documented
111  
112 3 ▶ $expr = '.*' if !$expr;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 1 2 3
113  
114 3 ▶ $expr = qr/$expr/ if ref($expr) ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $expr ne "Regexp" 3 0 3
115  
116 3 my @paths;
117  
118 push @paths, grep {
119 39 $_ =~ $expr
120 } map {
121 3 ▶ $_->is_directory ? $_->find($expr) : $_
Branch: 1 branch
BranchTrueFalseTotal
$_->is_directory ? : 0 39 39
122 }
123 $self->children;
124  
125 3 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
126 }
127  
128 sub files {
129 1 ▶ my ($self) = @_;
Subroutine files: called CC=2 SCAR=7.1
Pod documented
130  
131 1 my @paths = grep -f, $self->children;
132  
133 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
134 }
135  
136 sub glob {
137 21 ▶ my ($self, $expr) = @_;
Subroutine glob: called CC=3 SCAR=11.0
Pod documented
138  
139 21 require File::Spec;
140  
141 21 ▶ $expr ||= '*';
Condition100%2/2
$expr ||= "*"
l!l
201
MC/DC100%1/1
$expr ||= "*"
$expr
Truth table100%2/2
A
A= $expr
Aresult
11
00
142  
143 21 my @paths = map $self->class->new($_),
144 CORE::glob +File::Spec->catfile($self->absolute, $expr);
145  
146 21 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 20 1 21
147 }
148  
149 sub is_absolute {
150 2 ▶ my ($self) = @_;
Subroutine is_absolute: called CC=1 SCAR=0.0
Pod documented
151  
152 2 require File::Spec;
153  
154 2 return int!!(File::Spec->file_name_is_absolute($self->get));
155 }
156  
157 sub is_directory {
158 40 ▶ my ($self) = @_;
Subroutine is_directory: called CC=2 SCAR=7.0
Pod documented
159  
160 40 my $path = $self->get;
161  
162 40 ▶ return int!!(-e $path && -d $path);
Condition66%2/3
-e $path && -d $path
!ll&&!rl&&r
0391
MC/DC50%1/2
-e $path && -d $path
-e $path -d $path
Truth table66%2/3
A && B
A= -e $pathB= -d $path
ABresult
0X0
100
111
163 }
164  
165 sub is_file {
166 11 ▶ my ($self) = @_;
Subroutine is_file: called CC=2 SCAR=6.9
Pod documented
167  
168 11 my $path = $self->get;
169  
170 11 ▶ return int!!(-e $path && !-d $path);
Condition100%3/3
-e $path && !(-d $path)
!ll&&!rl&&r
335
MC/DC100%2/2
-e $path && !(-d $path)
-e $path !(-d $path)
Truth table100%3/3
A && not(B)
A= -e $pathB= !(-d $path)
ABresult
0X0
100
111
171 }
172  
173 sub is_relative {
174 1 ▶ my ($self) = @_;
Subroutine is_relative: called CC=1 SCAR=0.0
Pod documented
175  
176 1 return int!$self->is_absolute;
177 }
178  
179 sub lineage {
180 6 ▶ my ($self) = @_;
Subroutine lineage: called CC=2 SCAR=6.9
Pod documented
181  
182 6 require File::Spec;
183  
184 6 my @parts = File::Spec->splitdir($self->get);
185  
186 6 my @paths = ((
187 reverse map $self->class->new(File::Spec->catfile(@parts[0..$_])), 1..$#parts
188 ), $self->class->new($parts[0]));
189  
190 6 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 1 6
191 }
192  
193 sub open {
194 11 ▶ my ($self, @args) = @_;
Subroutine open: called CC=2 SCAR=6.9
Pod documented
195  
196 11 my $path = $self->get;
197  
198 11 require IO::File;
199  
200 11 my $handle = IO::File->new;
201  
202 11 ▶ $handle->open($path, @args) or do {
Branch: 1 branch
BranchTrueFalseTotal
$handle->open($path, @args) or do { my $throw; my $error = "Can't open ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 2 9 11
203 2 my $throw;
204 2 my $error = "Can't open $path: $!";
205 2 $throw = $self->throw;
206 2 $throw->message($error);
207 2 $throw->stash(path => $path);
208 2 $throw->error;
209 };
210  
211 9 return $handle;
212 }
213  
214 sub mkcall {
215 3 ▶ my ($self, $args) = @_;
Subroutine mkcall: called CC=5 SCAR=16.1
Pod documented
216  
217 3 my $path = File::Spec->catfile(File::Spec->splitdir($self->get));
218  
219 3 my $result;
220  
221 3 ▶ (defined($result = ($args ? qx($path $args) : qx($path)))) or do {
Branch: 2 branches
BranchTrueFalseTotal
defined($result = $args ? `$path $args` : `$path`) or do { my $throw; my $error = "Can't mkcall ${path}: " . ($! ? "$!" : "exit code ($?)"); $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 1 2 3
$args ? : 2 1 3
222 1 my $throw;
223 1 ▶ my $error = "Can't mkcall $path: " . ($! ? "$!" : "exit code ($?)");
Branch: 1 branch
BranchTrueFalseTotal
$! ? : 1 0 1
224 1 $throw = $self->throw;
225 1 $throw->message($error);
226 1 $throw->stash(path => $path);
227 1 $throw->error;
228 };
229  
230 2 chomp $result;
231  
232 2 ▶ return wantarray ? ($result, $?) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
233 }
234  
235 sub mkdir {
236 10 ▶ my ($self, $mode) = @_;
Subroutine mkdir: called CC=3 SCAR=11.0
Pod documented
237  
238 10 my $path = $self->get;
239  
240 10 ▶ ($mode ? CORE::mkdir($path, $mode) : CORE::mkdir($path)) or do {
Branch: 2 branches
BranchTrueFalseTotal
$mode ? CORE::mkdir($path, $mode) : CORE::mkdir($path) or do { my $throw; my $error = "Can't mkdir ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 2 8 10
$mode ? : 0 10 10
241 2 my $throw;
242 2 my $error = "Can't mkdir $path: $!";
243 2 $throw = $self->throw;
244 2 $throw->message($error);
245 2 $throw->stash(path => $path);
246 2 $throw->error;
247 };
248  
249 8 return $self;
250 }
251  
252 sub mkdirs {
253 4 ▶ my ($self, $mode) = @_;
Subroutine mkdirs: called CC=5 SCAR=16.3
Pod documented
254  
255 4 my @paths;
256  
257 4 ▶ for my $path (
Branch: 1 branch
BranchTrueFalseTotal
$self->is_file ? : 0 4 4
258 grep !!$_, reverse($self->parents), ($self->is_file ? () : $self)
259 )
260 {
261 12 ▶ if ($path->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->exists) { } 7 5 12
262 7 next;
263 }
264 else {
265 5 push @paths, $path->mkdir($mode);
266 }
267 }
268  
269 4 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
270 }
271  
272 sub mkfile {
273 8 ▶ my ($self) = @_;
Subroutine mkfile: called CC=3 SCAR=13.2
Pod documented
274  
275 8 my $path = $self->get;
276  
277 8 ▶ return $self if $self->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $self->exists 1 7 8
278  
279 7 $self->open('>');
280  
281 6 ▶ CORE::utime(undef, undef, $path) or do {
Branch: 1 branch
BranchTrueFalseTotal
utime undef, undef, $path or do { my $throw; my $error = "Can't mkfile ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 0 6 6
282 0 my $throw;
283 0 my $error = "Can't mkfile $path: $!";
284 0 $throw = $self->throw;
285 0 $throw->message($error);
286 0 $throw->stash(path => $path);
287 0 $throw->error;
288 };
289  
290 6 return $self;
291 }
292  
293 sub name {
294 1 ▶ my ($self) = @_;
Subroutine name: called CC=1 SCAR=0.0
Pod documented
295  
296 1 return $self->absolute->get;
297 }
298  
299 sub parent {
300 4 ▶ my ($self) = @_;
Subroutine parent: called CC=2 SCAR=7.0
Pod documented
301  
302 4 require File::Spec;
303  
304 4 my @parts = File::Spec->splitdir($self->get);
305  
306 4 my $path = File::Spec->catfile(@parts[0..$#parts-1]);
307  
308 4 ▶ return defined $path ? $self->class->new($path) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $path ? : 4 0 4
309 }
310  
311 sub parents {
312 5 ▶ my ($self) = @_;
Subroutine parents: called CC=3 SCAR=11.0
Pod documented
313  
314 5 my @paths = $self->lineage;
315  
316 5 ▶ @paths = @paths[1..$#paths] if @paths;
Branch: 1 branch
BranchTrueFalseTotal
if @paths 5 0 5
317  
318 5 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
319 }
320  
321 sub parts {
322 1 ▶ my ($self) = @_;
Subroutine parts: called CC=1 SCAR=0.0
Pod documented
323  
324 1 require File::Spec;
325  
326 1 return [File::Spec->splitdir($self->get)];
327 }
328  
329 sub read {
330 3993 ▶ my ($self, $binmode) = @_;
Subroutine read: called CC=7 SCAR=24.8
Pod documented
331  
332 3993 my $path = $self->get;
333  
334 3993 ▶ CORE::open(my $handle, '<', $path) or do {
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $handle, "<", $path or do { my $throw; my $error = "Can't read ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 1 3992 3993
335 1 my $throw;
336 1 my $error = "Can't read $path: $!";
337 1 $throw = $self->throw;
338 1 $throw->message($error);
339 1 $throw->stash(path => $path);
340 1 $throw->error;
341 };
342  
343 3992 ▶ CORE::binmode($handle, $binmode) or do {
Branch: 1 branch
BranchTrueFalseTotal
if defined $binmode 0 3992 3992
Condition20%1/5
defined $binmode && (binmode($handle, $binmode) || do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash('binmode', $binmode); $throw->stash('path', $path); $throw->error })
!ll
39920
binmode $handle, $binmode or do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $binmode && (binmode($handle, $binmode) || do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash('binmode', $binmode); $throw->stash('path', $path); $throw->error })
defined $binmode binmode $handle, $binmode do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
Truth table0%0/4
A && B or C
A= defined $binmodeB= binmode $handle, $binmodeC= do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
ABCresult
0XX0
1000
11X1
1011
344 0 my $throw;
345 0 my $error = "Can't binmode $path: $!";
346 0 $throw = $self->throw;
347 0 $throw->message($error);
348 0 $throw->stash(binmode => $binmode);
349 0 $throw->stash(path => $path);
350 0 $throw->error;
351 }
352 if defined($binmode);
353  
354 3992 my $result = my $content = '';
355  
356 3992 ▶ while ($result = $handle->sysread(my $buffer, 131072, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result = $handle->sysread(my $buffer, 131072, 0)) 3992 3992 7984
357 3992 $content .= $buffer;
358 }
359  
360 3992 ▶ if (not(defined($result))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 3992 3992
361 0 my $throw;
362 0 my $error = "Can't read from file $path: $!";
363 0 $throw = $self->throw;
364 0 $throw->message($error);
365 0 $throw->stash(path => $path);
366 0 $throw->error;
367 }
368  
369 3992 ▶ if ($^O =~ /win32/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /win32/iu) 0 3992 3992
370 0 $content =~ s/\015\012/\012/g;
371 }
372  
373 3992 return $content;
374 }
375  
376 sub relative {
377 2 ▶ my ($self, $path) = @_;
Subroutine relative: called CC=2 SCAR=7.4
Pod documented
378  
379 2 require File::Spec;
380  
381 2 ▶ $path ||= $self->default;
Condition33%1/3
$path ||= $self->default
l!l&&r!l&&!r
200
MC/DC0%0/2
$path ||= $self->default
$path $self->default
Truth table33%1/3
A ||= B
A= $pathB= $self->default
ABresult
1X1
011
000
382  
383 2 return $self->class->new(File::Spec->abs2rel($self->get, $path));
384 }
385  
386 sub rmdir {
387 3 ▶ my ($self) = @_;
Subroutine rmdir: called CC=2 SCAR=10.3
Pod documented
388  
389 3 my $path = $self->get;
390  
391 3 ▶ CORE::rmdir($path) or do {
Branch: 1 branch
BranchTrueFalseTotal
CORE::rmdir $path or do { my $throw; my $error = "Can't rmdir ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 0 3 3
392 0 my $throw;
393 0 my $error = "Can't rmdir $path: $!";
394 0 $throw = $self->throw;
395 0 $throw->message($error);
396 0 $throw->stash(path => $path);
397 0 $throw->error;
398 };
399  
400 3 return $self;
401 }
402  
403 sub rmdirs {
404 2 ▶ my ($self) = @_;
Subroutine rmdirs: called CC=4 SCAR=14.0
Pod documented
405  
406 2 my @paths;
407  
408 2 for my $path ($self->children) {
409 1 ▶ if ($path->is_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file) { } 0 1 1
410 0 push @paths, $path->unlink;
411 }
412 else {
413 1 push @paths, $path->rmdirs;
414 }
415 }
416  
417 2 push @paths, $self->rmdir;
418  
419 2 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
420 }
421  
422 sub rmfiles {
423 1 ▶ my ($self) = @_;
Subroutine rmfiles: called CC=4 SCAR=14.6
Pod documented
424  
425 1 my @paths;
426  
427 1 for my $path ($self->children) {
428 5 ▶ if ($path->is_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file) { } 5 0 5
429 5 push @paths, $path->unlink;
430 }
431 else {
432 0 push @paths, $path->rmfiles;
433 }
434 }
435  
436 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
437 }
438  
439 sub sibling {
440 1 ▶ my ($self, $path) = @_;
Subroutine sibling: called CC=1 SCAR=0.0
Pod documented
441  
442 1 require File::Basename;
443 1 require File::Spec;
444  
445 1 return $self->class->new(File::Spec->catfile(
446 File::Basename::dirname($self->get), $path));
447 }
448  
449 sub siblings {
450 1 ▶ my ($self) = @_;
Subroutine siblings: called CC=2 SCAR=7.0
Pod documented
451  
452 1 my @paths = map $self->parent->glob($_), '.??*', '*';
453  
454 1 my %seen = ($self->absolute, 1);
455  
456 1 @paths = grep !$seen{$_}++, @paths;
457  
458 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
459 }
460  
461 sub test {
462 2 ▶ my ($self, $spec) = @_;
Subroutine test: called CC=2 SCAR=6.9
Pod documented
463  
464 return eval(
465 2 ▶ join(' ', map("-$_", grep(/^[a-zA-Z]$/, split(//, $spec || 'e'))), '$self')
Condition100%2/2
$spec || 'e'
l!l
11
MC/DC100%1/1
$spec || 'e'
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
466 );
467 }
468  
469 sub unlink {
470 8 ▶ my ($self) = @_;
Subroutine unlink: called CC=2 SCAR=6.9
Pod documented
471  
472 8 my $path = $self->get;
473  
474 8 ▶ CORE::unlink($path) or do {
Branch: 1 branch
BranchTrueFalseTotal
CORE::unlink $path or do { my $throw; my $error = "Can't unlink ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 1 7 8
475 1 my $throw;
476 1 my $error = "Can't unlink $path: $!";
477 1 $throw = $self->throw;
478 1 $throw->message($error);
479 1 $throw->stash(path => $path);
480 1 $throw->error;
481 };
482  
483 7 return $self;
484 }
485  
486 sub write {
487 3 ▶ my ($self, $data, $binmode) = @_;
Subroutine write: called CC=6 SCAR=24.5
Pod documented
488  
489 3 my $path = $self->get;
490  
491 3 ▶ CORE::open(my $handle, '>', $path) or do {
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $handle, ">", $path or do { my $throw; my $error = "Can't write ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 1 2 3
492 1 my $throw;
493 1 my $error = "Can't write $path: $!";
494 1 $throw = $self->throw;
495 1 $throw->message($error);
496 1 $throw->stash(path => $path);
497 1 $throw->error;
498 };
499  
500 2 ▶ CORE::binmode($handle, $binmode) or do {
Branch: 1 branch
BranchTrueFalseTotal
if defined $binmode 0 2 2
Condition16%1/6
defined $binmode && (binmode($handle, $binmode) || do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash('binmode', $binmode); $throw->stash('path', $path); $throw->error })
!ll&&!rl&&r
200
binmode $handle, $binmode or do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $binmode && (binmode($handle, $binmode) || do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash('binmode', $binmode); $throw->stash('path', $path); $throw->error })
defined $binmode binmode $handle, $binmode do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
Truth table0%0/4
A && B or C
A= defined $binmodeB= binmode $handle, $binmodeC= do { my $throw; my $error = "Can't binmode ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("binmode", $binmode); $throw->stash("path", $path); $throw->error }
ABCresult
0XX0
1000
11X1
1011
501 0 my $throw;
502 0 my $error = "Can't binmode $path: $!";
503 0 $throw = $self->throw;
504 0 $throw->message($error);
505 0 $throw->stash(binmode => $binmode);
506 0 $throw->stash(path => $path);
507 0 $throw->error;
508 }
509 if defined($binmode);
510  
511 2 ▶ (($handle->syswrite($data) // -1) == length($data)) or do {
Branch: 1 branch
BranchTrueFalseTotal
($handle->syswrite($data) // -1) == length $data or do { my $throw; my $error = "Can't write to file ${path}: $!"; $throw = $self->throw; $throw->message($error); $throw->stash("path", $path); $throw->error } 0 2 2
Condition50%1/2
$handle->syswrite($data) // -1
l!l
20
MC/DC0%0/1
$handle->syswrite($data) // -1
$handle->syswrite($data)
Truth table50%1/2
A
A= $handle->syswrite($data)
Aresult
11
00
512 0 my $throw;
513 0 my $error = "Can't write to file $path: $!";
514 0 $throw = $self->throw;
515 0 $throw->message($error);
516 0 $throw->stash(path => $path);
517 0 $throw->error;
518 };
519  
520 2 return $self;
521 }
522  
523 61 1;
524  
525  
526  
527 =head1 NAME
528  
529 Venus::Path - Path Class
530  
531 =cut
532  
533 =head1 ABSTRACT
534  
535 Path Class for Perl 5
536  
537 =cut
538  
539 =head1 SYNOPSIS
540  
541 package main;
542  
543 use Venus::Path;
544  
545 my $path = Venus::Path->new('t/data/planets');
546  
547 # my $planets = $path->files;
548 # my $mercury = $path->child('mercury');
549 # my $content = $mercury->read;
550  
551 =cut
552  
553 =head1 DESCRIPTION
554  
555 This package provides methods for working with file system paths.
556  
557 =cut
558  
559 =head1 INHERITS
560  
561 This package inherits behaviors from:
562  
563 L<Venus::Kind::Utility>
564  
565 =cut
566  
567 =head1 INTEGRATES
568  
569 This package integrates behaviors from:
570  
571 L<Venus::Role::Accessible>
572  
573 L<Venus::Role::Explainable>
574  
575 =cut
576  
577 =head1 METHODS
578  
579 This package provides the following methods:
580  
581 =cut
582  
583 =head2 absolute
584  
585 absolute() (Path)
586  
587 The absolute method returns a path object where the value (path) is absolute.
588  
589 I<Since C<0.01>>
590  
591 =over 4
592  
593 =item absolute example 1
594  
595 # given: synopsis;
596  
597 $path = $path->absolute;
598  
599 # bless({ value => "/path/to/t/data/planets" }, "Venus::Path")
600  
601 =back
602  
603 =cut
604  
605 =head2 basename
606  
607 basename() (Str)
608  
609 The basename method returns the path base name.
610  
611 I<Since C<0.01>>
612  
613 =over 4
614  
615 =item basename example 1
616  
617 # given: synopsis;
618  
619 my $basename = $path->basename;
620  
621 # planets
622  
623 =back
624  
625 =cut
626  
627 =head2 child
628  
629 child(Str $path) (Path)
630  
631 The child method returns a path object representing the child path provided.
632  
633 I<Since C<0.01>>
634  
635 =over 4
636  
637 =item child example 1
638  
639 # given: synopsis;
640  
641 $path = $path->child('earth');
642  
643 # bless({ value => "t/data/planets/earth" }, "Venus::Path")
644  
645 =back
646  
647 =cut
648  
649 =head2 children
650  
651 children() (ArrayRef[Path])
652  
653 The children method returns the files and directories under the path. This
654 method can return a list of values in list-context.
655  
656 I<Since C<0.01>>
657  
658 =over 4
659  
660 =item children example 1
661  
662 # given: synopsis;
663  
664 my $children = $path->children;
665  
666 # [
667 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
668 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
669 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
670 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
671 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
672 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
673 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
674 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
675 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
676 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
677 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
678 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
679 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
680 # ]
681  
682 =back
683  
684 =cut
685  
686 =head2 chmod
687  
688 chmod(Str $mode) (Path)
689  
690 The chmod method changes the file permissions of the file or directory.
691  
692 I<Since C<0.01>>
693  
694 =over 4
695  
696 =item chmod example 1
697  
698 # given: synopsis;
699  
700 $path = $path->chmod(0755);
701  
702 # bless({ value => "t/data/planets" }, "Venus::Path")
703  
704 =back
705  
706 =cut
707  
708 =head2 chown
709  
710 chown(Str @args) (Path)
711  
712 The chown method changes the group and/or owner or the file or directory.
713  
714 I<Since C<0.01>>
715  
716 =over 4
717  
718 =item chown example 1
719  
720 # given: synopsis;
721  
722 $path = $path->chown(-1, -1);
723  
724 # bless({ value => "t/data/planets" }, "Venus::Path")
725  
726 =back
727  
728 =cut
729  
730 =head2 default
731  
732 default() (Str)
733  
734 The default method returns the default value, i.e. C<$ENV{PWD}>.
735  
736 I<Since C<0.01>>
737  
738 =over 4
739  
740 =item default example 1
741  
742 # given: synopsis;
743  
744 my $default = $path->default;
745  
746 # $ENV{PWD}
747  
748 =back
749  
750 =cut
751  
752 =head2 directories
753  
754 directories() (ArrayRef[Path])
755  
756 The directories method returns a list of children under the path which are
757 directories. This method can return a list of values in list-context.
758  
759 I<Since C<0.01>>
760  
761 =over 4
762  
763 =item directories example 1
764  
765 # given: synopsis;
766  
767 my $directories = $path->directories;
768  
769 # []
770  
771 =back
772  
773 =cut
774  
775 =head2 exists
776  
777 exists() (Bool)
778  
779 The exists method returns truthy or falsy if the path exists.
780  
781 I<Since C<0.01>>
782  
783 =over 4
784  
785 =item exists example 1
786  
787 # given: synopsis;
788  
789 my $exists = $path->exists;
790  
791 # 1
792  
793 =back
794  
795 =over 4
796  
797 =item exists example 2
798  
799 # given: synopsis;
800  
801 my $exists = $path->child('random')->exists;
802  
803 # 0
804  
805 =back
806  
807 =cut
808  
809 =head2 explain
810  
811 explain() (Str)
812  
813 The explain method returns the path string and is used in stringification
814 operations.
815  
816 I<Since C<0.01>>
817  
818 =over 4
819  
820 =item explain example 1
821  
822 # given: synopsis;
823  
824 my $explain = $path->explain;
825  
826 # t/data/planets
827  
828 =back
829  
830 =cut
831  
832 =head2 files
833  
834 files() (ArrayRef[Path])
835  
836 The files method returns a list of children under the path which are files.
837 This method can return a list of values in list-context.
838  
839 I<Since C<0.01>>
840  
841 =over 4
842  
843 =item files example 1
844  
845 # given: synopsis;
846  
847 my $files = $path->files;
848  
849 # [
850 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
851 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
852 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
853 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
854 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
855 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
856 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
857 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
858 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
859 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
860 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
861 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
862 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
863 # ]
864  
865 =back
866  
867 =cut
868  
869 =head2 find
870  
871 find(Str | Regexp $expr) (ArrayRef[Path])
872  
873 The find method does a recursive depth-first search and returns a list of paths
874 found, matching the expression provided, which defaults to C<*>. This method
875 can return a list of values in list-context.
876  
877 I<Since C<0.01>>
878  
879 =over 4
880  
881 =item find example 1
882  
883 # given: synopsis;
884  
885 my $find = $path->find;
886  
887 # [
888 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
889 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
890 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
891 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
892 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
893 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
894 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
895 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
896 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
897 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
898 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
899 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
900 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
901 # ]
902  
903 =back
904  
905 =over 4
906  
907 =item find example 2
908  
909 # given: synopsis;
910  
911 my $find = $path->find('[:\/\\\.]+m[^:\/\\\.]*$');
912  
913 # [
914 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
915 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
916 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
917 # ]
918  
919 =back
920  
921 =over 4
922  
923 =item find example 3
924  
925 # given: synopsis;
926  
927 my $find = $path->find('earth');
928  
929 # [
930 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
931 # ]
932  
933 =back
934  
935 =cut
936  
937 =head2 glob
938  
939 glob(Str | Regexp $expr) (ArrayRef[Path])
940  
941 The glob method returns the files and directories under the path matching the
942 expression provided, which defaults to C<*>. This method can return a list of
943 values in list-context.
944  
945 I<Since C<0.01>>
946  
947 =over 4
948  
949 =item glob example 1
950  
951 # given: synopsis;
952  
953 my $glob = $path->glob;
954  
955 # [
956 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
957 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
958 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
959 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
960 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
961 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
962 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
963 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
964 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
965 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
966 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
967 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
968 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
969 # ]
970  
971 =back
972  
973 =cut
974  
975 =head2 is_absolute
976  
977 is_absolute() (Bool)
978  
979 The is_absolute method returns truthy or falsy is the path is absolute.
980  
981 I<Since C<0.01>>
982  
983 =over 4
984  
985 =item is_absolute example 1
986  
987 # given: synopsis;
988  
989 my $is_absolute = $path->is_absolute;
990  
991 # 0
992  
993 =back
994  
995 =cut
996  
997 =head2 is_directory
998  
999 is_directory() (Bool)
1000  
1001 The is_directory method returns truthy or falsy is the path is a directory.
1002  
1003 I<Since C<0.01>>
1004  
1005 =over 4
1006  
1007 =item is_directory example 1
1008  
1009 # given: synopsis;
1010  
1011 my $is_directory = $path->is_directory;
1012  
1013 # 1
1014  
1015 =back
1016  
1017 =cut
1018  
1019 =head2 is_file
1020  
1021 is_file() (Bool)
1022  
1023 The is_file method returns truthy or falsy is the path is a file.
1024  
1025 I<Since C<0.01>>
1026  
1027 =over 4
1028  
1029 =item is_file example 1
1030  
1031 # given: synopsis;
1032  
1033 my $is_file = $path->is_file;
1034  
1035 # 0
1036  
1037 =back
1038  
1039 =cut
1040  
1041 =head2 is_relative
1042  
1043 is_relative() (Bool)
1044  
1045 The is_relative method returns truthy or falsy is the path is relative.
1046  
1047 I<Since C<0.01>>
1048  
1049 =over 4
1050  
1051 =item is_relative example 1
1052  
1053 # given: synopsis;
1054  
1055 my $is_relative = $path->is_relative;
1056  
1057 # 1
1058  
1059 =back
1060  
1061 =cut
1062  
1063 =head2 lineage
1064  
1065 lineage() (ArrayRef[Path])
1066  
1067 The lineage method returns the list of parent paths up to the root path. This
1068 method can return a list of values in list-context.
1069  
1070 I<Since C<0.01>>
1071  
1072 =over 4
1073  
1074 =item lineage example 1
1075  
1076 # given: synopsis;
1077  
1078 my $lineage = $path->lineage;
1079  
1080 # [
1081 # bless({ value => "t/data/planets" }, "Venus::Path"),
1082 # bless({ value => "t/data" }, "Venus::Path"),
1083 # bless({ value => "t" }, "Venus::Path"),
1084 # ]
1085  
1086 =back
1087  
1088 =cut
1089  
1090 =head2 mkcall
1091  
1092 mkcall(Any @data) (Any)
1093  
1094 The mkcall method returns the result of executing the path as an executable. In
1095 list context returns the call output and exit code.
1096  
1097 I<Since C<0.01>>
1098  
1099 =over 4
1100  
1101 =item mkcall example 1
1102  
1103 package main;
1104  
1105 use Venus::Path;
1106  
1107 my $path = Venus::Path->new($^X);
1108  
1109 my $output = $path->mkcall('--help');
1110  
1111 # Usage: perl ...
1112  
1113 =back
1114  
1115 =over 4
1116  
1117 =item mkcall example 2
1118  
1119 package main;
1120  
1121 use Venus::Path;
1122  
1123 my $path = Venus::Path->new($^X);
1124  
1125 my ($call_output, $exit_code) = $path->mkcall('t/data/sun --heat-death');
1126  
1127 # ("", 256)
1128  
1129 =back
1130  
1131 =over 4
1132  
1133 =item mkcall example 3
1134  
1135 package main;
1136  
1137 use Venus::Path;
1138  
1139 my $path = Venus::Path->new('.help');
1140  
1141 my $output = $path->mkcall;
1142  
1143 # Exception! Venus::Path::Error (isa Venus::Error)
1144  
1145 =back
1146  
1147 =cut
1148  
1149 =head2 mkdir
1150  
1151 mkdir(Maybe[Str] $mode) (Path)
1152  
1153 The mkdir method makes the path as a directory.
1154  
1155 I<Since C<0.01>>
1156  
1157 =over 4
1158  
1159 =item mkdir example 1
1160  
1161 package main;
1162  
1163 use Venus::Path;
1164  
1165 my $path = Venus::Path->new('t/data/systems');
1166  
1167 $path = $path->mkdir;
1168  
1169 # bless({ value => "t/data/systems" }, "Venus::Path")
1170  
1171 =back
1172  
1173 =over 4
1174  
1175 =item mkdir example 2
1176  
1177 package main;
1178  
1179 use Venus::Path;
1180  
1181 my $path = Venus::Path->new('/path/to/xyz');
1182  
1183 $path = $path->mkdir;
1184  
1185 # Exception! Venus::Path::Error (isa Venus::Error)
1186  
1187 =back
1188  
1189 =cut
1190  
1191 =head2 mkdirs
1192  
1193 mkdirs(Maybe[Str] $mode) (ArrayRef[Path])
1194  
1195 The mkdirs method creates parent directories and returns the list of created
1196 directories. This method can return a list of values in list-context.
1197  
1198 I<Since C<0.01>>
1199  
1200 =over 4
1201  
1202 =item mkdirs example 1
1203  
1204 package main;
1205  
1206 use Venus::Path;
1207  
1208 my $path = Venus::Path->new('t/data/systems');
1209  
1210 my $mkdirs = $path->mkdirs;
1211  
1212 # [
1213 # bless({ value => "t/data/systems" }, "Venus::Path")
1214 # ]
1215  
1216 =back
1217  
1218 =over 4
1219  
1220 =item mkdirs example 2
1221  
1222 package main;
1223  
1224 use Venus::Path;
1225  
1226 my $path = Venus::Path->new('t/data/systems/solar');
1227  
1228 my $mkdirs = $path->mkdirs;
1229  
1230 # [
1231 # bless({ value => "t/data/systems" }, "Venus::Path"),
1232 # bless({ value => "t/data/systems/solar" }, "Venus::Path"),
1233 # ]
1234  
1235 =back
1236  
1237 =cut
1238  
1239 =head2 mkfile
1240  
1241 mkfile() (Path)
1242  
1243 The mkfile method makes the path as an empty file.
1244  
1245 I<Since C<0.01>>
1246  
1247 =over 4
1248  
1249 =item mkfile example 1
1250  
1251 package main;
1252  
1253 use Venus::Path;
1254  
1255 my $path = Venus::Path->new('t/data/moon');
1256  
1257 $path = $path->mkfile;
1258  
1259 # bless({ value => "t/data/moon" }, "Venus::Path")
1260  
1261 =back
1262  
1263 =over 4
1264  
1265 =item mkfile example 2
1266  
1267 package main;
1268  
1269 use Venus::Path;
1270  
1271 my $path = Venus::Path->new('/path/to/xyz');
1272  
1273 $path = $path->mkfile;
1274  
1275 # Exception! Venus::Path::Error (isa Venus::Error)
1276  
1277 =back
1278  
1279 =cut
1280  
1281 =head2 name
1282  
1283 name() (Str)
1284  
1285 The name method returns the path as an absolute path.
1286  
1287 I<Since C<0.01>>
1288  
1289 =over 4
1290  
1291 =item name example 1
1292  
1293 # given: synopsis;
1294  
1295 my $name = $path->name;
1296  
1297 # /path/to/t/data/planets
1298  
1299 =back
1300  
1301 =cut
1302  
1303 =head2 open
1304  
1305 open(Any @data) (FileHandle)
1306  
1307 The open method creates and returns an open filehandle.
1308  
1309 I<Since C<0.01>>
1310  
1311 =over 4
1312  
1313 =item open example 1
1314  
1315 package main;
1316  
1317 use Venus::Path;
1318  
1319 my $path = Venus::Path->new('t/data/planets/earth');
1320  
1321 my $fh = $path->open;
1322  
1323 # bless(..., "IO::File");
1324  
1325 =back
1326  
1327 =over 4
1328  
1329 =item open example 2
1330  
1331 package main;
1332  
1333 use Venus::Path;
1334  
1335 my $path = Venus::Path->new('t/data/planets/earth');
1336  
1337 my $fh = $path->open('<');
1338  
1339 # bless(..., "IO::File");
1340  
1341 =back
1342  
1343 =over 4
1344  
1345 =item open example 3
1346  
1347 package main;
1348  
1349 use Venus::Path;
1350  
1351 my $path = Venus::Path->new('t/data/planets/earth');
1352  
1353 my $fh = $path->open('>');
1354  
1355 # bless(..., "IO::File");
1356  
1357 =back
1358  
1359 =over 4
1360  
1361 =item open example 4
1362  
1363 package main;
1364  
1365 use Venus::Path;
1366  
1367 my $path = Venus::Path->new('/path/to/xyz');
1368  
1369 my $fh = $path->open('>');
1370  
1371 # Exception! Venus::Path::Error (isa Venus::Error)
1372  
1373 =back
1374  
1375 =cut
1376  
1377 =head2 parent
1378  
1379 parent() (Path)
1380  
1381 The parent method returns a path object representing the parent directory.
1382  
1383 I<Since C<0.01>>
1384  
1385 =over 4
1386  
1387 =item parent example 1
1388  
1389 # given: synopsis;
1390  
1391 my $parent = $path->parent;
1392  
1393 # bless({ value => "t/data" }, "Venus::Path")
1394  
1395 =back
1396  
1397 =cut
1398  
1399 =head2 parents
1400  
1401 parents() (ArrayRef[Path])
1402  
1403 The parents method returns is a list of parent directories. This method can
1404 return a list of values in list-context.
1405  
1406 I<Since C<0.01>>
1407  
1408 =over 4
1409  
1410 =item parents example 1
1411  
1412 # given: synopsis;
1413  
1414 my $parents = $path->parents;
1415  
1416 # [
1417 # bless({ value => "t/data" }, "Venus::Path"),
1418 # bless({ value => "t" }, "Venus::Path"),
1419 # ]
1420  
1421 =back
1422  
1423 =cut
1424  
1425 =head2 parts
1426  
1427 parts() (ArrayRef[Str])
1428  
1429 The parts method returns an arrayref of path parts.
1430  
1431 I<Since C<0.01>>
1432  
1433 =over 4
1434  
1435 =item parts example 1
1436  
1437 # given: synopsis;
1438  
1439 my $parts = $path->parts;
1440  
1441 # ["t", "data", "planets"]
1442  
1443 =back
1444  
1445 =cut
1446  
1447 =head2 read
1448  
1449 read(Str $binmode) (Str)
1450  
1451 The read method reads the file and returns its contents.
1452  
1453 I<Since C<0.01>>
1454  
1455 =over 4
1456  
1457 =item read example 1
1458  
1459 package main;
1460  
1461 use Venus::Path;
1462  
1463 my $path = Venus::Path->new('t/data/planets/mars');
1464  
1465 my $content = $path->read;
1466  
1467 =back
1468  
1469 =over 4
1470  
1471 =item read example 2
1472  
1473 package main;
1474  
1475 use Venus::Path;
1476  
1477 my $path = Venus::Path->new('/path/to/xyz');
1478  
1479 my $content = $path->read;
1480  
1481 # Exception! Venus::Path::Error (isa Venus::Error)
1482  
1483 =back
1484  
1485 =cut
1486  
1487 =head2 relative
1488  
1489 relative(Str $root) (Path)
1490  
1491 The relative method returns a path object representing a relative path
1492 (relative to the path provided).
1493  
1494 I<Since C<0.01>>
1495  
1496 =over 4
1497  
1498 =item relative example 1
1499  
1500 package main;
1501  
1502 use Venus::Path;
1503  
1504 my $path = Venus::Path->new('/path/to/t/data/planets/mars');
1505  
1506 my $relative = $path->relative('/path');
1507  
1508 # bless({ value => "to/t/data/planets/mars" }, "Venus::Path")
1509  
1510 =back
1511  
1512 =over 4
1513  
1514 =item relative example 2
1515  
1516 package main;
1517  
1518 use Venus::Path;
1519  
1520 my $path = Venus::Path->new('/path/to/t/data/planets/mars');
1521  
1522 my $relative = $path->relative('/path/to/t');
1523  
1524 # bless({ value => "data/planets/mars" }, "Venus::Path")
1525  
1526 =back
1527  
1528 =cut
1529  
1530 =head2 rmdir
1531  
1532 rmdir() (Path)
1533  
1534 The rmdir method removes the directory and returns a path object representing
1535 the deleted directory.
1536  
1537 I<Since C<0.01>>
1538  
1539 =over 4
1540  
1541 =item rmdir example 1
1542  
1543 package main;
1544  
1545 use Venus::Path;
1546  
1547 my $path = Venus::Path->new('t/data/stars');
1548  
1549 my $rmdir = $path->mkdir->rmdir;
1550  
1551 # bless({ value => "t/data/stars" }, "Venus::Path")
1552  
1553 =back
1554  
1555 =over 4
1556  
1557 =item rmdir example 2
1558  
1559 package main;
1560  
1561 use Venus::Path;
1562  
1563 my $path = Venus::Path->new('/path/to/xyz');
1564  
1565 my $rmdir = $path->mkdir->rmdir;
1566  
1567 # Exception! Venus::Path::Error (isa Venus::Error)
1568  
1569 =back
1570  
1571 =cut
1572  
1573 =head2 rmdirs
1574  
1575 rmdirs() (ArrayRef[Path])
1576  
1577 The rmdirs method removes that path and its child files and directories and
1578 returns all paths removed. This method can return a list of values in
1579 list-context.
1580  
1581 I<Since C<0.01>>
1582  
1583 =over 4
1584  
1585 =item rmdirs example 1
1586  
1587 package main;
1588  
1589 use Venus::Path;
1590  
1591 my $path = Venus::Path->new('t/data/stars');
1592  
1593 $path->child('dwarfs')->mkdirs;
1594  
1595 my $rmdirs = $path->rmdirs;
1596  
1597 # [
1598 # bless({ value => "t/data/stars/dwarfs" }, "Venus::Path"),
1599 # bless({ value => "t/data/stars" }, "Venus::Path"),
1600 # ]
1601  
1602 =back
1603  
1604 =cut
1605  
1606 =head2 rmfiles
1607  
1608 rmfiles() (ArrayRef[Path])
1609  
1610 The rmfiles method recursively removes files under the path and returns the
1611 paths removed. This method does not remove the directories found. This method
1612 can return a list of values in list-context.
1613  
1614 I<Since C<0.01>>
1615  
1616 =over 4
1617  
1618 =item rmfiles example 1
1619  
1620 package main;
1621  
1622 use Venus::Path;
1623  
1624 my $path = Venus::Path->new('t/data/stars')->mkdir;
1625  
1626 $path->child('sirius')->mkfile;
1627 $path->child('canopus')->mkfile;
1628 $path->child('arcturus')->mkfile;
1629 $path->child('vega')->mkfile;
1630 $path->child('capella')->mkfile;
1631  
1632 my $rmfiles = $path->rmfiles;
1633  
1634 # [
1635 # bless({ value => "t/data/stars/arcturus" }, "Venus::Path"),
1636 # bless({ value => "t/data/stars/canopus" }, "Venus::Path"),
1637 # bless({ value => "t/data/stars/capella" }, "Venus::Path"),
1638 # bless({ value => "t/data/stars/sirius" }, "Venus::Path"),
1639 # bless({ value => "t/data/stars/vega" }, "Venus::Path"),
1640 # ]
1641  
1642 =back
1643  
1644 =cut
1645  
1646 =head2 sibling
1647  
1648 sibling(Str $path) (Path)
1649  
1650 The sibling method returns a path object representing the sibling path provided.
1651  
1652 I<Since C<0.01>>
1653  
1654 =over 4
1655  
1656 =item sibling example 1
1657  
1658 # given: synopsis;
1659  
1660 my $sibling = $path->sibling('galaxies');
1661  
1662 # bless({ value => "t/data/galaxies" }, "Venus::Path")
1663  
1664 =back
1665  
1666 =cut
1667  
1668 =head2 siblings
1669  
1670 siblings() (ArrayRef[Path])
1671  
1672 The siblings method returns all sibling files and directories for the current
1673 path. This method can return a list of values in list-context.
1674  
1675 I<Since C<0.01>>
1676  
1677 =over 4
1678  
1679 =item siblings example 1
1680  
1681 # given: synopsis;
1682  
1683 my $siblings = $path->siblings;
1684  
1685 # [
1686 # bless({ value => "t/data/moon" }, "Venus::Path"),
1687 # bless({ value => "t/data/sun" }, "Venus::Path"),
1688 # ]
1689  
1690 =back
1691  
1692 =cut
1693  
1694 =head2 test
1695  
1696 test(Str $expr) (Bool)
1697  
1698 The test method evaluates the current path against the stackable file test
1699 operators provided.
1700  
1701 I<Since C<0.01>>
1702  
1703 =over 4
1704  
1705 =item test example 1
1706  
1707 # given: synopsis;
1708  
1709 my $test = $path->test;
1710  
1711 # -e $path
1712  
1713 # 1
1714  
1715 =back
1716  
1717 =over 4
1718  
1719 =item test example 2
1720  
1721 package main;
1722  
1723 use Venus::Path;
1724  
1725 my $path = Venus::Path->new('t/data/sun');
1726  
1727 my $test = $path->test('efs');
1728  
1729 # -e -f -s $path
1730  
1731 # 1
1732  
1733 =back
1734  
1735 =cut
1736  
1737 =head2 unlink
1738  
1739 unlink() (Path)
1740  
1741 The unlink method removes the file and returns a path object representing the
1742 removed file.
1743  
1744 I<Since C<0.01>>
1745  
1746 =over 4
1747  
1748 =item unlink example 1
1749  
1750 package main;
1751  
1752 use Venus::Path;
1753  
1754 my $path = Venus::Path->new('t/data/asteroid')->mkfile;
1755  
1756 my $unlink = $path->unlink;
1757  
1758 # bless({ value => "t/data/asteroid" }, "Venus::Path")
1759  
1760 =back
1761  
1762 =over 4
1763  
1764 =item unlink example 2
1765  
1766 package main;
1767  
1768 use Venus::Path;
1769  
1770 my $path = Venus::Path->new('/path/to/xyz');
1771  
1772 my $unlink = $path->unlink;
1773  
1774 # Exception! Venus::Path::Error (isa Venus::Error)
1775  
1776 =back
1777  
1778 =cut
1779  
1780 =head2 write
1781  
1782 write(Str $data, Str $binmode) (Path)
1783  
1784 The write method write the data provided to the file.
1785  
1786 I<Since C<0.01>>
1787  
1788 =over 4
1789  
1790 =item write example 1
1791  
1792 package main;
1793  
1794 use Venus::Path;
1795  
1796 my $path = Venus::Path->new('t/data/asteroid');
1797  
1798 my $write = $path->write('asteroid');
1799  
1800 =back
1801  
1802 =over 4
1803  
1804 =item write example 2
1805  
1806 package main;
1807  
1808 use Venus::Path;
1809  
1810 my $path = Venus::Path->new('/path/to/xyz');
1811  
1812 my $write = $path->write('nothing');
1813  
1814 # Exception! Venus::Path::Error (isa Venus::Error)
1815  
1816 =back
1817  
1818 =cut
1819  
1820 =head1 OPERATORS
1821  
1822 This package overloads the following operators:
1823  
1824 =cut
1825  
1826 =over 4
1827  
1828 =item operation: C<(.)>
1829  
1830 This package overloads the C<.> operator.
1831  
1832 B<example 1>
1833  
1834 # given: synopsis;
1835  
1836 my $result = $path . '/earth';
1837  
1838 # "t/data/planets/earth"
1839  
1840 =back
1841  
1842 =over 4
1843  
1844 =item operation: C<(eq)>
1845  
1846 This package overloads the C<eq> operator.
1847  
1848 B<example 1>
1849  
1850 # given: synopsis;
1851  
1852 my $result = $path eq 't/data/planets';
1853  
1854 # 1
1855  
1856 =back
1857  
1858 =over 4
1859  
1860 =item operation: C<(ne)>
1861  
1862 This package overloads the C<ne> operator.
1863  
1864 B<example 1>
1865  
1866 # given: synopsis;
1867  
1868 my $result = $path ne 't/data/planets/';
1869  
1870 # 1
1871  
1872 =back
1873  
1874 =over 4
1875  
1876 =item operation: C<(qr)>
1877  
1878 This package overloads the C<qr> operator.
1879  
1880 B<example 1>
1881  
1882 # given: synopsis;
1883  
1884 my $result = 't/data/planets' =~ $path;
1885  
1886 # 1
1887  
1888 =back
1889  
1890 =over 4
1891  
1892 =item operation: C<("")>
1893  
1894 This package overloads the C<""> operator.
1895  
1896 B<example 1>
1897  
1898 # given: synopsis;
1899  
1900 my $result = "$path";
1901  
1902 # "t/data/planets"
1903  
1904 =back
1905  
1906 =over 4
1907  
1908 =item operation: C<(~~)>
1909  
1910 This package overloads the C<~~> operator.
1911  
1912 B<example 1>
1913  
1914 # given: synopsis;
1915  
1916 my $result = $path ~~ 't/data/planets';
1917  
1918 # 1
1919  
1920 =back
« Venus/Hash.pm ↑ Summary Venus/Box.pm »