Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement slurp.
  • Loading branch information
jnthn committed Aug 3, 2011
1 parent a207490 commit de65682
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/IO.pm
Expand Up @@ -92,6 +92,10 @@ class IO {
self.print: nqp::shift($args).gist while $args;
self.print: "\n";
}

method slurp() {
nqp::p6box_s($!PIO.readall());
}

method d() {
self.e && nqp::p6bool(pir::stat__Isi(nqp::unbox_s($!path), pir::const::STAT_ISDIR))
Expand Down Expand Up @@ -163,6 +167,14 @@ multi sub close($fh) {
$fh.close()
}

proto sub slurp(|$) { * }
multi sub slurp($filename) {
my $handle = open($filename, :r);
my $contents = $handle.slurp();
$handle.close();
$contents
}

$PROCESS::IN = open('-');
$PROCESS::OUT = open('-', :w);
$PROCESS::ERR = IO.new;
Expand Down

0 comments on commit de65682

Please sign in to comment.