-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement $*ARGFILES, and make it the default handle for lines()
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
- Loading branch information
Showing
5 changed files
with
70 additions
and
1 deletion.
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
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,60 @@ | ||
class IO::ArgFiles { | ||
has $!filenames; | ||
has $!filename; | ||
has $!current_file; | ||
has $!ins; | ||
|
||
method new($filenames) { | ||
if $filenames.elems { | ||
self.bless(*, :filenames($filenames)); | ||
} else { | ||
push $filenames, "-"; | ||
self.bless(*, :filenames($filenames)); | ||
} | ||
} | ||
|
||
method eof() { | ||
$.next_file; | ||
$!current_file.eof && $!filenames.elems == 0; | ||
} | ||
|
||
method getc() { | ||
... | ||
} | ||
|
||
method get() { | ||
$.next_file; | ||
$!ins++; | ||
$!current_file.get; | ||
} | ||
|
||
method lines() { | ||
gather while !$.eof { | ||
my $line = $.get; | ||
take $line if defined $line; | ||
} | ||
} | ||
|
||
method filename() { | ||
$!filename; | ||
} | ||
|
||
method ins() { | ||
$!ins; | ||
} | ||
|
||
method next_file() { | ||
if (!defined $!current_file) || ($!current_file.eof) { | ||
$!current_file.close if $!current_file && $!filename ne '-'; | ||
fail if $!filenames.elems == 0; | ||
$!filename = $!filenames.shift; | ||
$!current_file = $!filename eq '-' ?? $*IN !! open($!filename); | ||
} | ||
} | ||
} | ||
|
||
sub ARGFILES_CREATE() { | ||
IO::ArgFiles.new(@*ARGS); | ||
} | ||
|
||
# vim: ft=perl6 |
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