Skip to content

Commit

Permalink
Don't return standard .perl for classes with custom .new
Browse files Browse the repository at this point in the history
- also make code more idiomatic Perl 6
- return "Class.new(...)" for now with custom new
- step 1 in fixing R#2448
  • Loading branch information
lizmat committed Oct 31, 2018
1 parent 052067f commit adc9683
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/core/Mu.pm6
Expand Up @@ -634,20 +634,21 @@ Perhaps it can be found at https://docs.perl6.org/type/$name"
proto method perl(|) {*}
multi method perl(Mu:U:) { self.^name }
multi method perl(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).perl,
self.perlseen: self.^name, {
my @attrs;
for self.^attributes().flat.grep: { .has_accessor } -> $attr {
my $name := substr($attr.Str,2);
@attrs.push: $name ~ ' => ' ~ $attr.get_value(self).perl
}
self.^name ~ '.new' ~ ('(' ~ @attrs.join(', ') ~ ')' if @attrs)
}))
nqp::eqaddr(self,IterationEnd)
?? "IterationEnd"
!! nqp::iscont(self) # Proxy object would have a conted `self`
?? nqp::decont(self).perl
!! self.perlseen: self.^name,
nqp::eqaddr(self.^find_method("new"),Mu.^find_method("new"))
?? {
my @attrs = self.^attributes
.grep( { .has_accessor } )
.map: { "$_.Str.substr(2) => $_.get_value(self).perl()" }
@attrs
?? self.^name ~ ".new(@attrs.join(', '))"
!! self.^name ~ ".new"
}
!! { self.^name ~ ".new(...)" }
}

proto method DUMP(|) {*}
Expand Down

0 comments on commit adc9683

Please sign in to comment.