Skip to content

Commit

Permalink
[io grant] Straighten out &lines/&words
Browse files Browse the repository at this point in the history
- Just pass all args via captures; don't do own processing
- Make &words default to $*ARGFILES, just like the rest of the routines
    in this group.
- Add rudimentary IO::ArgFiles.words impl; will be replaced by IO::CatHandle
  • Loading branch information
zoffixznet committed Apr 24, 2017
1 parent 64c3032 commit 34b58d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/core/IO/ArgFiles.pm
Expand Up @@ -147,6 +147,26 @@ my class IO::ArgFiles is IO::Handle {
[~] @chunks;
}

method words(IO::ArgFiles:D: |c) {
$!has-args = ?$!args unless $!has-args.defined;

return $*IN.words(|c) unless $!has-args;

my @chunks;
if $!io.defined && $!io.opened {
@chunks.append: $!io.words(:close, |c);
}

while $!args {
@chunks.append: words $!args.shift, |c;
}

# TODO Should this be a failure?
return Nil unless @chunks;

@chunks.Seq;
}

method nl-in is rw {
Proxy.new(
FETCH => {
Expand Down
12 changes: 2 additions & 10 deletions src/core/io_operators.pm
Expand Up @@ -96,18 +96,10 @@ proto sub open(|) { * }
multi sub open(IO() $path, |c) { IO::Handle.new(:$path).open(|c) }

proto sub lines(|) { * }
multi sub lines($what = $*ARGFILES, $limit = Inf, *%named) {
nqp::istype($limit,Whatever) || $limit == Inf
?? $what.lines(|%named)
!! $what.lines($limit, |%named);
}
multi sub lines($what = $*ARGFILES, |c) { $what.lines(|c) }

proto sub words(|) { * }
multi sub words($what, $limit = Inf, *%named) {
nqp::istype($limit,Whatever) || $limit == Inf
?? $what.words(|%named)
!! $what.words($limit, |%named);
}
multi sub words($what = $*ARGFILES, |c) { $what.words(|c) }

proto sub get (|) { * }
multi sub get (IO::Handle $fh = $*ARGFILES) { $fh.get }
Expand Down

0 comments on commit 34b58d1

Please sign in to comment.