Permalink
Browse files

[IO] implement sub form of spurt

  • Loading branch information...
moritz committed Jul 6, 2012
1 parent 737fb0f commit b1aa031fa40813eceba9c1fe5bcc8c496dd868e5
Showing with 19 additions and 0 deletions.
  1. +19 −0 src/core/IO.pm
View
@@ -364,6 +364,25 @@ multi sub slurp(IO $io = $*ARGFILES) {
$io.slurp;
}
+proto sub spurt(|$) { * }
+multi sub spurt(Cool $filename,
+ Cool $contents,
+ :encoding(:$enc) = 'utf8',
+ :$append) {
+ my $mode = $append ?? :a !! :w;
+ my $fh = open($filename.Str, :$enc, |$mode);
+ $fh.print($contents);
+ $fh.close;
+}
+multi sub spurt(Cool $filename,
+ Buf $contents,
+ :$append) {
+ my $mode = $append ?? :a !! :w;
+ my $fh = open($filename.Str, :bin, |$mode);
+ $fh.write($contents);
+ $fh.close;
+}
+
my class X::IO::Cwd { ... }
proto sub cwd(|$) { * }
multi sub cwd() {

0 comments on commit b1aa031

Please sign in to comment.