Permalink
Browse files

Improve .perl by making it a multimethod; Mu.perl now produces "Mu" i…

…nstead of "Mu()".
  • Loading branch information...
1 parent 8424798 commit 342f7a53e149273131f27322cd082c39ae5ed388 @pmichaud pmichaud committed Jun 17, 2011
Showing with 11 additions and 5 deletions.
  1. +1 −1 src/core/Complex.pm
  2. +3 −1 src/core/Mu.pm
  3. +2 −2 src/core/Parcel.pm
  4. +1 −1 src/core/Rat.pm
  5. +4 −0 src/core/Str.pm
View
@@ -41,7 +41,7 @@ my class Complex is Numeric {
$!re.Str ~ $op ~ $!im.abs ~ 'i';
}
- method perl() {
+ method perl(Complex:D:) {
"Complex.new($.re, $.im)";
}
method conjugate() {
View
@@ -46,7 +46,9 @@ my class Mu {
method say() { say(self) }
- method perl() { self.Str }
+ proto method perl(|$) { * }
+ multi method perl(Mu:D:) { self.Str }
+ multi method perl(Mu:U:) { self.HOW.name(self) }
proto method DUMP(|$) { * }
multi method DUMP(Mu:D:) { self.perl }
View
@@ -13,12 +13,12 @@ my class Parcel is Iterable {
method iterator() { self }
method reify($n?) { self }
- method perl() {
+ multi method perl(Parcel:D:) {
my Mu $rpa := pir::clone($!storage);
my $perl = '(';
$perl = $perl ~ pir::shift__PP($rpa).perl if $rpa;
$perl = $perl ~ ', ' ~ pir::shift__PP($rpa).perl while $rpa;
- $perl = $perl ~ ')';
+ $perl ~ ')';
}
method DUMP() {
View
@@ -30,7 +30,7 @@ my class Rat is Real {
multi method Str(Rat:D:) {
self.Num.Str
}
- method perl() {
+ multi method perl(Rat:D:) {
$!numerator ~ '/' ~ $!denominator
}
method succ {
View
@@ -14,4 +14,8 @@ my class Str {
method Numeric() { self.Num }
multi method ACCEPTS(Str:D: $other) { $other eq self }
+
+ # XXX: need to translate escapes
+ multi method perl(Str:D:) { "'" ~ self ~ "'" }
+
}

0 comments on commit 342f7a5

Please sign in to comment.