class IO::Path::Parts
Error ReportCollection examples

IO::Path parts encapsulation

class IO::Path::Parts does Positional does Associative does Iterable { }

An IO::Path::Parts object is a container for the parts of an IO::Path object. It is usually created with a call to the method .parts on a IO::Path object. It can also be created with a call to the method .split on a object of one of the low-level path operations sub-classes of IO::Spec.

The parts of an IO::Path are:


method new

method new(\volume, \dirname, \basename)

Create a new IO::Path::Parts object with \volume, \dirname and \basename as respectively the volume, directory name and basename parts.

attribute volume

Read-only. Returns the volume of the IO::Path::Parts object.

# OUTPUT: «C:␤» 

attribute dirname

Read-only. Returns the directory name part of the IO::Path::Parts object.

# OUTPUT: «/some/dir␤» 

attribute basename

Read-only. Returns the basename part of the IO::Path::Parts object.

# OUTPUT: «foo.txt␤» 

Previous implementations

Before Rakudo 2020.06 the .parts method of IO::Path returned a Map and the .split routine of the IO::Spec sub-classes returned a List of Pair. The IO::Path::Part class maintains compatibility with these previous implementations by doing Positional, Associative and Iterable.

my $parts = IO::Path::Parts.new('C:''/some/dir''foo.txt');
say $parts<volume>;      # OUTPUT: «C:␤» 
say $parts[0];           # OUTPUT: «volume => C:␤» 
say $parts[0].^name;     # OUTPUT: «Pair␤» 
.say for $parts[];
# OUTPUT: «volume => C:␤dirname => /some/dir␤basename => foo.txt␤»