Skip to content

Commit d5abceb

Browse files
committed
[io grant] Write docs for all spurt routines
- Reflect changes in &spurt - Document all the args in IO::Path.spurt - Document newly-added IO::Handle.spurt Impl: rakudo/rakudo@099512b20c Tests: Raku/roast@79ff022881
1 parent b81148c commit d5abceb

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

doc/Type/IO.pod6

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,13 @@ exist, or is a directory.
353353
354354
=head2 sub spurt
355355
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.
374363
375364
=head3 Options
376365

doc/Type/IO/Handle.pod6

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ on strings.
8888
my $fh = open 'path/to/file', :r;
8989
$fn.split(' ', close => True); # Returns file content split by a space and closes file;
9090
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+
91105
=head2 method comb
92106
93107
multi method comb(IO::Handle:D: :$close = False)

doc/Type/IO/Path.pod6

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,23 @@ Returns C<Bool::True> if the invocant is a path and the size is 0.
321321
322322
Return the file content for this path, like L<slurp|/routine/slurp>.
323323
324-
=head2 routine spurt
324+
=head2 method spurt
325325
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)
328327
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.
330341
331342
=head2 routine chdir
332343

0 commit comments

Comments
 (0)