Skip to content

Commit 9607528

Browse files
committed
add visitdir and PROCESS::chdir, retarget chdir
1 parent 1b16c7b commit 9607528

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

S32-setting-library/IO.pod

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ DRAFT: Synopsis 32: Setting Library - IO
2222

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

25-
Last Modified: 30 May 2013
26-
Version: 20
25+
Last Modified: 19 Aug 2013
26+
Version: 21
2727

2828
The document is a draft.
2929

@@ -181,7 +181,30 @@ other error in opening, writing, or closing.
181181
multi sub chdir(Str:D)
182182
multi sub chdir(IO::Path::D)
183183

184-
Changes the current working directory to the new value. Fails (X::IO::Chdir) on error.
184+
Changes the current (emulated) working directory to the new value, scoped to the current scope of C<$*CWD> (usually thread-local at worst, or the scope of a C<visitdir> inside the current thread). Fails (X::IO::Chdir) on error.
185+
If C<$*CWD> is not scoped to the current dynamic scope, you must call C<chdir> again when exiting the
186+
dynamic scope to get back to the original directly, just as you would with a real C<chdir>. In this case
187+
you would probably be better off using C<visitdir> instead, which will automatically scope C<$*CWD> to the current
188+
dynamic scope.
189+
190+
Note that actually changing the process's working directory requires
191+
a call to C<PROCESS::chdir> (which will inform the chdir emulation
192+
that the process's actual current working directory has changed).
193+
This function is not threadsafe, however. And if calling out to a
194+
foreign function, only one thread can safely use it; in general it's
195+
better to pass absolute paths to foreign functions that don't allow
196+
you to set the working directory as a parameter.
197+
198+
=item visitdir
199+
200+
multi sub visitdir(Str:D)
201+
multi sub visitdir(IO::Path::D)
202+
203+
Changes the current (emulated) working directory to the new
204+
value, scoped to the current dynamic scope just as C<temp $*CWD = newdir();>
205+
would. Fails (X::IO::Chdir) on error. Since C<$*CWD> is dynamically scoped,
206+
leaving the current dynamic scope automatically restores the current (emulated)
207+
working directory.
185208

186209
=item unlink
187210

0 commit comments

Comments
 (0)