# New Ticket Created by Vasily Chekalkin
# Please include the string: [perl #61214]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61214 >
Hello.
There is patch for implemtation of IO.lines and lines(Str)
--
Bacek
commit 9ed96ea13fbe0a01c9961750a45fc84be29bab2a
Author: Vasily Chekalkin <[EMAIL PROTECTED]>
Date: Tue Dec 9 21:54:18 2008 +1100
Implement IO.lines method
diff --git a/languages/perl6/src/builtins/io.pir b/languages/perl6/src/builtins/io.pir
index 5b661f0..1560352 100644
--- a/languages/perl6/src/builtins/io.pir
+++ b/languages/perl6/src/builtins/io.pir
@@ -100,6 +100,16 @@ opened_ok:
.return(contents)
.end
+.sub 'lines' :multi('Str')
+ .param string filename
+ .local pmc contents
+
+ $P0 = 'open'(filename, 'r')
+ contents = $P0.'lines'()
+ 'close'($P0)
+
+ .return(contents)
+.end
=item unlink LIST
diff --git a/languages/perl6/src/classes/IO.pir b/languages/perl6/src/classes/IO.pir
index 9a906f1..6dd5f28 100644
--- a/languages/perl6/src/classes/IO.pir
+++ b/languages/perl6/src/classes/IO.pir
@@ -21,6 +21,9 @@ This file implements the IO file handle class.
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
p6meta.'new_class'('IO', 'parent'=>'Any', 'attr'=>'$!PIO')
p6meta.'new_class'('IOIterator', 'parent'=>'Perl6Object', 'attr'=>'$!IO')
+
+ $P0 = get_hll_namespace ['IO']
+ '!EXPORT'('lines', 'from'=>$P0)
.end
=item print
@@ -105,6 +108,29 @@ Slurp a file into a string.
.return($S0)
.end
+=item lines
+
+ our List multi method lines (IO $handle:) is export;
+ our List multi lines (Str $filename);
+
+Returns all the lines of a file as a (lazy) List regardless of context. See also slurp.
+
+=cut
+
+.sub 'lines' :method :multi('IO')
+ .local pmc PIO, res
+ PIO = getattribute self, "$!PIO"
+ res = new 'List'
+
+ loop:
+ $S0 = PIO.'readline'()
+ unless $S0 goto done
+ res.'push'($S0)
+ goto loop
+
+ done:
+ .return (res)
+.end
=item eof