Skip to content
Browse files

[IO] Add :new flag to &spurt

  • Loading branch information...
1 parent b1aa031 commit 501e8a26ffd0cba2a087ddf0c51f9cd1f99d35ea @moritz moritz committed Jul 6, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/core/IO.pm
View
6 src/core/IO.pm
@@ -368,15 +368,21 @@ proto sub spurt(|$) { * }
multi sub spurt(Cool $filename,
Cool $contents,
:encoding(:$enc) = 'utf8',
+ :$new,
:$append) {
+ fail("File '$filename' already exists, but :new was give to spurt")
+ if $new && $filename.IO.e;
my $mode = $append ?? :a !! :w;
my $fh = open($filename.Str, :$enc, |$mode);
$fh.print($contents);
$fh.close;
}
multi sub spurt(Cool $filename,
Buf $contents,
+ :$new,
:$append) {
+ fail("File '$filename' already exists, but :new was give to spurt")
+ if $new && $filename.IO.e;
my $mode = $append ?? :a !! :w;
my $fh = open($filename.Str, :bin, |$mode);
$fh.write($contents);

0 comments on commit 501e8a2

Please sign in to comment.
Something went wrong with that request. Please try again.