Skip to content

Commit

Permalink
Make IO::Special.WHICH return a ValueObjAt
Browse files Browse the repository at this point in the history
And add some additional return types
  • Loading branch information
lizmat committed Dec 28, 2018
1 parent 67cbd99 commit 9df0962
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/core/IO/Special.pm6
Expand Up @@ -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 }
Expand Down

0 comments on commit 9df0962

Please sign in to comment.