Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved spurt into methods in IO::Handle

  • Loading branch information...
commit 5fa040fb7ba60e4972e2eda66cbfe6a816b5e7e7 1 parent e4cb829
@dagurval dagurval authored
Showing with 30 additions and 15 deletions.
  1. +30 −15 src/core/IO.pm
View
45 src/core/IO.pm
@@ -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 {
@@ -450,23 +476,13 @@ 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,
@@ -474,17 +490,16 @@ multi sub spurt(Cool $filename,
: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(
Please sign in to comment.
Something went wrong with that request. Please try again.