Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[S32/IO] spurt now overwrites by default
It fails on existing files only if you pass it the new `:new` option.
  • Loading branch information
Carl Masak committed Jul 6, 2012
1 parent 7ccf428 commit 4137ad6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions S32-setting-library/IO.pod
Expand Up @@ -22,8 +22,8 @@ DRAFT: Synopsis 32: Setting Library - IO

Created: 19 Feb 2009 extracted from S29-functions.pod; added stuff from S16-IO later

Last Modified: 24 June 2012
Version: 14
Last Modified: 6 July 2012
Version: 15

The document is a draft.

Expand Down Expand Up @@ -954,35 +954,42 @@ The routine will C<fail> if the file does not exist, or is a directory.
Str $contents,
Str :$enc = $?ENC,
Bool :append = False,
Bool :new = False,
)
multi method spurt ($handle:
Buf $contents,
Bool :append = False,
Bool :new = False,
)
multi spurt (IO $fh,
Str $contents,
Str :$enc = $?ENC,
Bool :append = False,
Bool :new = False,
)
multi spurt (IO $fh,
Buf $contents,
Bool :append = False,
Bool :new = False,
)
multi spurt (Str $filename,
Str $contents,
Str :$enc = $?ENC,
Bool :append = False,
Bool :new = False,
)
multi spurt (Str $filename,
Buf $contents,
Bool :append = False,
Bool :new = False,
)

Opens the file for writing, dumps the contents, and closes the file.

This routine will C<fail> if the file exists, unless the C<:append> flag is
set, in which case it will instead add the given contents at the end of the
file.
If the C<:new> flag is set and the file already exists before opening, this
routine will C<fail>. With an unset C<:new> flag, the file will instead be
silently overwritten, unless the C<:append> flag is set, in which case the
routine will instead add the given contents at the end of the file.

The routine will also C<fail> with the corresponding exception if there was any
other error in opening, writing, or closing.
Expand Down

0 comments on commit 4137ad6

Please sign in to comment.