You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Created: 19 Feb 2009 extracted from S29-functions.pod; added stuff from S16-IO later
24
24
25
-
Last Modified: 30 May 2013
26
-
Version: 20
25
+
Last Modified: 19 Aug 2013
26
+
Version: 21
27
27
28
28
The document is a draft.
29
29
@@ -181,7 +181,30 @@ other error in opening, writing, or closing.
181
181
multi sub chdir(Str:D)
182
182
multi sub chdir(IO::Path::D)
183
183
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)
0 commit comments