Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[IO] Add :new flag to &spurt
  • Loading branch information
moritz committed Jul 6, 2012
1 parent b1aa031 commit 501e8a2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/IO.pm
Expand Up @@ -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);
Expand Down

0 comments on commit 501e8a2

Please sign in to comment.