blib/lib/Venus/Path.pm

filter: Statementstmt 98.7% 304 / 308 Branchbran 75.5% 74 / 98 Conditioncond 56.7% 21 / 37 MC/DCmcdc 38.1% 8 / 21 Subroutinesub 100% 71 / 71 Podpod 100% 61 / 61 totaltotal 90.4% 539 / 596 SCAR 42.8
CC
68
Cov
90%
write
8.8
read
7.9
find
5.2
CRAP 72.5
« blib/lib/Venus/Array.pm ↑ Summary blib/lib/Venus/Type.pm »
1 package Venus::Path;
2  
3 96 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 96 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 96 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 96 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 96 base 'Venus::Kind::Utility';
11  
12 96 with 'Venus::Role::Valuable';
13 96 with 'Venus::Role::Buildable';
14 96 with 'Venus::Role::Accessible';
15 96 with 'Venus::Role::Explainable';
16  
17 use overload (
18 '""' => 'explain',
19 1 ▶ 'eq' => sub{$_[0]->value eq "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶ 'ne' => sub{$_[0]->value ne "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 ▶ 'qr' => sub{qr/@{[quotemeta($_[0]->value)]}/},
Subroutine __ANON__: called CC=1 SCAR=0.0
22 96 '~~' => 'explain',
23 fallback => 1,
24 96 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # HOOKS
27  
28 sub _exitcode {
29 6 ▶ $? >> 8;
Subroutine _exitcode: called CC=1 SCAR=0.0
30 }
31  
32 # METHODS
33  
34 sub assertion {
35 2 ▶ my ($self) = @_;
Subroutine assertion: called CC=1 SCAR=0.2
Pod documented
36  
37 2 my $assertion = $self->SUPER::assertion;
38  
39 $assertion->match('string')->format(sub{
40 2 ▶ (ref $self || $self)->new($_)
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
41 2 });
42  
43 2 return $assertion;
44 }
45  
46 sub absolute {
47 76 ▶ my ($self) = @_;
Subroutine absolute: called CC=1 SCAR=0.0
Pod documented
48  
49 76 require File::Spec;
50  
51 76 return $self->class->new(File::Spec->rel2abs($self->get));
52 }
53  
54 sub basename {
55 5 ▶ my ($self) = @_;
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
56  
57 5 require File::Basename;
58  
59 5 return File::Basename::basename($self->get);
60 }
61  
62 sub child {
63 53 ▶ my ($self, $path) = @_;
Subroutine child: called CC=1 SCAR=0.0
Pod documented
64  
65 53 require File::Spec;
66  
67 53 my @parts = File::Spec->splitdir($path);
68  
69 53 return $self->class->new(File::Spec->catfile($self->get, @parts));
70 }
71  
72 sub chmod {
73 1 ▶ my ($self, $mode) = @_;
Subroutine chmod: called CC=1 SCAR=0.0
Pod documented
74  
75 1 my $path = $self->get;
76  
77 1 CORE::chmod($mode, $path);
78  
79 1 return $self;
80 }
81  
82 sub chown {
83 1 ▶ my ($self, @args) = @_;
Subroutine chown: called CC=2 SCAR=7.0
Pod documented
84  
85 1 my $path = $self->get;
86  
87 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
88  
89 1 return $self;
90 }
91  
92 sub children {
93 29 ▶ my ($self) = @_;
Subroutine children: called CC=2 SCAR=6.9
Pod documented
94  
95 29 require File::Spec;
96  
97 29 my @paths = map $self->glob($_), '.??*', '*';
98  
99 29 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 28 1 29
100 }
101  
102 sub copy {
103 1 ▶ my ($self, $path) = @_;
Subroutine copy: called CC=2 SCAR=7.0
Pod documented
104  
105 1 require File::Copy;
106  
107 1 ▶ File::Copy::copy("$self", "$path")
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy("$self", "$path") or $self->error({"throw", "error_on_copy", "error", $!, "path", $path}) 0 1 1
108 or $self->error({throw => 'error_on_copy', error => $!, path => $path});
109  
110 1 return $self;
111 }
112  
113 sub default {
114 4 ▶ require Cwd;
Subroutine default: called CC=1 SCAR=0.0
Pod documented
115  
116 4 return Cwd::getcwd();
117 }
118  
119 sub directories {
120 21 ▶ my ($self) = @_;
Subroutine directories: called CC=2 SCAR=6.9
Pod documented
121  
122 21 my @paths = grep -d, $self->children;
123  
124 21 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 20 1 21
125 }
126  
127 sub exists {
128 30 ▶ my ($self) = @_;
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
129  
130 30 return int!!-e $self->get;
131 }
132  
133 sub explain {
134 15632 ▶ my ($self) = @_;
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
135  
136 15632 return $self->get;
137 }
138  
139 sub extension {
140 4 ▶ my ($self, $value) = @_;
Subroutine extension: called CC=3 SCAR=11.0
Pod documented
141  
142 4 my $basename = $self->basename;
143  
144 4 my ($filename, $suffix) = $basename =~ /^([^\.]+)\.?(.*)$/;
145  
146 4 ▶ return $suffix || undef if !$value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 2 4
Condition100%2/2
$suffix || undef
l!l
11
MC/DC100%1/1
$suffix || undef
$suffix
Truth table100%2/2
A
A= $suffix
Aresult
11
00
147  
148 2 return $self->sibling(join '.', $filename, $value);
149 }
150  
151 sub find {
152 3 ▶ my ($self, $expr) = @_;
Subroutine find: called CC=5 SCAR=16.4
Pod documented
153  
154 3 ▶ $expr = '.*' if !$expr;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 1 2 3
155  
156 3 ▶ $expr = qr/$expr/ if ref($expr) ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $expr ne "Regexp" 3 0 3
157  
158 3 my @paths;
159  
160 push @paths, grep {
161 42 $_ =~ $expr
162 } map {
163 3 ▶ $_->is_directory ? $_->find($expr) : $_
Branch: 1 branch
BranchTrueFalseTotal
$_->is_directory ? : 0 42 42
164 }
165 $self->children;
166  
167 3 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
168 }
169  
170 sub files {
171 1 ▶ my ($self) = @_;
Subroutine files: called CC=2 SCAR=7.1
Pod documented
172  
173 1 my @paths = grep -f, $self->children;
174  
175 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
176 }
177  
178 sub glob {
179 61 ▶ my ($self, $expr) = @_;
Subroutine glob: called CC=3 SCAR=11.0
Pod documented
180  
181 61 require File::Spec;
182  
183 61 ▶ $expr ||= '*';
Condition100%2/2
$expr ||= "*"
l!l
601
MC/DC100%1/1
$expr ||= "*"
$expr
Truth table100%2/2
A
A= $expr
Aresult
11
00
184  
185 61 my @paths = map $self->class->new($_),
186 CORE::glob +File::Spec->catfile($self->absolute, $expr);
187  
188 61 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 60 1 61
189 }
190  
191 sub is_absolute {
192 4 ▶ my ($self) = @_;
Subroutine is_absolute: called CC=1 SCAR=0.0
Pod documented
193  
194 4 require File::Spec;
195  
196 4 return int!!(File::Spec->file_name_is_absolute($self->get));
197 }
198  
199 sub is_directory {
200 43 ▶ my ($self) = @_;
Subroutine is_directory: called CC=2 SCAR=7.0
Pod documented
201  
202 43 my $path = $self->get;
203  
204 43 ▶ return int!!(-e $path && -d $path);
Condition66%2/3
-e $path && -d $path
!ll&&!rl&&r
0421
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
205 }
206  
207 sub is_file {
208 11 ▶ my ($self) = @_;
Subroutine is_file: called CC=2 SCAR=6.9
Pod documented
209  
210 11 my $path = $self->get;
211  
212 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
213 }
214  
215 sub is_relative {
216 3 ▶ my ($self) = @_;
Subroutine is_relative: called CC=1 SCAR=0.0
Pod documented
217  
218 3 return int!$self->is_absolute;
219 }
220  
221 sub lines {
222 2 ▶ my ($self, $separator, $binmode) = @_;
Subroutine lines: called CC=3 SCAR=11.1
Pod documented
223  
224 2 ▶ $separator //= "\n";
Condition100%2/2
$separator //= "\n"
l!l
11
MC/DC100%1/1
$separator //= "\n"
$separator
Truth table100%2/2
A
A= $separator
Aresult
11
00
225  
226 2 ▶ return [split /$separator/, $binmode ? $self->read($binmode) : $self->read];
Branch: 1 branch
BranchTrueFalseTotal
$binmode ? : 0 2 2
227 }
228  
229 sub lineage {
230 8 ▶ my ($self) = @_;
Subroutine lineage: called CC=2 SCAR=6.9
Pod documented
231  
232 8 require File::Spec;
233  
234 8 my @parts = File::Spec->splitdir($self->get);
235  
236 8 my @paths = ((
237 reverse map $self->class->new(File::Spec->catfile(@parts[0..$_])), 1..$#parts
238 ), $self->class->new($parts[0]));
239  
240 8 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 1 8
241 }
242  
243 sub open {
244 12 ▶ my ($self, @args) = @_;
Subroutine open: called CC=2 SCAR=6.9
Pod documented
245  
246 12 my $path = $self->get;
247  
248 12 require IO::File;
249  
250 12 my $handle = IO::File->new;
251  
252 12 ▶ $handle->open($path, @args)
Branch: 1 branch
BranchTrueFalseTotal
$handle->open($path, @args) or $self->error({"throw", "error_on_open", "path", $path, "error", $!}) 2 10 12
253 or $self->error({throw => 'error_on_open', path => $path, error => $!});
254  
255 10 return $handle;
256 }
257  
258 sub mkcall {
259 7 ▶ my ($self, @args) = @_;
Subroutine mkcall: called CC=4 SCAR=13.9
Pod documented
260  
261 7 require File::Spec;
262  
263 7 my $path = File::Spec->catfile(File::Spec->splitdir($self->get));
264  
265 7 my $result;
266  
267 7 require Venus::Os;
268  
269 7 my $args = join ' ', map Venus::Os->quote($_), grep defined, @args;
270  
271 7 ▶ (defined($result = ($args ? qx($path $args) : qx($path))))
Branch: 2 branches
BranchTrueFalseTotal
defined($result = $args ? `$path $args` : `$path`) or $self->error({"throw", "error_on_mkcall", "error", $!, "exit_code", _exitcode(), "path", $path}) 1 6 7
$args ? : 6 1 7
272 or $self->error({
273 throw => 'error_on_mkcall',
274 error => $!,
275 exit_code => _exitcode(),
276 path => $path,
277 });
278  
279 6 chomp $result;
280  
281 6 ▶ return wantarray ? ($result, _exitcode()) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 1 6
282 }
283  
284 sub mkdir {
285 10 ▶ my ($self, $mode) = @_;
Subroutine mkdir: called CC=3 SCAR=11.0
Pod documented
286  
287 10 my $path = $self->get;
288  
289 10 ▶ ($mode ? CORE::mkdir($path, $mode) : CORE::mkdir($path))
Branch: 2 branches
BranchTrueFalseTotal
$mode ? CORE::mkdir($path, $mode) : CORE::mkdir($path) or $self->error({"throw", "error_on_mkdir", "error", $!, "path", $path}) 2 8 10
$mode ? : 0 10 10
290 or $self->error({
291 throw => 'error_on_mkdir',
292 error => $!,
293 path => $path,
294 });
295  
296 8 return $self;
297 }
298  
299 sub mkdirs {
300 4 ▶ my ($self, $mode) = @_;
Subroutine mkdirs: called CC=5 SCAR=16.3
Pod documented
301  
302 4 my @paths;
303  
304 4 ▶ for my $path (
Branch: 1 branch
BranchTrueFalseTotal
$self->is_file ? : 0 4 4
305 grep !!$_, reverse($self->parents), ($self->is_file ? () : $self)
306 )
307 {
308 14 ▶ if ($path->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->exists) { } 9 5 14
309 9 next;
310 }
311 else {
312 5 push @paths, $path->mkdir($mode);
313 }
314 }
315  
316 4 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
317 }
318  
319 sub mktemp_dir {
320 1 ▶ my ($self) = @_;
Subroutine mktemp_dir: called CC=1 SCAR=0.0
Pod documented
321  
322 1 require File::Temp;
323  
324 1 return $self->class->new(File::Temp::tempdir());
325 }
326  
327 sub mktemp_file {
328 1 ▶ my ($self) = @_;
Subroutine mktemp_file: called CC=1 SCAR=0.0
Pod documented
329  
330 1 require File::Temp;
331  
332 1 return $self->class->new((File::Temp::tempfile())[1]);
333 }
334  
335 sub mkfile {
336 9 ▶ my ($self) = @_;
Subroutine mkfile: called CC=3 SCAR=11.0
Pod documented
337  
338 9 my $path = $self->get;
339  
340 9 ▶ return $self if $self->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $self->exists 1 8 9
341  
342 8 $self->open('>');
343  
344 7 ▶ CORE::utime(undef, undef, $path)
Branch: 1 branch
BranchTrueFalseTotal
utime undef, undef, $path or $self->error({"throw", "error_on_mkfile", "path", $path, "error", $!}) 0 7 7
345 or $self->error({throw => 'error_on_mkfile', path => $path, error => $!});
346  
347 7 return $self;
348 }
349  
350 sub move {
351 3 ▶ my ($self, $path) = @_;
Subroutine move: called CC=2 SCAR=7.0
Pod documented
352  
353 3 require File::Copy;
354  
355 3 ▶ File::Copy::move("$self", "$path")
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::move("$self", "$path") or $self->error({"throw", "error_on_move", "path", $path, "error", $!}) 0 3 3
356 or $self->error({throw => 'error_on_move', path => $path, error => $!});
357  
358 3 return $self->class->make($path)->absolute;
359 }
360  
361 sub name {
362 1 ▶ my ($self) = @_;
Subroutine name: called CC=1 SCAR=0.0
Pod documented
363  
364 1 return $self->absolute->get;
365 }
366  
367 sub parent {
368 7 ▶ my ($self) = @_;
Subroutine parent: called CC=2 SCAR=7.0
Pod documented
369  
370 7 require File::Spec;
371  
372 7 my @parts = File::Spec->splitdir($self->get);
373  
374 7 my $path = File::Spec->catfile(@parts[0..$#parts-1]);
375  
376 7 ▶ return defined $path ? $self->class->new($path) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $path ? : 7 0 7
377 }
378  
379 sub parents {
380 5 ▶ my ($self) = @_;
Subroutine parents: called CC=3 SCAR=11.0
Pod documented
381  
382 5 my @paths = $self->lineage;
383  
384 5 ▶ @paths = @paths[1..$#paths] if @paths;
Branch: 1 branch
BranchTrueFalseTotal
if @paths 5 0 5
385  
386 5 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
387 }
388  
389 sub parts {
390 1 ▶ my ($self) = @_;
Subroutine parts: called CC=1 SCAR=0.0
Pod documented
391  
392 1 require File::Spec;
393  
394 1 return [File::Spec->splitdir($self->get)];
395 }
396  
397 sub read {
398 7608 ▶ my ($self, $binmode) = @_;
Subroutine read: called CC=7 SCAR=20.6
Pod documented
399  
400 7608 my $path = $self->get;
401  
402 7608 ▶ CORE::open(my $handle, '<', $path)
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $handle, "<", $path or $self->error({"throw", "error_on_read_open", "path", $path, "error", $!}) 1 7607 7608
403 or $self->error({throw => 'error_on_read_open', path => $path, error => $!});
404  
405 7607 ▶ CORE::binmode($handle, $binmode) or do {
Branch: 1 branch
BranchTrueFalseTotal
if defined $binmode 0 7607 7607
Condition20%1/5
defined $binmode && (binmode($handle, $binmode) || do { $self->error({'throw', 'error_on_read_binmode', 'path', $path, 'error', $!, 'binmode', $binmode}) })
!ll
76070
binmode $handle, $binmode or do { $self->error({"throw", "error_on_read_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $binmode && (binmode($handle, $binmode) || do { $self->error({'throw', 'error_on_read_binmode', 'path', $path, 'error', $!, 'binmode', $binmode}) })
defined $binmode binmode $handle, $binmode do { $self->error({"throw", "error_on_read_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
Truth table0%0/4
A && B or C
A= defined $binmodeB= binmode $handle, $binmodeC= do { $self->error({"throw", "error_on_read_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
ABCresult
0XX0
1000
11X1
1011
406 0 $self->error({
407 throw => 'error_on_read_binmode',
408 path => $path,
409 error => $!,
410 binmode => $binmode,
411 });
412 } if defined($binmode);
413  
414 7607 my $result = my $content = '';
415  
416 7607 ▶ while ($result = $handle->sysread(my $buffer, 131072, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result = $handle->sysread(my $buffer, 131072, 0)) 8726 7607 16333
417 8726 $content .= $buffer;
418 }
419  
420 7607 ▶ $self->error({throw => 'error_on_read_error', path => $path, error => $!}) if !defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 7607 7607
421  
422 7607 require Venus::Os;
423 7607 ▶ $content =~ s/\015\012/\012/g if Venus::Os->is_win;
Branch: 1 branch
BranchTrueFalseTotal
if "Venus::Os"->is_win 4 7603 7607
424  
425 7607 return $content;
426 }
427  
428 sub relative {
429 2 ▶ my ($self, $path) = @_;
Subroutine relative: called CC=2 SCAR=7.4
Pod documented
430  
431 2 require File::Spec;
432  
433 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
434  
435 2 return $self->class->new(File::Spec->abs2rel($self->get, $path));
436 }
437  
438 sub rename {
439 2 ▶ my ($self, $path) = @_;
Subroutine rename: called CC=2 SCAR=7.0
Pod documented
440  
441 2 $path = $self->class->make($path);
442  
443 2 ▶ $path = $self->sibling("$path") if $path->is_relative;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_relative 2 0 2
444  
445 2 return $self->move($path);
446 }
447  
448 sub rmdir {
449 4 ▶ my ($self) = @_;
Subroutine rmdir: called CC=2 SCAR=7.0
Pod documented
450  
451 4 my $path = $self->get;
452  
453 4 ▶ CORE::rmdir($path)
Branch: 1 branch
BranchTrueFalseTotal
CORE::rmdir $path or $self->error({"throw", "error_on_rmdir", "path", $path, "error", $!}) 0 4 4
454 or $self->error({throw => 'error_on_rmdir', path => $path, error => $!});
455  
456 4 return $self;
457 }
458  
459 sub rmdirs {
460 2 ▶ my ($self) = @_;
Subroutine rmdirs: called CC=4 SCAR=14.0
Pod documented
461  
462 2 my @paths;
463  
464 2 for my $path ($self->children) {
465 1 ▶ if ($path->is_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file) { } 0 1 1
466 0 push @paths, $path->unlink;
467 }
468 else {
469 1 push @paths, $path->rmdirs;
470 }
471 }
472  
473 2 push @paths, $self->rmdir;
474  
475 2 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
476 }
477  
478 sub rmfiles {
479 1 ▶ my ($self) = @_;
Subroutine rmfiles: called CC=4 SCAR=14.6
Pod documented
480  
481 1 my @paths;
482  
483 1 for my $path ($self->children) {
484 5 ▶ if ($path->is_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file) { } 5 0 5
485 5 push @paths, $path->unlink;
486 }
487 else {
488 0 push @paths, $path->rmfiles;
489 }
490 }
491  
492 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
493 }
494  
495 sub root {
496 2 ▶ my ($self, $spec, $base) = @_;
Subroutine root: called CC=5 SCAR=16.1
Pod documented
497  
498 2 my @paths;
499  
500 2 for my $path ($self->absolute->lineage) {
501 13 ▶ if ($path->child($base)->test($spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->child($base)->test($spec)) 1 12 13
502 1 push @paths, $path;
503 1 last;
504 }
505 }
506  
507 2 ▶ return @paths ? (-f $paths[0] ? $paths[0]->parent : $paths[0]) : undef;
Branch: 2 branches
BranchTrueFalseTotal
@paths ? : 1 1 2
-f $paths[0] ? : 0 1 1
508 }
509  
510 sub seek {
511 21 ▶ my ($self, $spec, $base) = @_;
Subroutine seek: called CC=4 SCAR=13.9
Pod documented
512  
513 21 ▶ if ((my $path = $self->child($base))->test($spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $path = $self->child($base))->test($spec)) { } 1 20 21
514 1 return $path;
515 }
516 else {
517 20 for my $path ($self->directories) {
518 19 my $sought = $path->seek($spec, $base);
519 19 ▶ return $sought if $sought;
Branch: 1 branch
BranchTrueFalseTotal
if $sought 2 17 19
520 }
521 18 return undef;
522 }
523 }
524  
525 sub sibling {
526 5 ▶ my ($self, $path) = @_;
Subroutine sibling: called CC=1 SCAR=0.0
Pod documented
527  
528 5 require File::Basename;
529 5 require File::Spec;
530  
531 5 return $self->class->new(File::Spec->catfile(
532 File::Basename::dirname($self->get), $path));
533 }
534  
535 sub siblings {
536 1 ▶ my ($self) = @_;
Subroutine siblings: called CC=2 SCAR=7.0
Pod documented
537  
538 1 my @paths = map $self->parent->glob($_), '.??*', '*';
539  
540 1 my %seen = ($self->absolute, 1);
541  
542 1 @paths = grep !$seen{$_}++, @paths;
543  
544 1 ▶ return wantarray ? (@paths) : \@paths;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
545 }
546  
547 sub test {
548 39 ▶ my ($self, $spec) = @_;
Subroutine test: called CC=2 SCAR=6.9
Pod documented
549  
550 return eval(
551 39 ▶ join(' ', map("-$_", grep(/^[a-zA-Z]$/, split(//, $spec || 'e'))), '$self')
Condition100%2/2
$spec || 'e'
l!l
381
MC/DC100%1/1
$spec || 'e'
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
552 );
553 }
554  
555 sub unlink {
556 10 ▶ my ($self) = @_;
Subroutine unlink: called CC=2 SCAR=6.9
Pod documented
557  
558 10 my $path = $self->get;
559  
560 10 ▶ CORE::unlink($path)
Branch: 1 branch
BranchTrueFalseTotal
CORE::unlink $path or $self->error({"throw", "error_on_unlink", "path", $path, "error", $!}) 1 9 10
561 or $self->error({throw => 'error_on_unlink', path => $path, error => $!});
562  
563 9 return $self;
564 }
565  
566 sub write {
567 3 ▶ my ($self, $data, $binmode) = @_;
Subroutine write: called CC=6 SCAR=21.8
Pod documented
568  
569 3 my $path = $self->get;
570  
571 3 ▶ CORE::open(my $handle, '>', $path)
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $handle, ">", $path or $self->error({"throw", "error_on_write_open", "path", $path, "error", $!}) 1 2 3
572 or $self->error({throw => 'error_on_write_open', path => $path, error => $!});
573  
574 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 { $self->error({'throw', 'error_on_write_binmode', 'path', $path, 'error', $!, 'binmode', $binmode}) })
!ll&&!rl&&r
200
binmode $handle, $binmode or do { $self->error({"throw", "error_on_write_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $binmode && (binmode($handle, $binmode) || do { $self->error({'throw', 'error_on_write_binmode', 'path', $path, 'error', $!, 'binmode', $binmode}) })
defined $binmode binmode $handle, $binmode do { $self->error({"throw", "error_on_write_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
Truth table0%0/4
A && B or C
A= defined $binmodeB= binmode $handle, $binmodeC= do { $self->error({"throw", "error_on_write_binmode", "path", $path, "error", $!, "binmode", $binmode}) }
ABCresult
0XX0
1000
11X1
1011
575 0 $self->error({
576 throw => 'error_on_write_binmode',
577 path => $path,
578 error => $!,
579 binmode => $binmode,
580 });
581 } if defined($binmode);
582  
583 2 ▶ (($handle->syswrite($data) // -1) == length($data))
Branch: 1 branch
BranchTrueFalseTotal
($handle->syswrite($data) // -1) == length $data or $self->error({"throw", "error_on_write_error", "path", $path, "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
584 or $self->error({throw => 'error_on_write_error', path => $path, error => $!});
585  
586 2 return $self;
587 }
588  
589 # ERRORS
590  
591 sub error_on_copy {
592 1 ▶ my ($self, $data) = @_;
Subroutine error_on_copy: called CC=1 SCAR=0.0
Pod documented
593  
594 1 my $message = 'Can\'t copy "{{self}}" to "{{path}}": {{error}}';
595  
596 my $stash = {
597 error => $data->{error},
598 path => $data->{path},
599 1 self => $self,
600 };
601  
602 1 my $result = {
603 name => 'on.copy',
604 raise => true,
605 stash => $stash,
606 message => $message,
607 };
608  
609 1 return $result;
610 }
611  
612 sub error_on_mkcall {
613 2 ▶ my ($self, $data) = @_;
Subroutine error_on_mkcall: called CC=3 SCAR=11.0
Pod documented
614  
615 2 my $error = $data->{error};
616 2 ▶ my $exit_code = $data->{exit_code} || 0;
Condition100%2/2
$data->{'exit_code'} || 0
l!l
11
MC/DC100%1/1
$data->{'exit_code'} || 0
$data->{'exit_code'}
Truth table100%2/2
A
A= $data->{'exit_code'}
Aresult
11
00
617  
618 2 ▶ my $message = ("Can't make system call to \"{{path}}\": "
Branch: 1 branch
BranchTrueFalseTotal
$error ? : 1 1 2
619 . ($error ? "$error" : sprintf("exit code (%s)", $exit_code)));
620  
621 my $stash = {
622 error => $error,
623 exit_code => $exit_code,
624 path => $data->{path},
625 2 };
626  
627 2 my $result = {
628 name => 'on.mkcall',
629 raise => true,
630 stash => $stash,
631 message => $message,
632 };
633  
634 2 return $result;
635 }
636  
637 sub error_on_mkdir {
638 3 ▶ my ($self, $data) = @_;
Subroutine error_on_mkdir: called CC=1 SCAR=0.0
Pod documented
639  
640 3 my $message = 'Can\'t make directory "{{path}}": {{error}}';
641  
642 my $stash = {
643 error => $data->{error},
644 path => $data->{path},
645 3 };
646  
647 3 my $result = {
648 name => 'on.mkdir',
649 raise => true,
650 stash => $stash,
651 message => $message,
652 };
653  
654 3 return $result;
655 }
656  
657 sub error_on_mkfile {
658 1 ▶ my ($self, $data) = @_;
Subroutine error_on_mkfile: called CC=1 SCAR=0.0
Pod documented
659  
660 1 my $message = 'Can\'t make file "{{path}}": {{error}}';
661  
662 my $stash = {
663 error => $data->{error},
664 path => $data->{path},
665 1 };
666  
667 1 my $result = {
668 name => 'on.mkfile',
669 raise => true,
670 stash => $stash,
671 message => $message,
672 };
673  
674 1 return $result;
675 }
676  
677 sub error_on_move {
678 1 ▶ my ($self, $data) = @_;
Subroutine error_on_move: called CC=1 SCAR=0.0
Pod documented
679  
680 1 my $message = 'Can\'t move "{{self}}" to "{{path}}": {{error}}';
681  
682 my $stash = {
683 error => $data->{error},
684 path => $data->{path},
685 1 self => $self,
686 };
687  
688 1 my $result = {
689 name => 'on.move',
690 raise => true,
691 stash => $stash,
692 message => $message,
693 };
694  
695 1 return $result;
696 }
697  
698 sub error_on_open {
699 3 ▶ my ($self, $data) = @_;
Subroutine error_on_open: called CC=1 SCAR=0.0
Pod documented
700  
701 3 my $message = 'Can\'t open "{{path}}": {{error}}';
702  
703 my $stash = {
704 error => $data->{error},
705 path => $data->{path},
706 3 };
707  
708 3 my $result = {
709 name => 'on.open',
710 raise => true,
711 stash => $stash,
712 message => $message,
713 };
714  
715 3 return $result;
716 }
717  
718 sub error_on_read_binmode {
719 1 ▶ my ($self, $data) = @_;
Subroutine error_on_read_binmode: called CC=1 SCAR=0.0
Pod documented
720  
721 1 my $message = 'Can\'t binmode "{{path}}": {{error}}';
722  
723 my $stash = {
724 binmode => $data->{binmode},
725 error => $data->{error},
726 path => $data->{path},
727 1 };
728  
729 1 my $result = {
730 name => 'on.read.binmode',
731 raise => true,
732 stash => $stash,
733 message => $message,
734 };
735  
736 1 return $result;
737 }
738  
739 sub error_on_read_error {
740 1 ▶ my ($self, $data) = @_;
Subroutine error_on_read_error: called CC=1 SCAR=0.0
Pod documented
741  
742 1 my $message = 'Can\'t read from file "{{path}}": {{error}}';
743  
744 my $stash = {
745 error => $data->{error},
746 path => $data->{path},
747 1 };
748  
749 1 my $result = {
750 name => 'on.read.error',
751 raise => true,
752 stash => $stash,
753 message => $message,
754 };
755  
756 1 return $result;
757 }
758  
759 sub error_on_read_open {
760 2 ▶ my ($self, $data) = @_;
Subroutine error_on_read_open: called CC=1 SCAR=0.0
Pod documented
761  
762 2 my $message = 'Can\'t read "{{path}}": {{error}}';
763  
764 my $stash = {
765 error => $data->{error},
766 path => $data->{path},
767 2 };
768  
769 2 my $result = {
770 name => 'on.read.open',
771 raise => true,
772 stash => $stash,
773 message => $message,
774 };
775  
776 2 return $result;
777 }
778  
779 sub error_on_rmdir {
780 1 ▶ my ($self, $data) = @_;
Subroutine error_on_rmdir: called CC=1 SCAR=0.0
Pod documented
781  
782 1 my $message = 'Can\'t rmdir "{{path}}": {{error}}';
783  
784 my $stash = {
785 error => $data->{error},
786 path => $data->{path},
787 1 };
788  
789 1 my $result = {
790 name => 'on.rmdir',
791 raise => true,
792 stash => $stash,
793 message => $message,
794 };
795  
796 1 return $result;
797 }
798  
799 sub error_on_write_binmode {
800 1 ▶ my ($self, $data) = @_;
Subroutine error_on_write_binmode: called CC=1 SCAR=0.0
Pod documented
801  
802 1 my $message = 'Can\'t binmode "{{path}}": {{error}}';
803  
804 my $stash = {
805 binmode => $data->{binmode},
806 error => $data->{error},
807 path => $data->{path},
808 1 };
809  
810 1 my $result = {
811 name => 'on.write.binmode',
812 raise => true,
813 stash => $stash,
814 message => $message,
815 };
816  
817 1 return $result;
818 }
819  
820 sub error_on_write_error {
821 1 ▶ my ($self, $data) = @_;
Subroutine error_on_write_error: called CC=1 SCAR=0.0
Pod documented
822  
823 1 my $message = 'Can\'t write to file "{{path}}": {{error}}';
824  
825 my $stash = {
826 error => $data->{error},
827 path => $data->{path},
828 1 };
829  
830 1 my $result = {
831 name => 'on.write.error',
832 raise => true,
833 stash => $stash,
834 message => $message,
835 };
836  
837 1 return $result;
838 }
839  
840 sub error_on_write_open {
841 2 ▶ my ($self, $data) = @_;
Subroutine error_on_write_open: called CC=1 SCAR=0.0
Pod documented
842  
843 2 my $message = 'Can\'t write "{{path}}": {{error}}';
844  
845 my $stash = {
846 error => $data->{error},
847 path => $data->{path},
848 2 };
849  
850 2 my $result = {
851 name => 'on.write.open',
852 raise => true,
853 stash => $stash,
854 message => $message,
855 };
856  
857 2 return $result;
858 }
859  
860 sub error_on_unlink {
861 2 ▶ my ($self, $data) = @_;
Subroutine error_on_unlink: called CC=1 SCAR=0.0
Pod documented
862  
863 2 my $message = 'Can\'t unlink "{{path}}": {{error}}';
864  
865 my $stash = {
866 error => $data->{error},
867 path => $data->{path},
868 2 };
869  
870 2 my $result = {
871 name => 'on.unlink',
872 raise => true,
873 stash => $stash,
874 message => $message,
875 };
876  
877 2 return $result;
878 }
879  
880 96 1;
881  
882  
883  
884 =head1 NAME
885  
886 Venus::Path - Path Class
887  
888 =cut
889  
890 =head1 ABSTRACT
891  
892 Path Class for Perl 5
893  
894 =cut
895  
896 =head1 SYNOPSIS
897  
898 package main;
899  
900 use Venus::Path;
901  
902 my $path = Venus::Path->new('t/data/planets');
903  
904 # my $planets = $path->files;
905 # my $mercury = $path->child('mercury');
906 # my $content = $mercury->read;
907  
908 =cut
909  
910 =head1 DESCRIPTION
911  
912 This package provides methods for working with file system paths.
913  
914 =cut
915  
916 =head1 INHERITS
917  
918 This package inherits behaviors from:
919  
920 L<Venus::Kind::Utility>
921  
922 =cut
923  
924 =head1 INTEGRATES
925  
926 This package integrates behaviors from:
927  
928 L<Venus::Role::Accessible>
929  
930 L<Venus::Role::Buildable>
931  
932 L<Venus::Role::Explainable>
933  
934 L<Venus::Role::Valuable>
935  
936 =cut
937  
938 =head1 METHODS
939  
940 This package provides the following methods:
941  
942 =cut
943  
944 =head2 absolute
945  
946 absolute() (Venus::Path)
947  
948 The absolute method returns a path object where the value (path) is absolute.
949  
950 I<Since C<0.01>>
951  
952 =over 4
953  
954 =item absolute example 1
955  
956 # given: synopsis;
957  
958 $path = $path->absolute;
959  
960 # bless({ value => "/path/to/t/data/planets" }, "Venus::Path")
961  
962 =back
963  
964 =cut
965  
966 =head2 basename
967  
968 basename() (string)
969  
970 The basename method returns the path base name.
971  
972 I<Since C<0.01>>
973  
974 =over 4
975  
976 =item basename example 1
977  
978 # given: synopsis;
979  
980 my $basename = $path->basename;
981  
982 # planets
983  
984 =back
985  
986 =cut
987  
988 =head2 child
989  
990 child(string $path) (Venus::Path)
991  
992 The child method returns a path object representing the child path provided.
993  
994 I<Since C<0.01>>
995  
996 =over 4
997  
998 =item child example 1
999  
1000 # given: synopsis;
1001  
1002 $path = $path->child('earth');
1003  
1004 # bless({ value => "t/data/planets/earth" }, "Venus::Path")
1005  
1006 =back
1007  
1008 =cut
1009  
1010 =head2 children
1011  
1012 children() (within[arrayref, Venus::Path])
1013  
1014 The children method returns the files and directories under the path. This
1015 method can return a list of values in list-context.
1016  
1017 I<Since C<0.01>>
1018  
1019 =over 4
1020  
1021 =item children example 1
1022  
1023 # given: synopsis;
1024  
1025 my $children = $path->children;
1026  
1027 # [
1028 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
1029 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
1030 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
1031 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
1032 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
1033 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
1034 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
1035 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
1036 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
1037 # bless({ value => "t/data/planets/planet9" }, "Venus::Path"),
1038 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
1039 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
1040 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
1041 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
1042 # ]
1043  
1044 =back
1045  
1046 =cut
1047  
1048 =head2 chmod
1049  
1050 chmod(string $mode) (Venus::Path)
1051  
1052 The chmod method changes the file permissions of the file or directory.
1053  
1054 I<Since C<0.01>>
1055  
1056 =over 4
1057  
1058 =item chmod example 1
1059  
1060 # given: synopsis;
1061  
1062 $path = $path->chmod(0755);
1063  
1064 # bless({ value => "t/data/planets" }, "Venus::Path")
1065  
1066 =back
1067  
1068 =cut
1069  
1070 =head2 chown
1071  
1072 chown(string @args) (Venus::Path)
1073  
1074 The chown method changes the group and/or owner or the file or directory.
1075  
1076 I<Since C<0.01>>
1077  
1078 =over 4
1079  
1080 =item chown example 1
1081  
1082 # given: synopsis;
1083  
1084 $path = $path->chown(-1, -1);
1085  
1086 # bless({ value => "t/data/planets" }, "Venus::Path")
1087  
1088 =back
1089  
1090 =cut
1091  
1092 =head2 copy
1093  
1094 copy(string | Venus::Path $path) (Venus::Path)
1095  
1096 The copy method uses L<File::Copy/copy> to copy the file represented by the
1097 invocant to the path provided and returns the invocant.
1098  
1099 I<Since C<2.80>>
1100  
1101 =over 4
1102  
1103 =item copy example 1
1104  
1105 # given: synopsis
1106  
1107 package main;
1108  
1109 my $copy = $path->child('mercury')->copy($path->child('yrucrem'));
1110  
1111 # bless({...}, 'Venus::Path')
1112  
1113 =back
1114  
1115 =cut
1116  
1117 =head2 default
1118  
1119 default() (string)
1120  
1121 The default method returns the default value, i.e. C<$ENV{PWD}>.
1122  
1123 I<Since C<0.01>>
1124  
1125 =over 4
1126  
1127 =item default example 1
1128  
1129 # given: synopsis;
1130  
1131 my $default = $path->default;
1132  
1133 # $ENV{PWD}
1134  
1135 =back
1136  
1137 =cut
1138  
1139 =head2 directories
1140  
1141 directories() (within[arrayref, Venus::Path])
1142  
1143 The directories method returns a list of children under the path which are
1144 directories. This method can return a list of values in list-context.
1145  
1146 I<Since C<0.01>>
1147  
1148 =over 4
1149  
1150 =item directories example 1
1151  
1152 # given: synopsis;
1153  
1154 my $directories = $path->directories;
1155  
1156 # []
1157  
1158 =back
1159  
1160 =cut
1161  
1162 =head2 exists
1163  
1164 exists() (boolean)
1165  
1166 The exists method returns truthy or falsy if the path exists.
1167  
1168 I<Since C<0.01>>
1169  
1170 =over 4
1171  
1172 =item exists example 1
1173  
1174 # given: synopsis;
1175  
1176 my $exists = $path->exists;
1177  
1178 # 1
1179  
1180 =back
1181  
1182 =over 4
1183  
1184 =item exists example 2
1185  
1186 # given: synopsis;
1187  
1188 my $exists = $path->child('random')->exists;
1189  
1190 # 0
1191  
1192 =back
1193  
1194 =cut
1195  
1196 =head2 explain
1197  
1198 explain() (string)
1199  
1200 The explain method returns the path string and is used in stringification
1201 operations.
1202  
1203 I<Since C<0.01>>
1204  
1205 =over 4
1206  
1207 =item explain example 1
1208  
1209 # given: synopsis;
1210  
1211 my $explain = $path->explain;
1212  
1213 # t/data/planets
1214  
1215 =back
1216  
1217 =cut
1218  
1219 =head2 extension
1220  
1221 extension(string $name) (string | Venus::Path)
1222  
1223 The extension method returns a new path object using the extension name
1224 provided. If no argument is provided this method returns the extension for the
1225 path represented by the invocant, otherwise returns undefined.
1226  
1227 I<Since C<2.55>>
1228  
1229 =over 4
1230  
1231 =item extension example 1
1232  
1233 package main;
1234  
1235 use Venus::Path;
1236  
1237 my $path = Venus::Path->new('t/Venus_Path.t');
1238  
1239 my $extension = $path->extension;
1240  
1241 # "t"
1242  
1243 =back
1244  
1245 =over 4
1246  
1247 =item extension example 2
1248  
1249 package main;
1250  
1251 use Venus::Path;
1252  
1253 my $path = Venus::Path->new('t/data/mercury');
1254  
1255 my $extension = $path->extension('txt');
1256  
1257 # bless({ value => "t/data/mercury.txt"}, "Venus::Path")
1258  
1259 =back
1260  
1261 =over 4
1262  
1263 =item extension example 3
1264  
1265 package main;
1266  
1267 use Venus::Path;
1268  
1269 my $path = Venus::Path->new('t/data');
1270  
1271 my $extension = $path->extension;
1272  
1273 # undef
1274  
1275 =back
1276  
1277 =over 4
1278  
1279 =item extension example 4
1280  
1281 package main;
1282  
1283 use Venus::Path;
1284  
1285 my $path = Venus::Path->new('t/data');
1286  
1287 my $extension = $path->extension('txt');
1288  
1289 # bless({ value => "t/data.txt"}, "Venus::Path")
1290  
1291 =back
1292  
1293 =cut
1294  
1295 =head2 files
1296  
1297 files() (within[arrayref, Venus::Path])
1298  
1299 The files method returns a list of children under the path which are files.
1300 This method can return a list of values in list-context.
1301  
1302 I<Since C<0.01>>
1303  
1304 =over 4
1305  
1306 =item files example 1
1307  
1308 # given: synopsis;
1309  
1310 my $files = $path->files;
1311  
1312 # [
1313 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
1314 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
1315 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
1316 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
1317 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
1318 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
1319 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
1320 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
1321 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
1322 # bless({ value => "t/data/planets/planet9" }, "Venus::Path"),
1323 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
1324 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
1325 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
1326 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
1327 # ]
1328  
1329 =back
1330  
1331 =cut
1332  
1333 =head2 find
1334  
1335 find(string | regexp $expr) (within[arrayref, Venus::Path])
1336  
1337 The find method does a recursive depth-first search and returns a list of paths
1338 found, matching the expression provided, which defaults to C<*>. This method
1339 can return a list of values in list-context.
1340  
1341 I<Since C<0.01>>
1342  
1343 =over 4
1344  
1345 =item find example 1
1346  
1347 # given: synopsis;
1348  
1349 my $find = $path->find;
1350  
1351 # [
1352 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
1353 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
1354 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
1355 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
1356 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
1357 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
1358 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
1359 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
1360 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
1361 # bless({ value => "t/data/planets/planet9" }, "Venus::Path"),
1362 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
1363 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
1364 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
1365 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
1366 # ]
1367  
1368 =back
1369  
1370 =over 4
1371  
1372 =item find example 2
1373  
1374 # given: synopsis;
1375  
1376 my $find = $path->find('[:\/\\\.]+m[^:\/\\\.]*$');
1377  
1378 # [
1379 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
1380 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
1381 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
1382 # ]
1383  
1384 =back
1385  
1386 =over 4
1387  
1388 =item find example 3
1389  
1390 # given: synopsis;
1391  
1392 my $find = $path->find('earth');
1393  
1394 # [
1395 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
1396 # ]
1397  
1398 =back
1399  
1400 =cut
1401  
1402 =head2 glob
1403  
1404 glob(string | regexp $expr) (within[arrayref, Venus::Path])
1405  
1406 The glob method returns the files and directories under the path matching the
1407 expression provided, which defaults to C<*>. This method can return a list of
1408 values in list-context.
1409  
1410 I<Since C<0.01>>
1411  
1412 =over 4
1413  
1414 =item glob example 1
1415  
1416 # given: synopsis;
1417  
1418 my $glob = $path->glob;
1419  
1420 # [
1421 # bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
1422 # bless({ value => "t/data/planets/earth" }, "Venus::Path"),
1423 # bless({ value => "t/data/planets/eris" }, "Venus::Path"),
1424 # bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
1425 # bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
1426 # bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
1427 # bless({ value => "t/data/planets/mars" }, "Venus::Path"),
1428 # bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
1429 # bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
1430 # bless({ value => "t/data/planets/planet9" }, "Venus::Path"),
1431 # bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
1432 # bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
1433 # bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
1434 # bless({ value => "t/data/planets/venus" }, "Venus::Path"),
1435 # ]
1436  
1437 =back
1438  
1439 =cut
1440  
1441 =head2 is_absolute
1442  
1443 is_absolute() (boolean)
1444  
1445 The is_absolute method returns truthy or falsy is the path is absolute.
1446  
1447 I<Since C<0.01>>
1448  
1449 =over 4
1450  
1451 =item is_absolute example 1
1452  
1453 # given: synopsis;
1454  
1455 my $is_absolute = $path->is_absolute;
1456  
1457 # 0
1458  
1459 =back
1460  
1461 =cut
1462  
1463 =head2 is_directory
1464  
1465 is_directory() (boolean)
1466  
1467 The is_directory method returns truthy or falsy is the path is a directory.
1468  
1469 I<Since C<0.01>>
1470  
1471 =over 4
1472  
1473 =item is_directory example 1
1474  
1475 # given: synopsis;
1476  
1477 my $is_directory = $path->is_directory;
1478  
1479 # 1
1480  
1481 =back
1482  
1483 =cut
1484  
1485 =head2 is_file
1486  
1487 is_file() (boolean)
1488  
1489 The is_file method returns truthy or falsy is the path is a file.
1490  
1491 I<Since C<0.01>>
1492  
1493 =over 4
1494  
1495 =item is_file example 1
1496  
1497 # given: synopsis;
1498  
1499 my $is_file = $path->is_file;
1500  
1501 # 0
1502  
1503 =back
1504  
1505 =cut
1506  
1507 =head2 is_relative
1508  
1509 is_relative() (boolean)
1510  
1511 The is_relative method returns truthy or falsy is the path is relative.
1512  
1513 I<Since C<0.01>>
1514  
1515 =over 4
1516  
1517 =item is_relative example 1
1518  
1519 # given: synopsis;
1520  
1521 my $is_relative = $path->is_relative;
1522  
1523 # 1
1524  
1525 =back
1526  
1527 =cut
1528  
1529 =head2 lineage
1530  
1531 lineage() (within[arrayref, Venus::Path])
1532  
1533 The lineage method returns the list of parent paths up to the root path. This
1534 method can return a list of values in list-context.
1535  
1536 I<Since C<0.01>>
1537  
1538 =over 4
1539  
1540 =item lineage example 1
1541  
1542 # given: synopsis;
1543  
1544 my $lineage = $path->lineage;
1545  
1546 # [
1547 # bless({ value => "t/data/planets" }, "Venus::Path"),
1548 # bless({ value => "t/data" }, "Venus::Path"),
1549 # bless({ value => "t" }, "Venus::Path"),
1550 # ]
1551  
1552 =back
1553  
1554 =cut
1555  
1556 =head2 lines
1557  
1558 lines(string | regexp $separator, string $binmode) (within[arrayref, string])
1559  
1560 The lines method returns the list of lines from the underlying file. By default
1561 the file contents are separated by newline.
1562  
1563 I<Since C<1.23>>
1564  
1565 =over 4
1566  
1567 =item lines example 1
1568  
1569 # given: synopsis;
1570  
1571 my $lines = $path->child('mercury')->lines;
1572  
1573 # ['mercury']
1574  
1575 =back
1576  
1577 =over 4
1578  
1579 =item lines example 2
1580  
1581 # given: synopsis;
1582  
1583 my $lines = $path->child('planet9')->lines($^O =~ /win32/i ? "\n" : "\r\n");
1584  
1585 # ['planet', 'nine']
1586  
1587 =back
1588  
1589 =cut
1590  
1591 =head2 mkcall
1592  
1593 mkcall(any @data) (any)
1594  
1595 The mkcall method returns the result of executing the path as an executable. In
1596 list context returns the call output and exit code.
1597  
1598 I<Since C<0.01>>
1599  
1600 =over 4
1601  
1602 =item mkcall example 1
1603  
1604 package main;
1605  
1606 use Venus::Path;
1607  
1608 my $path = Venus::Path->new($^X);
1609  
1610 my $output = $path->mkcall('--help');
1611  
1612 # Usage: perl ...
1613  
1614 =back
1615  
1616 =over 4
1617  
1618 =item mkcall example 2
1619  
1620 package main;
1621  
1622 use Venus::Path;
1623  
1624 my $path = Venus::Path->new($^X);
1625  
1626 my ($call_output, $exit_code) = $path->mkcall('t/data/sun', '--heat-death');
1627  
1628 # ("", 1)
1629  
1630 =back
1631  
1632 =over 4
1633  
1634 =item mkcall example 3
1635  
1636 package main;
1637  
1638 use Venus::Path;
1639  
1640 my $path = Venus::Path->new('.help');
1641  
1642 my $output = $path->mkcall;
1643  
1644 # Exception! (isa Venus::Path::Error) (see error_on_mkcall)
1645  
1646 =back
1647  
1648 =cut
1649  
1650 =head2 mkdir
1651  
1652 mkdir(maybe[string] $mode) (Venus::Path)
1653  
1654 The mkdir method makes the path as a directory.
1655  
1656 I<Since C<0.01>>
1657  
1658 =over 4
1659  
1660 =item mkdir example 1
1661  
1662 package main;
1663  
1664 use Venus::Path;
1665  
1666 my $path = Venus::Path->new('t/data/systems');
1667  
1668 $path = $path->mkdir;
1669  
1670 # bless({ value => "t/data/systems" }, "Venus::Path")
1671  
1672 =back
1673  
1674 =over 4
1675  
1676 =item mkdir example 2
1677  
1678 package main;
1679  
1680 use Venus::Path;
1681  
1682 my $path = Venus::Path->new('/path/to/xyz');
1683  
1684 $path = $path->mkdir;
1685  
1686 # Exception! (isa Venus::Path::Error) (see error_on_mkdir)
1687  
1688 =back
1689  
1690 =cut
1691  
1692 =head2 mkdirs
1693  
1694 mkdirs(maybe[string] $mode) (within[arrayref, Venus::Path])
1695  
1696 The mkdirs method creates parent directories and returns the list of created
1697 directories. This method can return a list of values in list-context.
1698  
1699 I<Since C<0.01>>
1700  
1701 =over 4
1702  
1703 =item mkdirs example 1
1704  
1705 package main;
1706  
1707 use Venus::Path;
1708  
1709 my $path = Venus::Path->new('t/data/systems');
1710  
1711 my $mkdirs = $path->mkdirs;
1712  
1713 # [
1714 # bless({ value => "t/data/systems" }, "Venus::Path")
1715 # ]
1716  
1717 =back
1718  
1719 =over 4
1720  
1721 =item mkdirs example 2
1722  
1723 package main;
1724  
1725 use Venus::Path;
1726  
1727 my $path = Venus::Path->new('t/data/systems/solar');
1728  
1729 my $mkdirs = $path->mkdirs;
1730  
1731 # [
1732 # bless({ value => "t/data/systems" }, "Venus::Path"),
1733 # bless({ value => "t/data/systems/solar" }, "Venus::Path"),
1734 # ]
1735  
1736 =back
1737  
1738 =cut
1739  
1740 =head2 mkfile
1741  
1742 mkfile() (Venus::Path)
1743  
1744 The mkfile method makes the path as an empty file.
1745  
1746 I<Since C<0.01>>
1747  
1748 =over 4
1749  
1750 =item mkfile example 1
1751  
1752 package main;
1753  
1754 use Venus::Path;
1755  
1756 my $path = Venus::Path->new('t/data/moon');
1757  
1758 $path = $path->mkfile;
1759  
1760 # bless({ value => "t/data/moon" }, "Venus::Path")
1761  
1762 =back
1763  
1764 =over 4
1765  
1766 =item mkfile example 2
1767  
1768 package main;
1769  
1770 use Venus::Path;
1771  
1772 my $path = Venus::Path->new('/path/to/xyz');
1773  
1774 $path = $path->mkfile;
1775  
1776 # Exception! (isa Venus::Path::Error) (see error_on_mkfile)
1777  
1778 =back
1779  
1780 =cut
1781  
1782 =head2 mktemp_dir
1783  
1784 mktemp_dir() (Venus::Path)
1785  
1786 The mktemp_dir method uses L<File::Temp/tempdir> to create a temporary
1787 directory which isn't automatically removed and returns a new path object.
1788  
1789 I<Since C<2.80>>
1790  
1791 =over 4
1792  
1793 =item mktemp_dir example 1
1794  
1795 # given: synopsis
1796  
1797 package main;
1798  
1799 my $mktemp_dir = $path->mktemp_dir;
1800  
1801 # bless({value => "/tmp/ZnKTxBpuBE"}, "Venus::Path")
1802  
1803 =back
1804  
1805 =cut
1806  
1807 =head2 mktemp_file
1808  
1809 mktemp_file() (Venus::Path)
1810  
1811 The mktemp_file method uses L<File::Temp/tempfile> to create a temporary file
1812 which isn't automatically removed and returns a new path object.
1813  
1814 I<Since C<2.80>>
1815  
1816 =over 4
1817  
1818 =item mktemp_file example 1
1819  
1820 # given: synopsis
1821  
1822 package main;
1823  
1824 my $mktemp_file = $path->mktemp_file;
1825  
1826 # bless({value => "/tmp/y5MvliBQ2F"}, "Venus::Path")
1827  
1828 =back
1829  
1830 =cut
1831  
1832 =head2 move
1833  
1834 move(string | Venus::Path $path) (Venus::Path)
1835  
1836 The move method uses L<File::Copy/move> to move the file represented by the
1837 invocant to the path provided and returns the invocant.
1838  
1839 I<Since C<2.80>>
1840  
1841 =over 4
1842  
1843 =item move example 1
1844  
1845 package main;
1846  
1847 use Venus::Path;
1848  
1849 my $path = Venus::Path->new('t/data');
1850  
1851 my $unknown = $path->child('unknown')->mkfile->move($path->child('titan'));
1852  
1853 # bless({value => 't/data/titan'}, 'Venus::Path')
1854  
1855 =back
1856  
1857 =cut
1858  
1859 =head2 name
1860  
1861 name() (string)
1862  
1863 The name method returns the path as an absolute path.
1864  
1865 I<Since C<0.01>>
1866  
1867 =over 4
1868  
1869 =item name example 1
1870  
1871 # given: synopsis;
1872  
1873 my $name = $path->name;
1874  
1875 # /path/to/t/data/planets
1876  
1877 =back
1878  
1879 =cut
1880  
1881 =head2 open
1882  
1883 open(any @data) (FileHandle)
1884  
1885 The open method creates and returns an open filehandle.
1886  
1887 I<Since C<0.01>>
1888  
1889 =over 4
1890  
1891 =item open example 1
1892  
1893 package main;
1894  
1895 use Venus::Path;
1896  
1897 my $path = Venus::Path->new('t/data/planets/earth');
1898  
1899 my $fh = $path->open;
1900  
1901 # bless(..., "IO::File");
1902  
1903 =back
1904  
1905 =over 4
1906  
1907 =item open example 2
1908  
1909 package main;
1910  
1911 use Venus::Path;
1912  
1913 my $path = Venus::Path->new('t/data/planets/earth');
1914  
1915 my $fh = $path->open('<');
1916  
1917 # bless(..., "IO::File");
1918  
1919 =back
1920  
1921 =over 4
1922  
1923 =item open example 3
1924  
1925 package main;
1926  
1927 use Venus::Path;
1928  
1929 my $path = Venus::Path->new('t/data/planets/earth');
1930  
1931 my $fh = $path->open('>');
1932  
1933 # bless(..., "IO::File");
1934  
1935 =back
1936  
1937 =over 4
1938  
1939 =item open example 4
1940  
1941 package main;
1942  
1943 use Venus::Path;
1944  
1945 my $path = Venus::Path->new('/path/to/xyz');
1946  
1947 my $fh = $path->open('>');
1948  
1949 # Exception! (isa Venus::Path::Error) (see error_on_open)
1950  
1951 =back
1952  
1953 =cut
1954  
1955 =head2 parent
1956  
1957 parent() (Venus::Path)
1958  
1959 The parent method returns a path object representing the parent directory.
1960  
1961 I<Since C<0.01>>
1962  
1963 =over 4
1964  
1965 =item parent example 1
1966  
1967 # given: synopsis;
1968  
1969 my $parent = $path->parent;
1970  
1971 # bless({ value => "t/data" }, "Venus::Path")
1972  
1973 =back
1974  
1975 =cut
1976  
1977 =head2 parents
1978  
1979 parents() (within[arrayref, Venus::Path])
1980  
1981 The parents method returns is a list of parent directories. This method can
1982 return a list of values in list-context.
1983  
1984 I<Since C<0.01>>
1985  
1986 =over 4
1987  
1988 =item parents example 1
1989  
1990 # given: synopsis;
1991  
1992 my $parents = $path->parents;
1993  
1994 # [
1995 # bless({ value => "t/data" }, "Venus::Path"),
1996 # bless({ value => "t" }, "Venus::Path"),
1997 # ]
1998  
1999 =back
2000  
2001 =cut
2002  
2003 =head2 parts
2004  
2005 parts() (within[arrayref, string])
2006  
2007 The parts method returns an arrayref of path parts.
2008  
2009 I<Since C<0.01>>
2010  
2011 =over 4
2012  
2013 =item parts example 1
2014  
2015 # given: synopsis;
2016  
2017 my $parts = $path->parts;
2018  
2019 # ["t", "data", "planets"]
2020  
2021 =back
2022  
2023 =cut
2024  
2025 =head2 read
2026  
2027 read(string $binmode) (string)
2028  
2029 The read method reads the file and returns its contents.
2030  
2031 I<Since C<0.01>>
2032  
2033 =over 4
2034  
2035 =item read example 1
2036  
2037 package main;
2038  
2039 use Venus::Path;
2040  
2041 my $path = Venus::Path->new('t/data/planets/mars');
2042  
2043 my $content = $path->read;
2044  
2045 =back
2046  
2047 =over 4
2048  
2049 =item read example 2
2050  
2051 package main;
2052  
2053 use Venus::Path;
2054  
2055 my $path = Venus::Path->new('/path/to/xyz');
2056  
2057 my $content = $path->read;
2058  
2059 # Exception! (isa Venus::Path::Error) (see error_on_read_open)
2060  
2061 =back
2062  
2063 =cut
2064  
2065 =head2 relative
2066  
2067 relative(string $root) (Venus::Path)
2068  
2069 The relative method returns a path object representing a relative path
2070 (relative to the path provided).
2071  
2072 I<Since C<0.01>>
2073  
2074 =over 4
2075  
2076 =item relative example 1
2077  
2078 package main;
2079  
2080 use Venus::Path;
2081  
2082 my $path = Venus::Path->new('/path/to/t/data/planets/mars');
2083  
2084 my $relative = $path->relative('/path');
2085  
2086 # bless({ value => "to/t/data/planets/mars" }, "Venus::Path")
2087  
2088 =back
2089  
2090 =over 4
2091  
2092 =item relative example 2
2093  
2094 package main;
2095  
2096 use Venus::Path;
2097  
2098 my $path = Venus::Path->new('/path/to/t/data/planets/mars');
2099  
2100 my $relative = $path->relative('/path/to/t');
2101  
2102 # bless({ value => "data/planets/mars" }, "Venus::Path")
2103  
2104 =back
2105  
2106 =cut
2107  
2108 =head2 rename
2109  
2110 rename(string | Venus::Path $path) (Venus::Path)
2111  
2112 The rename method performs a L</move> unless the path provided is only a file
2113 name, in which case it attempts a rename under the directory of the invocant.
2114  
2115 I<Since C<2.91>>
2116  
2117 =over 4
2118  
2119 =item rename example 1
2120  
2121 package main;
2122  
2123 use Venus::Path;
2124  
2125 my $path = Venus::Path->new('t/path/001');
2126  
2127 my $rename = $path->rename('002');
2128  
2129 # bless({value => 't/path/002'}, 'Venus::Path')
2130  
2131 =back
2132  
2133 =cut
2134  
2135 =head2 rmdir
2136  
2137 rmdir() (Venus::Path)
2138  
2139 The rmdir method removes the directory and returns a path object representing
2140 the deleted directory.
2141  
2142 I<Since C<0.01>>
2143  
2144 =over 4
2145  
2146 =item rmdir example 1
2147  
2148 package main;
2149  
2150 use Venus::Path;
2151  
2152 my $path = Venus::Path->new('t/data/stars');
2153  
2154 my $rmdir = $path->mkdir->rmdir;
2155  
2156 # bless({ value => "t/data/stars" }, "Venus::Path")
2157  
2158 =back
2159  
2160 =over 4
2161  
2162 =item rmdir example 2
2163  
2164 package main;
2165  
2166 use Venus::Path;
2167  
2168 my $path = Venus::Path->new('/path/to/xyz');
2169  
2170 my $rmdir = $path->mkdir->rmdir;
2171  
2172 # Exception! (isa Venus::Path::Error) (see error_on_rmdir)
2173  
2174 =back
2175  
2176 =cut
2177  
2178 =head2 rmdirs
2179  
2180 rmdirs() (within[arrayref, Venus::Path])
2181  
2182 The rmdirs method removes that path and its child files and directories and
2183 returns all paths removed. This method can return a list of values in
2184 list-context.
2185  
2186 I<Since C<0.01>>
2187  
2188 =over 4
2189  
2190 =item rmdirs example 1
2191  
2192 package main;
2193  
2194 use Venus::Path;
2195  
2196 my $path = Venus::Path->new('t/data/stars');
2197  
2198 $path->child('dwarfs')->mkdirs;
2199  
2200 my $rmdirs = $path->rmdirs;
2201  
2202 # [
2203 # bless({ value => "t/data/stars/dwarfs" }, "Venus::Path"),
2204 # bless({ value => "t/data/stars" }, "Venus::Path"),
2205 # ]
2206  
2207 =back
2208  
2209 =cut
2210  
2211 =head2 rmfiles
2212  
2213 rmfiles() (within[arrayref, Venus::Path])
2214  
2215 The rmfiles method recursively removes files under the path and returns the
2216 paths removed. This method does not remove the directories found. This method
2217 can return a list of values in list-context.
2218  
2219 I<Since C<0.01>>
2220  
2221 =over 4
2222  
2223 =item rmfiles example 1
2224  
2225 package main;
2226  
2227 use Venus::Path;
2228  
2229 my $path = Venus::Path->new('t/data/stars')->mkdir;
2230  
2231 $path->child('sirius')->mkfile;
2232 $path->child('canopus')->mkfile;
2233 $path->child('arcturus')->mkfile;
2234 $path->child('vega')->mkfile;
2235 $path->child('capella')->mkfile;
2236  
2237 my $rmfiles = $path->rmfiles;
2238  
2239 # [
2240 # bless({ value => "t/data/stars/arcturus" }, "Venus::Path"),
2241 # bless({ value => "t/data/stars/canopus" }, "Venus::Path"),
2242 # bless({ value => "t/data/stars/capella" }, "Venus::Path"),
2243 # bless({ value => "t/data/stars/sirius" }, "Venus::Path"),
2244 # bless({ value => "t/data/stars/vega" }, "Venus::Path"),
2245 # ]
2246  
2247 =back
2248  
2249 =cut
2250  
2251 =head2 root
2252  
2253 root(string $spec, string $base) (maybe[Venus::Path])
2254  
2255 The root method performs a search up the file system heirarchy returns the
2256 first path (i.e. absolute path) matching the file test specification and base
2257 path expression provided. The file test specification is the same passed to
2258 L</test>. If no path matches are found this method returns underfined.
2259  
2260 I<Since C<2.32>>
2261  
2262 =over 4
2263  
2264 =item root example 1
2265  
2266 # given: synopsis;
2267  
2268 my $root = $path->root('d', 't');
2269  
2270 # bless({ value => "/path/to/t/../" }, "Venus::Path")
2271  
2272 =back
2273  
2274 =over 4
2275  
2276 =item root example 2
2277  
2278 # given: synopsis;
2279  
2280 my $root = $path->root('f', 't');
2281  
2282 # undef
2283  
2284 =back
2285  
2286 =cut
2287  
2288 =head2 seek
2289  
2290 seek(string $spec, string $base) (maybe[Venus::Path])
2291  
2292 The seek method performs a search down the file system heirarchy returns the
2293 first path (i.e. absolute path) matching the file test specification and base
2294 path expression provided. The file test specification is the same passed to
2295 L</test>. If no path matches are found this method returns underfined.
2296  
2297 I<Since C<2.32>>
2298  
2299 =over 4
2300  
2301 =item seek example 1
2302  
2303 # given: synopsis;
2304  
2305 $path = Venus::Path->new('t');
2306  
2307 my $seek = $path->seek('f', 'earth');
2308  
2309 # bless({ value => "/path/to/t/data/planets/earth" }, "Venus::Path")
2310  
2311 =back
2312  
2313 =over 4
2314  
2315 =item seek example 2
2316  
2317 # given: synopsis;
2318  
2319 $path = Venus::Path->new('t');
2320  
2321 my $seek = $path->seek('f', 'europa');
2322  
2323 # undef
2324  
2325 =back
2326  
2327 =cut
2328  
2329 =head2 sibling
2330  
2331 sibling(string $path) (Venus::Path)
2332  
2333 The sibling method returns a path object representing the sibling path provided.
2334  
2335 I<Since C<0.01>>
2336  
2337 =over 4
2338  
2339 =item sibling example 1
2340  
2341 # given: synopsis;
2342  
2343 my $sibling = $path->sibling('galaxies');
2344  
2345 # bless({ value => "t/data/galaxies" }, "Venus::Path")
2346  
2347 =back
2348  
2349 =cut
2350  
2351 =head2 siblings
2352  
2353 siblings() (within[arrayref, Venus::Path])
2354  
2355 The siblings method returns all sibling files and directories for the current
2356 path. This method can return a list of values in list-context.
2357  
2358 I<Since C<0.01>>
2359  
2360 =over 4
2361  
2362 =item siblings example 1
2363  
2364 # given: synopsis;
2365  
2366 my $siblings = $path->siblings;
2367  
2368 # [
2369 # bless({ value => "t/data/moon" }, "Venus::Path"),
2370 # bless({ value => "t/data/sun" }, "Venus::Path"),
2371 # ]
2372  
2373 =back
2374  
2375 =cut
2376  
2377 =head2 test
2378  
2379 test(string $expr) (boolean)
2380  
2381 The test method evaluates the current path against the stackable file test
2382 operators provided.
2383  
2384 I<Since C<0.01>>
2385  
2386 =over 4
2387  
2388 =item test example 1
2389  
2390 # given: synopsis;
2391  
2392 my $test = $path->test;
2393  
2394 # -e $path
2395  
2396 # 1
2397  
2398 =back
2399  
2400 =over 4
2401  
2402 =item test example 2
2403  
2404 package main;
2405  
2406 use Venus::Path;
2407  
2408 my $path = Venus::Path->new('t/data/sun');
2409  
2410 my $test = $path->test('efs');
2411  
2412 # -e -f -s $path
2413  
2414 # 1
2415  
2416 =back
2417  
2418 =cut
2419  
2420 =head2 unlink
2421  
2422 unlink() (Venus::Path)
2423  
2424 The unlink method removes the file and returns a path object representing the
2425 removed file.
2426  
2427 I<Since C<0.01>>
2428  
2429 =over 4
2430  
2431 =item unlink example 1
2432  
2433 package main;
2434  
2435 use Venus::Path;
2436  
2437 my $path = Venus::Path->new('t/data/asteroid')->mkfile;
2438  
2439 my $unlink = $path->unlink;
2440  
2441 # bless({ value => "t/data/asteroid" }, "Venus::Path")
2442  
2443 =back
2444  
2445 =over 4
2446  
2447 =item unlink example 2
2448  
2449 package main;
2450  
2451 use Venus::Path;
2452  
2453 my $path = Venus::Path->new('/path/to/xyz');
2454  
2455 my $unlink = $path->unlink;
2456  
2457 # Exception! (isa Venus::Path::Error) (see error_on_unlink)
2458  
2459 =back
2460  
2461 =cut
2462  
2463 =head2 write
2464  
2465 write(string $data, string $binmode) (Venus::Path)
2466  
2467 The write method write the data provided to the file.
2468  
2469 I<Since C<0.01>>
2470  
2471 =over 4
2472  
2473 =item write example 1
2474  
2475 package main;
2476  
2477 use Venus::Path;
2478  
2479 my $path = Venus::Path->new('t/data/asteroid');
2480  
2481 my $write = $path->write('asteroid');
2482  
2483 =back
2484  
2485 =over 4
2486  
2487 =item write example 2
2488  
2489 package main;
2490  
2491 use Venus::Path;
2492  
2493 my $path = Venus::Path->new('/path/to/xyz');
2494  
2495 my $write = $path->write('nothing');
2496  
2497 # Exception! (isa Venus::Path::Error) (see error_on_write_open)
2498  
2499 =back
2500  
2501 =cut
2502  
2503 =head1 ERRORS
2504  
2505 This package may raise the following errors:
2506  
2507 =cut
2508  
2509 =over 4
2510  
2511 =item error: C<error_on_copy>
2512  
2513 This package may raise an error_on_copy exception.
2514  
2515 B<example 1>
2516  
2517 # given: synopsis;
2518  
2519 my $input = {
2520 throw => 'error_on_copy',
2521 error => $!,
2522 path => '/nowhere',
2523 };
2524  
2525 my $error = $path->catch('error', $input);
2526  
2527 # my $name = $error->name;
2528  
2529 # "on_copy"
2530  
2531 # my $message = $error->render;
2532  
2533 # "Can't copy \"t\/data\/planets\" to \"/nowhere\": $!"
2534  
2535 # my $path = $error->stash('path');
2536  
2537 # "/nowhere"
2538  
2539 # my $self = $error->stash('self');
2540  
2541 # bless({...}, 'Venus::Path')
2542  
2543 =back
2544  
2545 =over 4
2546  
2547 =item error: C<error_on_mkcall>
2548  
2549 This package may raise an error_on_mkcall exception.
2550  
2551 B<example 1>
2552  
2553 # given: synopsis;
2554  
2555 my $input = {
2556 throw => 'error_on_mkcall',
2557 error => $!,
2558 path => '/nowhere',
2559 };
2560  
2561 my $error = $path->catch('error', $input);
2562  
2563 # my $name = $error->name;
2564  
2565 # "on_mkcall"
2566  
2567 # my $message = $error->render;
2568  
2569 # "Can't make system call to \"/nowhere\": $!"
2570  
2571 # my $path = $error->stash('path');
2572  
2573 # "/nowhere"
2574  
2575 =back
2576  
2577 =over 4
2578  
2579 =item error: C<error_on_mkdir>
2580  
2581 This package may raise an error_on_mkdir exception.
2582  
2583 B<example 1>
2584  
2585 # given: synopsis;
2586  
2587 my $input = {
2588 throw => 'error_on_mkdir',
2589 error => $!,
2590 path => '/nowhere',
2591 };
2592  
2593 my $error = $path->catch('error', $input);
2594  
2595 # my $name = $error->name;
2596  
2597 # "on_mkdir"
2598  
2599 # my $message = $error->render;
2600  
2601 # "Can't make directory \"/nowhere\": $!"
2602  
2603 # my $path = $error->stash('path');
2604  
2605 # "/nowhere"
2606  
2607 =back
2608  
2609 =over 4
2610  
2611 =item error: C<error_on_mkfile>
2612  
2613 This package may raise an error_on_mkfile exception.
2614  
2615 B<example 1>
2616  
2617 # given: synopsis;
2618  
2619 my $input = {
2620 throw => 'error_on_mkfile',
2621 error => $!,
2622 path => '/nowhere',
2623 };
2624  
2625 my $error = $path->catch('error', $input);
2626  
2627 # my $name = $error->name;
2628  
2629 # "on_mkfile"
2630  
2631 # my $message = $error->render;
2632  
2633 # "Can't make file \"/nowhere\": $!"
2634  
2635 # my $path = $error->stash('path');
2636  
2637 # "/nowhere"
2638  
2639 =back
2640  
2641 =over 4
2642  
2643 =item error: C<error_on_move>
2644  
2645 This package may raise an error_on_move exception.
2646  
2647 B<example 1>
2648  
2649 # given: synopsis;
2650  
2651 my $input = {
2652 throw => 'error_on_move',
2653 error => $!,
2654 path => '/nowhere',
2655 };
2656  
2657 my $error = $path->catch('error', $input);
2658  
2659 # my $name = $error->name;
2660  
2661 # "on_move"
2662  
2663 # my $message = $error->render;
2664  
2665 # "Can't copy \"t\/data\/planets\" to \"/nowhere\": $!"
2666  
2667 # my $path = $error->stash('path');
2668  
2669 # "/nowhere"
2670  
2671 # my $self = $error->stash('self');
2672  
2673 # bless({...}, 'Venus::Path')
2674  
2675 =back
2676  
2677 =over 4
2678  
2679 =item error: C<error_on_open>
2680  
2681 This package may raise an error_on_open exception.
2682  
2683 B<example 1>
2684  
2685 # given: synopsis;
2686  
2687 my $input = {
2688 throw => 'error_on_open',
2689 error => $!,
2690 path => '/nowhere',
2691 };
2692  
2693 my $error = $path->catch('error', $input);
2694  
2695 # my $name = $error->name;
2696  
2697 # "on_open"
2698  
2699 # my $message = $error->render;
2700  
2701 # "Can't open \"/nowhere\": $!"
2702  
2703 # my $path = $error->stash('path');
2704  
2705 # "/nowhere"
2706  
2707 =back
2708  
2709 =over 4
2710  
2711 =item error: C<error_on_read_binmode>
2712  
2713 This package may raise an error_on_read_binmode exception.
2714  
2715 B<example 1>
2716  
2717 # given: synopsis;
2718  
2719 my $input = {
2720 throw => 'error_on_read_binmode',
2721 error => $!,
2722 path => '/nowhere',
2723 };
2724  
2725 my $error = $path->catch('error', $input);
2726  
2727 # my $name = $error->name;
2728  
2729 # "on_read_binmode"
2730  
2731 # my $message = $error->render;
2732  
2733 # "Can't binmode \"/nowhere\": $!"
2734  
2735 # my $path = $error->stash('path');
2736  
2737 # "/nowhere"
2738  
2739 =back
2740  
2741 =over 4
2742  
2743 =item error: C<error_on_read_error>
2744  
2745 This package may raise an error_on_read_error exception.
2746  
2747 B<example 1>
2748  
2749 # given: synopsis;
2750  
2751 my $input = {
2752 throw => 'error_on_read_error',
2753 error => $!,
2754 path => '/nowhere',
2755 };
2756  
2757 my $error = $path->catch('error', $input);
2758  
2759 # my $name = $error->name;
2760  
2761 # "on_read_error"
2762  
2763 # my $message = $error->render;
2764  
2765 # "Can't read from file \"/nowhere\": $!"
2766  
2767 # my $path = $error->stash('path');
2768  
2769 # "/nowhere"
2770  
2771 =back
2772  
2773 =over 4
2774  
2775 =item error: C<error_on_read_open>
2776  
2777 This package may raise an error_on_read_open exception.
2778  
2779 B<example 1>
2780  
2781 # given: synopsis;
2782  
2783 my $input = {
2784 throw => 'error_on_read_open',
2785 error => $!,
2786 path => '/nowhere',
2787 };
2788  
2789 my $error = $path->catch('error', $input);
2790  
2791 # my $name = $error->name;
2792  
2793 # "on_read_open"
2794  
2795 # my $message = $error->render;
2796  
2797 # "Can't read \"/nowhere\": $!"
2798  
2799 # my $path = $error->stash('path');
2800  
2801 # "/nowhere"
2802  
2803 =back
2804  
2805 =over 4
2806  
2807 =item error: C<error_on_rmdir>
2808  
2809 This package may raise an error_on_rmdir exception.
2810  
2811 B<example 1>
2812  
2813 # given: synopsis;
2814  
2815 my $input = {
2816 throw => 'error_on_rmdir',
2817 error => $!,
2818 path => '/nowhere',
2819 };
2820  
2821 my $error = $path->catch('error', $input);
2822  
2823 # my $name = $error->name;
2824  
2825 # "on_rmdir"
2826  
2827 # my $message = $error->render;
2828  
2829 # "Can't rmdir \"/nowhere\": $!"
2830  
2831 # my $path = $error->stash('path');
2832  
2833 # "/nowhere"
2834  
2835 =back
2836  
2837 =over 4
2838  
2839 =item error: C<error_on_unlink>
2840  
2841 This package may raise an error_on_unlink exception.
2842  
2843 B<example 1>
2844  
2845 # given: synopsis;
2846  
2847 my $input = {
2848 throw => 'error_on_unlink',
2849 error => $!,
2850 path => '/nowhere',
2851 };
2852  
2853 my $error = $path->catch('error', $input);
2854  
2855 # my $name = $error->name;
2856  
2857 # "on_unlink"
2858  
2859 # my $message = $error->render;
2860  
2861 # "Can't unlink \"/nowhere\": $!"
2862  
2863 # my $path = $error->stash('path');
2864  
2865 # "/nowhere"
2866  
2867 =back
2868  
2869 =over 4
2870  
2871 =item error: C<error_on_write_binmode>
2872  
2873 This package may raise an error_on_write_binmode exception.
2874  
2875 B<example 1>
2876  
2877 # given: synopsis;
2878  
2879 my $input = {
2880 throw => 'error_on_write_binmode',
2881 error => $!,
2882 path => '/nowhere',
2883 binmode => ':utf8',
2884 };
2885  
2886 my $error = $path->catch('error', $input);
2887  
2888 # my $name = $error->name;
2889  
2890 # "on_write_binmode"
2891  
2892 # my $message = $error->render;
2893  
2894 # "Can't binmode \"/nowhere\": $!"
2895  
2896 # my $binmode = $error->stash('binmode');
2897  
2898 # ":utf8"
2899  
2900 # my $path = $error->stash('path');
2901  
2902 # "/nowhere"
2903  
2904 =back
2905  
2906 =over 4
2907  
2908 =item error: C<error_on_write_error>
2909  
2910 This package may raise an error_on_write_error exception.
2911  
2912 B<example 1>
2913  
2914 # given: synopsis;
2915  
2916 my $input = {
2917 throw => 'error_on_write_error',
2918 error => $!,
2919 path => '/nowhere',
2920 };
2921  
2922 my $error = $path->catch('error', $input);
2923  
2924 # my $name = $error->name;
2925  
2926 # "on_write_error"
2927  
2928 # my $message = $error->render;
2929  
2930 # "Can't write to file \"/nowhere\": $!"
2931  
2932 # my $path = $error->stash('path');
2933  
2934 # "/nowhere"
2935  
2936 =back
2937  
2938 =over 4
2939  
2940 =item error: C<error_on_write_open>
2941  
2942 This package may raise an error_on_write_open exception.
2943  
2944 B<example 1>
2945  
2946 # given: synopsis;
2947  
2948 my $input = {
2949 throw => 'error_on_write_open',
2950 error => $!,
2951 path => '/nowhere',
2952 };
2953  
2954 my $error = $path->catch('error', $input);
2955  
2956 # my $name = $error->name;
2957  
2958 # "on_write_open"
2959  
2960 # my $message = $error->render;
2961  
2962 # "Can't write \"/nowhere\": $!"
2963  
2964 # my $path = $error->stash('path');
2965  
2966 # "/nowhere"
2967  
2968 =back
2969  
2970 =head1 OPERATORS
2971  
2972 This package overloads the following operators:
2973  
2974 =cut
2975  
2976 =over 4
2977  
2978 =item operation: C<("")>
2979  
2980 This package overloads the C<""> operator.
2981  
2982 B<example 1>
2983  
2984 # given: synopsis;
2985  
2986 my $result = "$path";
2987  
2988 # "t/data/planets"
2989  
2990 B<example 2>
2991  
2992 # given: synopsis;
2993  
2994 my $mercury = $path->child('mercury');
2995  
2996 my $result = "$path, $path";
2997  
2998 # "t/data/planets, t/data/planets"
2999  
3000 =back
3001  
3002 =over 4
3003  
3004 =item operation: C<(.)>
3005  
3006 This package overloads the C<.> operator.
3007  
3008 B<example 1>
3009  
3010 # given: synopsis;
3011  
3012 my $result = $path . '/earth';
3013  
3014 # "t/data/planets/earth"
3015  
3016 =back
3017  
3018 =over 4
3019  
3020 =item operation: C<(eq)>
3021  
3022 This package overloads the C<eq> operator.
3023  
3024 B<example 1>
3025  
3026 # given: synopsis;
3027  
3028 my $result = $path eq 't/data/planets';
3029  
3030 # 1
3031  
3032 =back
3033  
3034 =over 4
3035  
3036 =item operation: C<(ne)>
3037  
3038 This package overloads the C<ne> operator.
3039  
3040 B<example 1>
3041  
3042 # given: synopsis;
3043  
3044 my $result = $path ne 't/data/planets/';
3045  
3046 # 1
3047  
3048 =back
3049  
3050 =over 4
3051  
3052 =item operation: C<(qr)>
3053  
3054 This package overloads the C<qr> operator.
3055  
3056 B<example 1>
3057  
3058 # given: synopsis;
3059  
3060 my $result = 't/data/planets' =~ $path;
3061  
3062 # 1
3063  
3064 =back
3065  
3066 =over 4
3067  
3068 =item operation: C<(~~)>
3069  
3070 This package overloads the C<~~> operator.
3071  
3072 B<example 1>
3073  
3074 # given: synopsis;
3075  
3076 my $result = $path ~~ 't/data/planets';
3077  
3078 # 1
3079  
3080 =back
3081  
3082 =head1 AUTHORS
3083  
3084 Awncorp, C<awncorp@cpan.org>
3085  
3086 =cut
3087  
3088 =head1 LICENSE
3089  
3090 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
3091  
3092 This program is free software, you can redistribute it and/or modify it under
3093 the terms of the Apache license version 2.0.
3094  
3095 =cut
« blib/lib/Venus/Array.pm ↑ Summary blib/lib/Venus/Type.pm »