Skip to content

Commit 6960683

Browse files
committed
Change IO::Path stringification, add new methods.
.Str returns full path instead of basename .path is now a no-op (so Str.path.path still returns IO::Path) .contents is now documented - lists the directory .is-absolute, .is-relative, .absolute, .relative added
1 parent eb862b2 commit 6960683

File tree

1 file changed

+61
-18
lines changed

1 file changed

+61
-18
lines changed

S32-setting-library/IO.pod

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ DRAFT: Synopsis 32: Setting Library - IO
1717
Tim Nelson <wayland@wayland.id.au>
1818
Daniel Ruoso <daniel@ruoso.com>
1919
Lyle Hopkins <webmaster@cosmicperl.com>
20+
Brent Laabs <bslaabs@gmail.com>
2021

2122
=head1 VERSION
2223

2324
Created: 19 Feb 2009 extracted from S29-functions.pod; added stuff from S16-IO later
2425

25-
Last Modified: 14 July 2012
26-
Version: 16
26+
Last Modified: 28 March 2013
27+
Version: 17
2728

2829
The document is a draft.
2930

@@ -96,7 +97,9 @@ and the parent directory are excluded, which can be controlled with the
9697
C<$test> named parameter. Only items that smart-match against this test are
9798
returned.
9899

99-
The return value is a list of C<IO::File> and C<IO::Dir> objects.
100+
The return value is a list of C<IO::File> and C<IO::Dir> objects. Because of
101+
this, you may want use the C<basename> method on the results to get the just
102+
the file name, without its full path.
100103

101104
=item note
102105

@@ -391,31 +394,30 @@ TODO: methods created, accessed, modified
391394
class IO::Path is Cool does IO::FileTest { }
392395

393396
Holds a path of a file or directory. The path is generally divided
394-
into three parts, the I<file system>, I<directory> and I<base name>.
397+
into three parts, the I<volume>, I<directory> and I<base name>.
395398

396-
On Windows, the file system is a drive letter like C<C:>. Relative paths
397-
never have a file system part. On UNIX-based systems, the file system part
398-
is empty.
399+
On Windows, the volume is a drive letter like C<C:>, or a UNC network volume
400+
like C<\\share\>. On UNIX-based systems, the volume part is empty.
399401

400402
The base name is name of the file or directory that the IO::Path object
401403
represents, and the directory is the part of the path leading up to the base
402404
name.
403405

404-
path file system directory base name
405-
/usr/bin/gvim /usr/bin gvim
406-
/usr/bin/ /usr bin
407-
C:\temp\f.txt C: temp f.txt
406+
path volume directory base name
407+
/usr/bin/gvim /usr/bin gvim
408+
/usr/bin/ /usr bin
409+
C:\temp\f.txt C: temp f.txt
408410

409411
=over 4
410412

411-
=item path
413+
=item Str
412414

413-
Returns the path (file system, directory and base name joined together) as
414-
a string.
415+
Stringification returns the path (volume, directory and base name joined
416+
together) as a string.
415417

416-
=item filesystem
418+
=item volume
417419

418-
Returns the file system part of the path
420+
Returns the volume part of the path
419421

420422
=item directory
421423

@@ -425,9 +427,50 @@ Returns the directory part of the path
425427

426428
Returns the base name part of the path
427429

428-
=item Str
430+
=item path
431+
432+
Returns the entire IO::Path object (a no-op).
433+
434+
=item contents
435+
436+
method contents( Mu :$test = none('.', '..') )
437+
438+
Returns a lazy list of file names in the path, if it is a directory. The
439+
current and the parent directory are excluded, which can be controlled with
440+
the C<$test> named parameter. Only items that smart-match against this test
441+
are returned.
442+
443+
The return value is a list of C<IO::File> and C<IO::Dir> objects. Because of
444+
this, you may want use the C<basename> method on the results to get the just
445+
the file name, without its full path.
446+
447+
=item is-relative
448+
449+
Returns True if the path is a relative path (like C<foo/bar>), False
450+
otherwise.
451+
452+
=item is-absolute
453+
454+
Returns True if the path is an absolute path (like C</usr/bin>), False
455+
otherwise.
456+
457+
=item absolute
458+
459+
method absolute ( Str $base = $*CWD )
460+
461+
Transforms the path into an absolute form, and returns the result as a new
462+
IO::Path. If C<$base> is supplied, transforms it relative to that base
463+
directory; otherwise the current working directory is used. Paths that are
464+
already absolute are returned unchanged.
465+
466+
=item relative
467+
468+
method relative ( Str $base = $*CWD )
429469

430-
Stringifies to the base name.
470+
Transforms the path into an relative form, and returns the result as a new
471+
IO::Path. If C<$base> is supplied, transforms it relative to that base
472+
directory; otherwise the current working directory is used. Paths that are
473+
already relative are returned unchanged.
431474

432475
=back
433476

0 commit comments

Comments
 (0)