Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved spurt into methods in IO::Handle
  • Loading branch information
dagurval committed May 22, 2013
1 parent e4cb829 commit 5fa040f
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/core/IO.pm
Expand Up @@ -208,6 +208,32 @@ my class IO::Handle does IO::FileTestable {
}


proto method spurt(|) { * }
multi method spurt(Cool $contents,
:encoding(:$enc) = 'utf8',
:$createonly, :$append) {

fail("File '" ~ self.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && self.e;

my $mode = $append ?? :a !! :w;
self.open(:$enc, |$mode);
self.print($contents);
self.close;
}

multi method spurt(Buf $contents,
:$createonly,
:$append) {
fail("File '" ~ self.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && self.e;

my $mode = $append ?? :a !! :w;
self.open(:bin, |$mode);
self.write($contents);
self.close;
}

# not spec'd
method copy($dest) {
try {
Expand Down Expand Up @@ -450,41 +476,30 @@ multi sub spurt(IO::Handle $fh,
:encoding(:$enc) = 'utf8',
:$createonly,
:$append) {
fail("File '" ~ $fh.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && $fh.e;
my $mode = $append ?? :a !! :w;
$fh.open(:$enc, |$mode);
$fh.print($contents);
$fh.close;
$fh.spurt($contents, :$enc, :$createonly, :$append);
}
multi sub spurt(IO::Handle $fh,
Buf $contents,
:$createonly,
:$append) {
fail("File '" ~ $fh.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && $fh.e;
my $mode = $append ?? :a !! :w;
$fh.open(:bin, |$mode);
$fh.write($contents);
$fh.close;
$fh.spurt($contents, :$createonly, :$append);
}

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

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


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

0 comments on commit 5fa040f

Please sign in to comment.