Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement $*ARGFILES, and make it the default handle for lines()

Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information...
commit 68852e4e7b0fa5c7845540ad261c14c449d9667b 1 parent d18b5e7
Tyler Curtis authored moritz committed
View
5 CREDITS
@@ -329,6 +329,11 @@ U: tene
D: Minor Rakudo patches
E: tene@allalone.org
+N: Tyler Curtis
+U: tcurtis
+D: $*ARGFILES
+E: tyler.l.curtis@gmail.com
+
N: Ujwal Reddy Malipeddi
E: ujwalic@gmail.com
D: Rakudo patch
View
1  build/Makefile.in
@@ -208,6 +208,7 @@ CORE_SOURCES = \
src/core/Hash.pm \
src/core/Enum.pm \
src/core/IO.pm \
+ src/core/IO/ArgFiles.pm \
src/core/IO/Socket.pm \
src/core/IO/Socket/INET.pm \
src/core/Parameter.pm \
View
2  src/core/IO.pm
@@ -68,7 +68,7 @@ class IO is Cool {
}
}
-multi sub lines(IO $filehandle,
+multi sub lines(IO $filehandle = $*ARGFILES,
:$bin = False,
:$enc = 'Unicode',
:$nl = "\n",
View
60 src/core/IO/ArgFiles.pm
@@ -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
View
3  src/glue/run.pir
@@ -87,6 +87,9 @@ of the compilation unit.
set_hll_global '@ARGS', $P2
setprop $P2, "rw", true
+ $P3 = 'ARGFILES_CREATE'()
+ set_hll_global '$ARGFILES', $P3
+
## set up %*VM
load_bytecode 'config.pbc'
.local pmc vm, interp, config
Please sign in to comment.
Something went wrong with that request. Please try again.