@@ -63,6 +63,40 @@ to specify which file tests to perform.
63
63
&*chdir('/tmp'); # change $*CWD and process's current directory to '/tmp'
64
64
&*chdir('/not-there'); # returns Failure
65
65
66
+ = head2 sub indir
67
+
68
+ Defined as:
69
+
70
+ sub indir(IO() $path, &code, :$d = True, :$r, :$w, :$x --> Mu)
71
+
72
+ Takes L « C < Callable > |/type/Callable» C < &code > and executes it after locally (to
73
+ C < &code > ) changing C < $*CWD > variable to C < $path > , optionally ensuring
74
+ the new path passes several file tests. B < NOTE: > that this routine does I < NOT >
75
+ alter the process's current directory (see
76
+ L « C < &*chdir > |/routine/$AMPERSAND*chdir» ). The C < $*CWD > outside of the C < &code >
77
+ is not affected, even if C < &code > explicitly assignes a new value to C < $*CWD > .
78
+
79
+ Returns the return value of C < &code > on success. On failure to successfully
80
+ change C < $*CWD > , returns L « C < Failure > |/type/Failure» .
81
+ The C < $path > can be any object with an IO method that returns an
82
+ L « C < IO::Path > |/type/IO::Path» object. The available file tests are:
83
+
84
+ = item C < :d > — check L « C < .d > |/routine/d» returns C < True >
85
+
86
+ = item C < :r > — check L « C < .r > |/routine/d» returns C < True >
87
+
88
+ = item C < :w > — check L « C < .w > |/routine/d» returns C < True >
89
+
90
+ = item C < :x > — check L « C < .x > |/routine/d» returns C < True >
91
+
92
+ By default, only C < :d > test is performed.
93
+
94
+ say $*CWD; # OUTPUT: «"/home/camelia".IO»
95
+ indir '/tmp', { say $*CWD }; # OUTPUT: «"/tmp".IO»
96
+ say $*CWD; # OUTPUT: «"/home/camelia".IO»
97
+
98
+ indir '/not-there', {;}; # returns Failure; path does not exist
99
+
66
100
= head2 sub print
67
101
68
102
Print the given text on C < $*OUT > (standard output), e.g.:
0 commit comments