Skip to content

Instantly share code, notes, and snippets.

@labster
Created March 28, 2013 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labster/5267241 to your computer and use it in GitHub Desktop.
Save labster/5267241 to your computer and use it in GitHub Desktop.
new spec for IO::Path
=head2 IO::Path
class IO::Path is Cool does IO::FileTest { }
Holds a path of a file or directory. The path is generally divided
into three parts, the I<volume>, I<directory> and I<base name>.
On Windows, the volume is a drive letter like C<C:>, or a UNC network volume
like C<\\share\>. On UNIX-based systems, the volume part is empty.
The base name is name of the file or directory that the IO::Path object
represents, and the directory is the part of the path leading up to the base
name.
path volume directory base name
/usr/bin/gvim /usr/bin gvim
/usr/bin/ /usr bin
C:\temp\f.txt C: temp f.txt
=over 4
=item Str
Stringification returns the path (volume, directory and base name joined
together) as a string.
=item volume
Returns the volume part of the path
=item directory
Returns the directory part of the path
=item basename
Returns the base name part of the path
=item path
Returns the entire IO::Path object (a no-op).
=item is-relative
Returns True if the path is a relative path (like C<foo/bar>), False
otherwise.
=item is-absolute
Returns True if the path is an absolute path (like C</usr/bin>), False
otherwise.
=item absolute
method absolute ( Str $base = $*CWD )
Transforms the path into an absolute form, and returns the result as a new
IO::Path. If C<$base> is supplied, transforms it relative to that base
directory; otherwise the current working directory is used. Paths that are
already absolute are returned unchanged.
=item relative
method relative ( Str $base = $*CWD )
Transforms the path into an relative form, and returns the result as a new
IO::Path. If C<$base> is supplied, transforms it relative to that base
directory; otherwise the current working directory is used. Paths that are
already relative are returned unchanged.
=back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment