Navigation Menu

Skip to content

Commit

Permalink
Implement :excl and :all for methods, attributes and parents. Make :e…
Browse files Browse the repository at this point in the history
…xcl the default.
  • Loading branch information
jnthn committed Jan 9, 2012
1 parent b1d3c7c commit 1f302f8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/Perl6/Metamodel/AttributeContainer.pm
Expand Up @@ -47,16 +47,15 @@ role Perl6::Metamodel::AttributeContainer {
}

# Introspect attributes.
method attributes($obj, :$local) {
method attributes($obj, :$local, :$excl, :$all) {
my @attrs;

if $local {
for @!attributes {
@attrs.push($_);
}

for @!attributes {
@attrs.push($_);
}
else {
for self.mro($obj) {

unless $local {
for self.parents($obj, :excl($excl), :all($all)) {
for $_.HOW.attributes($_, :local(1)) {
@attrs.push($_);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Perl6/Metamodel/MethodContainer.pm
Expand Up @@ -33,7 +33,7 @@ role Perl6::Metamodel::MethodContainer {
}

# Gets the method hierarchy.
method methods($obj, :$local) {
method methods($obj, :$local, :$excl, :$all) {
# Always need local methods on the list.
my @meths;
for @!method_order {
Expand All @@ -42,7 +42,7 @@ role Perl6::Metamodel::MethodContainer {

# If local flag was not passed, include those from parents.
unless $local {
for self.parents($obj) {
for self.parents($obj, :all($all), :excl($excl)) {
for $_.HOW.method_table($_) {
@meths.push($_.value);
}
Expand Down
16 changes: 14 additions & 2 deletions src/Perl6/Metamodel/MultipleInheritance.pm
@@ -1,6 +1,12 @@
role Perl6::Metamodel::MultipleInheritance {
# Array of parents.
has @!parents;

# Classes to exclude from the parents list in introspection by default.
my @excluded;
method exclude_parent($parent) {
@excluded.push($parent);
}

# Adds a parent.
method add_parent($obj, $parent) {
Expand All @@ -21,7 +27,7 @@ role Perl6::Metamodel::MultipleInheritance {
}

# Introspects the parents.
method parents($obj, :$local, :$tree) {
method parents($obj, :$local, :$tree, :$excl, :$all) {
if $local {
@!parents
}
Expand All @@ -40,7 +46,13 @@ role Perl6::Metamodel::MultipleInheritance {
my @parents;
my $i := 1;
while $i < +@mro {
@parents.push(@mro[$i]);
my $exclude := 0;
unless $all {
for @excluded {
$exclude := 1 if @mro[$i] =:= $_;
}
}
@parents.push(@mro[$i]) unless $exclude;
$i := $i + 1;
}
@parents
Expand Down
1 change: 1 addition & 0 deletions src/core/Any.pm
Expand Up @@ -161,6 +161,7 @@ my class Any {

method reduce(&with) { self.list.reduce(&with) }
}
Metamodel::ClassHOW.exclude_parent(Any);

proto infix:<===>($?, $?) { * }
multi infix:<===>($a?) { Bool::True }
Expand Down
1 change: 1 addition & 0 deletions src/core/Cool.pm
Expand Up @@ -181,6 +181,7 @@ my class Cool {
method Num() { self.Numeric.Num }
method Rat() { self.Numeric.Rat }
}
Metamodel::ClassHOW.exclude_parent(Cool);

sub chop(Cool $s) { $s.chop }
sub chomp(Cool $s) { $s.chomp }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Mu.pm
Expand Up @@ -432,4 +432,4 @@ sub DUMP(|$) {
!! $topic.DUMP()
}
};

Metamodel::ClassHOW.exclude_parent(Mu);

0 comments on commit 1f302f8

Please sign in to comment.