Skip to content

Commit

Permalink
Make sure that .raku will call .perl on a class that has that
Browse files Browse the repository at this point in the history
Apparently I thought I had implemented that already, but obviously
I hadn't.  This means that:

    class A { method perl() { say "perl" } }
    A.raku;      # perl
    A.new.raku;  # perl

Also took the opportunity to rewrite Mu.raku using ternaries.
  • Loading branch information
lizmat committed Jan 15, 2020
1 parent 0f0947b commit b1e986c
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/core.c/Mu.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -636,29 +636,31 @@ Perhaps it can be found at https://docs.raku.org/type/$name"
}

proto method raku(|) {*}
multi method raku(Mu:U:) { self.^name }
multi method raku(Mu:U:) {
nqp::eqaddr(self.^find_method("perl").package,Mu)
?? self.^name
!! self.perl
}
multi method raku(Mu:D:) {
nqp::if(
nqp::eqaddr(self,IterationEnd),
"IterationEnd",
nqp::if(
nqp::iscont(self), # a Proxy object would have a conted `self`
nqp::decont(self).raku,
self.rakuseen: self.^name, {
if self.^attributes.map( {
nqp::concat(
nqp::substr(.Str,2),
nqp::concat(' => ',.get_value(self).raku)
) if .is_built;
} ).join(', ') -> $attributes {
self.^name ~ '.new(' ~ $attributes ~ ')'
}
else {
self.^name ~ '.new'
}
}
)
)
nqp::eqaddr(self,IterationEnd)
?? "IterationEnd"
!! nqp::iscont(self) # a Proxy object would have a conted `self`
?? nqp::decont(self).raku
!! nqp::eqaddr(self.^find_method("perl").package,Mu)
?? self.rakuseen: self.^name, {
if self.^attributes.map( {
nqp::concat(
nqp::substr(.Str,2),
nqp::concat(' => ',.get_value(self).raku)
) if .is_built;
} ).join(', ') -> $attributes {
self.^name ~ '.new(' ~ $attributes ~ ')'
}
else {
self.^name ~ '.new'
}
}
!! self.perl # class has dedicated old-style .perl
}

proto method DUMP(|) {*}
Expand Down

0 comments on commit b1e986c

Please sign in to comment.