New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent semantics for slurp and lines subs #947
Comments
From @ronaldxsPatch provides semantics for "slurp $filehandle" consistent with "slurp Note that according to Dr. Michaud this patch requires a spec change This is my first attempt at submitting a patch using git branching and |
From @ronaldxs0001-Provide-semantics-for-slurp-filehandle-consistent-w.patchFrom 0c032d4a8b9f14effe0047fb3dc6cadb3cbcbb0d Mon Sep 17 00:00:00 2001
From: U-ron-PC\ron <ron@ron-PC.(none)>
Date: Fri, 24 Apr 2009 10:39:20 -0400
Subject: [PATCH] Provide semantics for slurp $filehandle consistent with slurp filename and
allow slurp by itself to slurp stdin. Also provide consistency with
existing lines implementation.
---
src/builtins/io.pir | 10 ----------
src/setting/Any-str.pm | 8 ++++++++
src/setting/IO.pm | 23 +++++++++++++++++++++++
3 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/src/builtins/io.pir b/src/builtins/io.pir
index 1b92857..0c638f5 100644
--- a/src/builtins/io.pir
+++ b/src/builtins/io.pir
@@ -98,16 +98,6 @@ opened_ok:
obj.'close'()
.end
-.sub 'slurp'
- .param string filename
- .local string contents
-
- $P0 = 'open'(filename, 'r')
- contents = $P0.'slurp'()
- 'close'($P0)
- .return(contents)
-.end
-
=item unlink LIST
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index b427332..617dcab 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -173,6 +173,14 @@ multi sub lines(Str $filename,
return lines($filehandle, :$bin, :$enc, :$nl, :$chomp);
}
+multi sub slurp(Str $filename,
+ :$bin = False,
+ :$enc = 'Unicode') {
+
+ my $filehandle = open($filename, :r);
+ return slurp($filehandle, :$bin, :$enc);
+}
+
sub unpack($template, $target) {
$template.trans(/\s+/ => '') ~~ / ((<[Ax]>)(\d+))* /
or return (); # unknown syntax
diff --git a/src/setting/IO.pm b/src/setting/IO.pm
index 0948b6c..6cac0e7 100644
--- a/src/setting/IO.pm
+++ b/src/setting/IO.pm
@@ -62,4 +62,27 @@ multi sub lines(IO $filehandle,
return $filehandle.lines();
}
+multi sub lines(:$bin = False,
+ :$enc = 'Unicode',
+ :$nl = "\n",
+ :$chomp = True) {
+
+ return lines($*IN, :$bin, :$enc, :$nl, :$chomp);
+}
+
+multi sub slurp(IO $filehandle,
+ :$bin = False,
+ :$enc = 'Unicode') {
+
+ fail 'Binary mode not supported yet' if $bin;
+ fail 'Encodings not supported yet' if $enc ne 'Unicode';
+
+ return $filehandle.slurp();
+}
+
+multi sub slurp(:$bin = False,
+ :$enc = 'Unicode') {
+ return slurp($*IN, :$bin, :$enc);
+}
+
# vim: ft=perl6
--
1.6.1.2
|
From @ronaldxsS16-unfiled-slurp.patchIndex: t/spec/S16-unfiled/slurp.t
===================================================================
--- t/spec/S16-unfiled/slurp.t (revision 26412)
+++ t/spec/S16-unfiled/slurp.t (working copy)
@@ -2,7 +2,7 @@
use Test;
-plan 4;
+plan 5;
# L<E07/"And every one shall share..." /returns them as a single string/>
# L<S16/"Unfiled"/"=item IO.slurp">
@@ -30,4 +30,16 @@
my @slurped_lines = lines(open($self));
ok +@slurped_lines > 30, "more than 30 lines in this file ?";
+{
+ my $fh = open $self, :r;
+ my $contents = slurp $fh;
+
+ # lame use of filehandle but might be able to seek/rewind some day ...
+ # also allows 'slurp $*IN' huffmanized to just slurp
+ ok $fh.ins == 0 && $contents ~~ m/'use v6'.*'StringThatsNowhereElse'/,
+ "slurp worked through file handle";
+
+ $fh.close;
+}
+
# vim: ft=perl6
|
From @cokeOn Fri Apr 24 15:02:46 2009, ronaldxs wrote:
Thanks for the patch ... unfortunately, this patch no longer cleanly applies. Can you rebase Regards. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @ronaldxs
I don't know how long this has been true, but at this point $*IO.slurp Ron |
From @masakOn Sun Sep 11 10:14:08 2011, ronaldxs wrote:
Thanks again for the patches. Sorry about not acting fast enough for them Rejecting ticket. |
@masak - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#65120 (status was 'rejected')
Searchable as RT65120$
The text was updated successfully, but these errors were encountered: