Skip to content
Permalink
Browse files

Make IO::Special.WHICH return a ValueObjAt

And add some additional return types
  • Loading branch information...
lizmat committed Dec 28, 2018
1 parent 67cbd99 commit 9df09621264d4580bbc05ff77bde5b0f01f1dc47
Showing with 21 additions and 5 deletions.
  1. +21 −5 src/core/IO/Special.pm6
@@ -3,22 +3,38 @@ my class Instant { ... }
class IO::Special does IO {
has Str $.what;

method new(\what) {
method new(Str:D \what --> IO::Special:D) {
nqp::p6bindattrinvres(nqp::create(self),self,'$!what',what)
}
multi method WHICH(IO::Special:D:) { "IO::Special$!what" }
multi method WHICH(IO::Special:D: --> ValueObjAt) {
nqp::box_s(
nqp::concat(
nqp::if(
nqp::eqaddr(self.WHAT,IO::Special),
'IO::Special|',
nqp::concat(nqp::unbox_s(self.^name), '|')
),
$!what
),
ValueObjAt
)
}
multi method Str (IO::Special:D:) { $!what }
multi method perl (IO::Special:D:) { "{self.^name}.new({$!what.perl})" }

method IO(IO::Special:D:) { self }
method IO(IO::Special:D: --> IO::Special:D) { self }

method e(IO::Special:D: --> True) { }
method d(IO::Special:D: --> False) { }
method f(IO::Special:D: --> False) { }
method s(IO::Special:D:--> 0) { }
method l(IO::Special:D: --> False) { }
method r(IO::Special:D:) { $!what eq '<STDIN>' }
method w(IO::Special:D:) { $!what eq '<STDOUT>' or $!what eq '<STDERR>' }
method r(IO::Special:D: --> Bool:D) {
$!what eq '<STDIN>'
}
method w(IO::Special:D: --> Bool:D) {
$!what eq '<STDOUT>' or $!what eq '<STDERR>'
}
method x(IO::Special:D: --> False) { }
method modified(IO::Special:D: --> Instant) { Instant }
method accessed(IO::Special:D: --> Instant) { Instant }

0 comments on commit 9df0962

Please sign in to comment.
You can’t perform that action at this time.