Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add IO.open to allow attaching an existing IO object to a file. Also …
…now understands "-" as a filename meaning "standard input".
  • Loading branch information
pmichaud committed Jun 30, 2010
1 parent 806efc8 commit 8e7bf30
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/IO.pm
Expand Up @@ -35,6 +35,19 @@ class IO is Cool {
}
}

method open($filename, :$r, :$w, :$a) {
if $!PIO { $!PIO.close; $!PIO = Nil; }
my $mode = $w ?? 'w' !! ($a ?? 'wa' !! 'r');
$!PIO = $filename eq '-'
?? pir::getstdin__P()
!! pir::open__PSS($filename, $mode);
unless pir::istrue__IP($!PIO) {
fail("Unable to open file '$filename'");
}
$!PIO.encoding('utf8');
self;
}

multi method print(*@items) {
try {
for @items -> $item {
Expand Down

0 comments on commit 8e7bf30

Please sign in to comment.