Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
An initial implementation of $*ARGFILES and lines().
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| my class ArgFiles { | ||
| has $.args; | ||
| has $.filename; | ||
| has $!io; | ||
| has $!ins; | ||
|
|
||
| method eof() { ! $!args } | ||
|
|
||
| method get() { | ||
| unless $!io.defined && $!io.opened { | ||
| $!filename = $!args ?? $!args.shift !! '-'; | ||
| $!io = open($!filename, :r) || | ||
| fail "Unable to open file '$!filename'"; | ||
| } | ||
| my $x = $!io.get; | ||
| while !$x.defined { | ||
| $!io.close; | ||
| $!io = IO; | ||
| fail "End of argfiles reached" unless $!args; | ||
| $x = self.get; | ||
| } | ||
| $!ins++; | ||
| $x; | ||
| } | ||
|
|
||
| method lines($limit = *) { | ||
| my $l = $limit ~~ Whatever ?? $Inf !! $limit; | ||
| gather while !$.eof && $l-- > 0 { | ||
| my $line = $.get; | ||
| if $line.defined { | ||
| take $line; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters