Permalink
Browse files

Merging IO module buffering work

  • Loading branch information...
2 parents 06a7305 + 8c570c9 commit 4eb1b6eb08d48bccd596be1272a9c380c7df202b @ajs committed Jun 24, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/core/IO.pm
View
@@ -45,6 +45,7 @@ class IO {
$!path = $path;
$!chomp = $chomp;
$!PIO.encoding($bin ?? 'binary' !! 'utf8');
+ self.buffer_type(:line);
self;
}
@@ -54,6 +55,13 @@ class IO {
Bool::True;
}
+ # XXX - DESTROY is NYI in Rakudo at the time this was written, so
+ # the following has no effect.
+ method DESTROY() {
+ # It might be correct to self.close(), here, but perhaps not...
+ self.flush();
+ }
+
method eof() {
nqp::p6bool($!PIO.eof);
}
@@ -135,6 +143,26 @@ class IO {
Bool::True
}
+ # Underlying Parrot buffer types:
+ # * unbuffered
+ # * line-buffered
+ # * full-buffered
+ # Returns one of those strings
+ method buffer_type(IO:D: Bool :$unbuffered=False,
+ Bool :$line=False,
+ Bool :$full=False) {
+ my $type = $unbuffered ?? 'unbuffered' !! (
+ $line ?? 'line-buffered' !! (
+ $full ?? 'full-buffered' !!
+ die "buffer_type called without a type"));
+ nqp::p6box_s($!PIO.buffer_type(nqp::unbox_s($type)));
+ }
+
+ method flush(IO:D:) {
+ $!PIO.flush();
+ Bool::True;
+ }
+
multi method say(IO:D: |$) {
my Mu $args := pir::perl6_current_args_rpa__P();
nqp::shift($args);

0 comments on commit 4eb1b6e

Please sign in to comment.