File tree Expand file tree Collapse file tree 3 files changed +36
-22
lines changed Expand file tree Collapse file tree 3 files changed +36
-22
lines changed Original file line number Diff line number Diff line change @@ -353,24 +353,13 @@ exist, or is a directory.
353
353
354
354
= head2 sub spurt
355
355
356
- = for code :skip-test
357
- sub spurt($where, $what,
358
- Str :$enc = 'utf8',
359
- Bool :$bin = False,
360
- Bool :$append = False,
361
- Bool :$createonly = False
362
- --> Bool )
363
-
364
- Writes the indicated contents (2nd positional parameter, C < $what > ) to the
365
- location indicated by the first positional parameter, C < $where > (which can
366
- either be a string or an C < IO::Path > object). To write to an C < IO::Handle > ,
367
- use the L < print > method.
368
-
369
- If a file needs to be opened for writing, it will also be C < close > d. Returns
370
- C < True > on success, or the appropriate C < Failure > if something went wrong.
371
-
372
- These named parameters are optional and only have meaning if the first
373
- positional parameter was B < not > an C < IO::Handle > :
356
+ Defined as:
357
+
358
+ multi slurp(IO() $path, |c)
359
+
360
+ The C < $path > can be any object with an IO method that returns an
361
+ L « C < IO::Path > |/type/IO::Path» object. Calls L « C < IO::Path.spurt > |/routine/spurt»
362
+ on the C < $path > , forwarding any of the remaining arguments.
374
363
375
364
= head3 Options
376
365
Original file line number Diff line number Diff line change @@ -88,6 +88,20 @@ on strings.
88
88
my $fh = open 'path/to/file', :r;
89
89
$fn.split(' ', close => True); # Returns file content split by a space and closes file;
90
90
91
+ = head2 method spurt
92
+
93
+ multi method spurt(IO::Handle:D: Blob $data, :$close = False)
94
+ multi method spurt(IO::Handle:D: Cool $data, :$close = False)
95
+
96
+ Writes all of the C < $data > into the filehandle, closing it when finished,
97
+ if C < $close > is C < True > . For L « C < Cool > |/type/Cool» C < $data > , will use the
98
+ encoding the handle is set to use (L « C < IO::Handle.open > |/routine/open»
99
+ or L « C < IO::Handle.encoding > |/routine/encoding» ).
100
+
101
+ Behaviour for spurting a L « C < Cool > |/type/Cool» when the handle is in binary
102
+ mode or spurting a L « C < Blob > |/type/Blob» when the handle is NOT in binary
103
+ mode is undefined.
104
+
91
105
= head2 method comb
92
106
93
107
multi method comb(IO::Handle:D: :$close = False)
Original file line number Diff line number Diff line change @@ -321,12 +321,23 @@ Returns C<Bool::True> if the invocant is a path and the size is 0.
321
321
322
322
Return the file content for this path, like L < slurp|/routine/slurp > .
323
323
324
- = head2 routine spurt
324
+ = head2 method spurt
325
325
326
- multi method spurt(IO::Path:D: Blob $contents, :$bin, |c)
327
- multi method spurt(IO::Path:D: Cool $contents, :$bin, |c)
326
+ method spurt(IO::Path:D: $data, :$enc, :$append, :$createonly)
328
327
329
- Write C < $contents > to this path, like L < spurt|/routine/spurt > .
328
+ Opens the file path for writing, and writes all of the C < $data > into it.
329
+ Will L « C < fail > |/routine/fail» if it cannot succeed for any reason.
330
+ The C < $data > can be any L « C < Cool > |/type/Cool» type or any L « C < Blob > |/type/Blob»
331
+ type. Arguments are as follows:
332
+
333
+ = item C < :$enc > — character encoding of the data. Takes same values as C < :$enc >
334
+ in L « C < IO::Handle.open > |/routine/open» . Defaults to C < utf8 > . Ignored if C < $data >
335
+ is a L « C < Blob > |/type/Blob» .
336
+
337
+ = item C < :$append > — open the file in C < append > mode, preserving existing
338
+ contents, and appending data to the end of the file.
339
+
340
+ = item C < :$createonly > — L « C < fail > |/routine/fail» if the file already exists.
330
341
331
342
= head2 routine chdir
332
343
You can’t perform that action at this time.
0 commit comments