@@ -20,35 +20,43 @@ increase the performance or maintainability.
20
20
21
21
=head1 Functions
22
22
23
- =head2 print()
24
- X<print()>
23
+ In alphabetical order.
25
24
26
- sub print(*@text --> Bool) is export
25
+ =head2 chdir()
26
+ X<chdir()>
27
27
28
- Print the given text (as C< Str> objects) on $*OUT. Return whether successful.
28
+ sub chdir( Str(Any) $dir, Str(Any) $CWD = $*CWD --> Bool) is export
29
29
30
- =head2 say()
31
- X<say()>
30
+ Changes the current working directory to the given directory, for the scope in
31
+ which C<$*CWD> is active. Optionally takes a second positional parameter to
32
+ indicate from which directory any relative path specified in the first
33
+ positional parameter, should be taken. Returns C<True> if successful, or an
34
+ appropriate C<Failure>.
32
35
33
- sub say(*@text --> Bool) is export
36
+ Please note that this directory has B<no> connection with whatever the
37
+ operating system thinks is the current working directory. The value of
38
+ C<$*CWD> just will always be prepended to any relative paths in any file
39
+ operation in Perl 6.
34
40
35
- Print the given text, followed by a new line C<"\n"> on C<$*OUT>. Before
36
- printing, call the C<.gist> method on any non-C<Str> objects. Return whether
37
- successful.
41
+ Normal usage:
38
42
39
- =head2 note()
40
- X<note()>
43
+ chdir("foo");
41
44
42
- sub note(*@text --> Bool) is export
45
+ A typically lexical scope bound use case:
43
46
44
- Print the given text, followed by a new line C<"\n"> on C<$*ERR>. Before
45
- printing, call the C<.gist> method on any non-C<Str> objects. Return whether
46
- successful.
47
+ {
48
+ my $*CWD;
49
+ chdir("foo");
50
+ # working directory changed to "foo"
51
+ }
52
+ # restored to what it was
53
+
54
+ But for the latter, you're probably better off using L</indir()>.
47
55
48
56
=head2 dd()
49
57
X<dd()>
50
58
51
- sub dd(@vars --> Bool) is export
59
+ sub dd(@vars --> Bool) is export
52
60
53
61
Tiny Data Dumper. Takes the C<variables> specified and C<note>s them (on
54
62
C<$*ERR>) in an easy to read format, along with the C<name> of the variable.
57
65
my $a = 42;
58
66
dd($a); # notes "$a = 42"
59
67
60
- =head2 prompt()
61
- X<prompt()>
68
+ Returns C<True> (not that that will matter most of the time).
62
69
63
- sub prompt($msg --> Bool) is export
70
+ =head2 dir()
71
+ X<dir()>
64
72
65
- Simple Prompter. Print message (as C<Str> object) on C<$*OUT> and obtains a
66
- single line of input from C<$*IN>.
73
+ sub dir(
74
+ Str(Any) $dir = $*CWD,
75
+ Str(Any) $from = $*CWD,
76
+ Mu :$test = (exclude . and ..),
77
+ Bool :$Str = False,
78
+ --> List ) is export
79
+
80
+ Returns a lazy list of objects doing the C<IO::Pathy> role for the directory
81
+ entries in the given the C<$dir>. Optionally takes a second positional
82
+ parameter to be used as the root for any relative path specified as the first
83
+ positional. Defaults to the directory pointed to by C<$*CWD>.
84
+ If dir() fails, it returns an L<X::IO::Dir|S32::Exception/X::IO::Dir> failure.
85
+ The following named parameters are optional:
86
+
87
+ =over 4
88
+
89
+ =item :test
90
+
91
+ Expression against which to smart-match for inclusion in result list. By
92
+ default excludes C<"."> and C<".."> only.
93
+
94
+ =item :Str
95
+
96
+ Boolean indicating to return absolute C<Str>ings, rather than objects doing
97
+ the C<IO::Pathy> role. False by default.
98
+
99
+ =back
100
+
101
+ =head2 indir()
102
+ X<indir()>
103
+
104
+ sub indir(Str(Any) $dir, &what, Str(Any) $CWD = $*CWD) is export
105
+
106
+ Change to the directory indicated by the first positional, and execute the
107
+ code given by the second positional. Optionally specify the directory to
108
+ which any relative dir should be applied. Returns whatever the code returns.
109
+
110
+ =head2 mkdir()
111
+ X<mkdir()>
112
+
113
+ multi sub mkdir(Str(Any) $dir, Int $mode = 0o777 --> Bool)
114
+
115
+ Create directory indicated by the first positional, with the (optional) mode
116
+ as the second positional. Return True if successful, or an appropriate
117
+ C<Failure>.
118
+
119
+ multi sub mkdir(Int $mode, *@dir --> List)
120
+
121
+ Use the first positional parameter C<Int> value as mode with which to create
122
+ the directories specified with the other positional parameters. Returns a
123
+ C<List> with the directories that were successfully created.
124
+
125
+ =head2 move()
126
+ X<move()>
127
+
128
+ sub move(
129
+ Str(Any) $src,
130
+ Str(Any) $dest,
131
+ Bool :$createonly,
132
+ --> Bool ) is export
133
+
134
+ Moves a file, as indicate by the first positional parameter, by copying its
135
+ contents to the destination specified, and then removing the file at the
136
+ original location. If the destination is a directory, moves the file into
137
+ that directory. If :createonly is set to True, the move fails if a
138
+ directory entry already exists at the destination. Returns C<True> upon
139
+ success, or an appropriate C<Failure> if the operation could not be completed.
140
+
141
+ Please use L</rename()> if a file can be moved by renaming (which is usually
142
+ possible if the destination is on the same different physical storage device).
143
+ Alternately, the C<move()> function is free to try the C<rename()> first,
144
+ and if that (silently) fails, do it the hard way.
145
+
146
+ =head2 note()
147
+ X<note()>
148
+
149
+ sub note(*@text --> Bool) is export
150
+
151
+ Print the given text, followed by a new line C<"\n"> on C<$*ERR>. Before
152
+ printing, call the C<.gist> method on any non-C<Str> objects. Return whether
153
+ successful.
67
154
68
155
=head2 open()
69
156
X<open()>
@@ -136,46 +223,38 @@ C<.lines> and C<.get>. Defaults to C<True>.
136
223
137
224
=back
138
225
139
- =head2 dir()
140
- X<dir()>
141
-
142
- sub dir($directory as Str = $*CWD,
143
- Mu :$test = (exclude . and ..)
144
- Bool :$Str = False,
145
- :$CWD = $*CWD.Str,
146
- --> List ) is export
147
-
148
- Returns a lazy list directory entries in given the C<$directory> as objects
149
- doing the C<IO::Pathy> role. Defualts to the directory pointed to by C<$*CWD>.
150
- If dir() fails, it returns an L<X::IO::Dir|S32::Exception/X::IO::Dir> failure.
151
- The following named parameters are optional:
226
+ =head2 print()
227
+ X<print()>
152
228
153
- =over 4
229
+ sub print(*@text --> Bool) is export
154
230
155
- =item :test
231
+ Print the given text (as C<Str> objects) on $*OUT. Return whether successful.
156
232
157
- Expression against which to smart-match for inclusion in result list. By
158
- default excludes C<"."> and C<".."> only.
233
+ =head2 prompt()
234
+ X<prompt()>
159
235
160
- =item : Str
236
+ sub prompt( Str(Any) $msg --> Str) is export
161
237
162
- Boolean indicating to return absolute C<Str>ings, rather than objects doing
163
- the C<IO::Path> role. False by default .
238
+ Simple Prompter. Print message (as C<Str> object) on C<$*OUT> and obtains a
239
+ single line of input from C<$*IN>, which is returned .
164
240
165
- =item :CWD
241
+ =head2 say()
242
+ X<say()>
166
243
167
- The directory to pre-pend to C<$directory> if specified as a relative path.
168
- Defaults to C<$*CWD>.
244
+ sub say(*@text --> Bool) is export
169
245
170
- =back
246
+ Print the given text, followed by a new line C<"\n"> on C<$*OUT>. Before
247
+ printing, call the C<.gist> method on any non-C<Str> objects. Return whether
248
+ successful.
171
249
172
250
=head2 slurp()
173
251
X<slurp()>
174
252
175
- sub slurp ($what = $*ARGFILES,
176
- Bool :$bin = False,
177
- Str :$enc = "Unicode",
178
- --> Str|Buf ) is export
253
+ sub slurp(
254
+ $what = $*ARGFILES, # XXX need to generalize $*ARGFILES behaviour
255
+ Bool :$bin = False,
256
+ Str :$enc = "Unicode",
257
+ --> Str|Buf ) is export
179
258
180
259
Slurps the contents of the entire file into a C<Str> (or C<Buf> if C<:bin>).
181
260
Accepts C<:bin> and C<:enc> optional named parameters, with the same meaning
@@ -185,11 +264,11 @@ directory.
185
264
=head2 spurt()
186
265
X<spurt()>
187
266
188
- sub spurt ($where, $what,
189
- Str :$enc = $*ENC,
190
- Bool :append = False,
191
- Bool :$createonly = False,
192
- --> Bool ) is export
267
+ sub spurt ($where, $what,
268
+ Str :$enc = $*ENC,
269
+ Bool :$ append = False,
270
+ Bool :$createonly = False,
271
+ --> Bool ) is export
193
272
194
273
Writes the indicated contents (2nd positional parameter) to the location
195
274
indicated by the first positional parameter (which can either be a string,
@@ -219,21 +298,6 @@ C<False>.
219
298
220
299
=back
221
300
222
- =head2 mkdir()
223
- X<mkdir()>
224
-
225
- multi sub mkdir($dir, Int $mode = 0o777 --> Bool)
226
-
227
- Create directory indicated by the first positional, with the (optional) mode
228
- as the second positional. Return True if successful, or an appropriate
229
- C<Failure>.
230
-
231
- multi sub mkdir(Int $mode, *@dir --> List)
232
-
233
- Use the first positional parameter C<Int> value as mode with which to create
234
- the directories specified with the other positional parameters. Returns a
235
- C<List> with the directories that were successfully created.
236
-
237
301
=head2 rmdir()
238
302
X<rmdir()>
239
303
@@ -242,48 +306,16 @@ X<rmdir()>
242
306
Removes the (empty) directory as indicated by the positional parameter.
243
307
Returns C<True> on success or an appropriate C<Failure>.
244
308
245
- =head2 chdir()
246
- X<chdir()>
247
-
248
- sub chdir($dir as IO, $CWD = $*CWD,
249
- :$test = <d r>
250
- --> Bool) is export
251
-
252
- Changes the current working directory to the given directory, for the scope in
253
- which C<$*CWD> is active (if no second positional parameter is given) or for
254
- the scope of the indicated localized C<$*CWD>. A typical use case:
255
-
256
- {
257
- chdir("foo", my $*CWD);
258
- # working directory changed to "foo"
259
- }
260
- # restored to what it was
261
-
262
- Returns C<True> if successful, or an appropriate C<Failure>, e.g if the
263
- directory does not exist, or is not a directory, or is not readable.
264
-
265
- Please note that this directory has B<no> connection with whatever the
266
- operating system thinks is the current working directory. The value of
267
- C<$*CWD> just will always be prepended to any relative paths in any file
268
- operation in Perl 6.
269
-
270
- Also note that you can use C<chdir> to set similar dynamic variables, like
271
- C<$*TMPDIR> and C<$*HOME> this way:
272
-
273
- chdir("bar", my $*TMPDIR); # set $*TMPDIR in this scope
274
- chdir("bar", my $*HOME); # set $*HOME in this scope
275
-
276
309
=head2 copy()
277
310
X<copy()>
278
311
279
- sub copy ($source as IO, $dest as IO,
280
- :$createonly = False,
281
- --> Bool ) is export
312
+ sub copy(Str(Any) $src, Str(Any) $dst, :$createonly --> Bool) is export
282
313
283
314
Copies a file, as indicate by the first positional parameter, to the
284
- destination specified. If :createonly is set to True, copy fails if a file
285
- already exists in the destination. Returns C<True> upon success, or an
286
- appropriate C<Failure> if the operation could not be completed.
315
+ destination specified. Optionally takes a named parameter C<:createonly>:
316
+ if set to True, the copy will fail if a directory entry already exists at the
317
+ destination. Returns C<True> upon success, or an appropriate C<Failure> if
318
+ the operation could not be completed.
287
319
288
320
=head2 rename()
289
321
X<rename()>
@@ -300,23 +332,13 @@ an appropriate C<Failure> if the operation could not be completed.
300
332
Please use L</move()> if a file could not be moved by renaming (usually because
301
333
the destination is on a different physical storage device).
302
334
303
- =head2 move ()
304
- X<move ()>
335
+ =head2 tmpdir ()
336
+ X<tmpdir ()>
305
337
306
- sub move ($source as IO, $dest as IO,
307
- :$createonly = False,
308
- --> Bool ) is export
309
-
310
- Moves a file, as indicate by the first positional parameter, by copying its
311
- contents to the destination specified, and then removing the file at the
312
- original location. If :createonly is set to True, the move fails if a file
313
- already exists in the destination. Returns C<True> upon success, or an
314
- appropriate C<Failure> if the operation could not be completed.
338
+ sub tmpdir(Str(Any) $dir, Str(Any) $CWD = $*CWD --> Bool) is export
315
339
316
- Please use L</rename()> if a file can be moved by renaming (which is usually
317
- possible if the destination is on the same different physical storage device).
318
- Alternately, the C<move()> function is free to try the C<rename()> first,
319
- and if that (silently) fails, do it the hard way.
340
+ Similar in functionality to L</chdir()>, but instead sets the dynamic
341
+ variable C<$*TMPDIR> (rather than $*CWD).
320
342
321
343
=head2 unlink()
322
344
X<unlink()>
0 commit comments