Navigation Menu

Skip to content

Commit

Permalink
Add a version of __dump() to NQPMu so that NQP objects can
Browse files Browse the repository at this point in the history
be used by Parrot's Data::Dumper.
  • Loading branch information
pmichaud committed Jul 4, 2011
1 parent 358eeb0 commit 8557631
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/NQPMu.pm
Expand Up @@ -46,4 +46,28 @@ my class NQPMu {
method isa($type) {
self.HOW.isa(self, $type)
}

method __dump($dumper, $label) {
my $subindent;
my $indent;
Q:PIR {
$P0 = find_lex '$dumper'
($P0, $P1) = $P0.'newIndent'()
store_lex '$subindent', $P0
store_lex '$indent', $P1
};
print('{');
for self.HOW.parents(self) -> $type {
my @attr := nqp::list();
for $type.HOW.attributes($type, :local) {
nqp::push(@attr, $_.name);
}
@attr.sort();
for @attr -> $name {
print("\n", $subindent, $type.HOW.name($type), "::", $name, " => ");
$dumper.'dump'($label, nqp::getattr(self, $type, $name));
}
}
print("\n", $indent, '}');
}
}

0 comments on commit 8557631

Please sign in to comment.