develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33705 - trunk/languages/perl6/src/classes

From:
jonathan
Date:
December 9, 2008 04:30
Subject:
[svn:parrot] r33705 - trunk/languages/perl6/src/classes
Message ID:
20081209123046.2CEBACB9AF@x12.develooper.com
Author: jonathan
Date: Tue Dec  9 04:30:45 2008
New Revision: 33705

Modified:
   trunk/languages/perl6/src/classes/IO.pir

Log:
[rakudo] Implement lines method on IO objects and export it. Patch courtesy of bacek++.

Modified: trunk/languages/perl6/src/classes/IO.pir
==============================================================================
--- trunk/languages/perl6/src/classes/IO.pir	(original)
+++ trunk/languages/perl6/src/classes/IO.pir	Tue Dec  9 04:30:45 2008
@@ -21,8 +21,36 @@
     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 lines
+
+our List multi method lines (IO $handle:) is export;
+
+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 print
 
 Writes the given list of items to the file.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About