Permalink
Browse files

[S32/IO] spurt now overwrites by default

It fails on existing files only if you pass it the new `:new` option.
  • Loading branch information...
1 parent 7ccf428 commit 4137ad6cf75aaefedcb2c0bb8c0674ef2e22472c @masak masak committed Jul 6, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 S32-setting-library/IO.pod
View
@@ -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.
@@ -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.

0 comments on commit 4137ad6

Please sign in to comment.