Combined from primary sources listed below.
See primary docmentation in context for method chdir.
multi method chdir(IO::Path:D: IO $path, |c)
multi method chdir(IO::Path:D: Str() $path, :$d = True, :$r, :$w, :$x)
Contrary to the name, the .chdir method does not change any directories, but merely concatenates the given $path to the invocant and returns the resultant IO::Path. Optional file tests can be performed by providing :d, :r, :w, or :x Bool named arguments; when set to True, they'll perform .d, .r, .w, and .x tests respectively. By default, only :d is set to True.
See primary docmentation in context for sub chdir.
sub chdir(IO() $path, :$d = True, :$r, :$w, :$x --> IO::Path:D)
Changes value of $*CWD variable to the provided $path, optionally ensuring the new path passes several file tests. NOTE: that this routine does NOT alter the process's current directory (see &*chdir).
Returns IO::Path representing new $*CWD on success. On failure, returns Failure and leaves $*CWD untouched. The $path can be any object with an IO method that returns an IO::Path object. The available file tests are:
:d — check .d returns True
:r — check .r returns True
:w — check .w returns True
:x — check .x returns True
By default, only :d test is performed.
chdir '/tmp'; # change $*CWD to '/tmp' and check its .d is True
chdir :r, :w, '/tmp'; # … check its .r and .w are True
chdir '/not-there'; # returns Failure
Note that the following construct is a mistake:
# WRONG! DO NOT DO THIS!
my $*CWD = chdir '/tmp/';
Use indir instead.