Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added slurp(IO::Handle... support
  • Loading branch information
dagurval committed May 21, 2013
1 parent 267c54c commit 1a9b0da
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/core/IO.pm
Expand Up @@ -445,30 +445,46 @@ multi sub slurp(IO::Handle $io = $*ARGFILES) {
}

proto sub spurt(|) { * }
multi sub spurt(Cool $filename,
multi sub spurt(IO::Handle $fh,
Cool $contents,
:encoding(:$enc) = 'utf8',
:$createonly,
:$append) {
fail("File '$filename' already exists, but :createonly was give to spurt")
if $createonly && $filename.IO.e;
fail("File '" ~ $fh.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && $fh.e;
my $mode = $append ?? :a !! :w;
my $fh = open($filename.Str, :$enc, |$mode);
$fh.open(:$enc, |$mode);
$fh.print($contents);
$fh.close;
}
multi sub spurt(Cool $filename,
multi sub spurt(IO::Handle $fh,
Buf $contents,
:$createonly,
:$append) {
fail("File '$filename' already exists, but :createonly was give to spurt")
if $createonly && $filename.IO.e;
fail("File '" ~ $fh.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && $fh.e;
my $mode = $append ?? :a !! :w;
my $fh = open($filename.Str, :bin, |$mode);
$fh.open(:bin, |$mode);
$fh.write($contents);
$fh.close;
}

multi sub spurt(Cool $filename,
Cool $contents,
:encoding(:$enc) = 'utf8',
:$createonly,
:$append) {
spurt($filename.IO, $contents, :$enc, :$createonly, :$append);
}

multi sub spurt(Cool $filename,
Buf $contents,
:$createonly,
:$append) {
spurt($filename.IO, $contents, :$createonly, :$append);
}


proto sub cwd(|) { * }
multi sub cwd() {
return nqp::p6box_s(
Expand Down

0 comments on commit 1a9b0da

Please sign in to comment.