Skip to content

Commit

Permalink
Normalizing IO::Handle.say/put/print/note, part 4
Browse files Browse the repository at this point in the history
Basically rince / repeat for .note, like in 88d9822, except that
no changes were needed for IO::Handle, as note is just say, but
writing to $*ERR instead of $*OUT.
  • Loading branch information
lizmat committed May 10, 2020
1 parent 438c1d2 commit 483cac3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/core.c/Mu.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ Perhaps it can be found at https://docs.raku.org/type/$name"

proto method say(|) {*}
proto method put(|) {*}
proto method note(|) {*}

# Handle the typical "foo.say"
multi method say() {
Expand Down Expand Up @@ -729,8 +730,22 @@ Perhaps it can be found at https://docs.raku.org/type/$name"
self.print: nqp::join("",$parts)
}

# Handle the typical "foo.note"
multi method note() {

# no own print method, so use $*ERR.print
if nqp::eqaddr(self.^find_method("print").package,Mu) {
$_ := $*ERR;
.print(nqp::concat(self.gist,.nl-out))
}

# has its own .print, let it handle the empty case
else {
self.print(self.nl-out)
}
}

method print() { print(self) }
method note() { note(self) }

method gistseen(Mu:D \SELF: $id, $gist, *%named) {
if nqp::not_i(nqp::isnull(nqp::getlexdyn('$*gistseen'))) {
Expand Down
22 changes: 13 additions & 9 deletions src/core.c/io_operators.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ multi sub put(\x) {
$_ := $*OUT;
.print: nqp::concat(x.Str,.nl-out)
}
multi sub put(**@args is raw) {
multi sub put(|) {
my $parts := Rakudo::Internals.StrList2list_s(nqp::p6argvmarray);
$_ := $*OUT;
nqp::push_s($parts,.nl-out);
Expand All @@ -47,14 +47,18 @@ multi sub put(**@args is raw) {

proto sub note(|) {*}
multi sub note() {
my $err := $*ERR;
$err.print(nqp::concat("Noted",$err.nl-out));
}
multi sub note(**@args is raw) {
my $err := $*ERR;
my str $str;
$str = nqp::concat($str,nqp::unbox_s(.gist)) for @args;
$err.print(nqp::concat($str,$err.nl-out));
$_ := $*ERR;
.print: nqp::concat("Noted",.nl-out)
}
multi sub note(\x) {
$_ := $*ERR;
.print: nqp::concat(x.gist,.nl-out)
}
multi sub note(|) {
my $parts := Rakudo::Internals.GistList2list_s(nqp::p6argvmarray);
$_ := $*ERR;
nqp::push_s($parts,.nl-out);
.print: nqp::join("",$parts)
}

proto sub gist(|) {*}
Expand Down

0 comments on commit 483cac3

Please sign in to comment.