Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created November 1, 2015 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizmat/d01f35e64b648578e3a4 to your computer and use it in GitHub Desktop.
Save lizmat/d01f35e64b648578e3a4 to your computer and use it in GitHub Desktop.
Adding .^attribute for hash based introspection
diff --git a/src/Perl6/Metamodel/AttributeContainer.nqp b/src/Perl6/Metamodel/AttributeContainer.nqp
index a5fafdd..bc0a525 100644
--- a/src/Perl6/Metamodel/AttributeContainer.nqp
+++ b/src/Perl6/Metamodel/AttributeContainer.nqp
@@ -76,4 +76,22 @@ role Perl6::Metamodel::AttributeContainer {
@attrs
}
+
+ method attribute($obj, :$local, :$excl, :$all) {
+ my %attrs;
+
+ for @!attributes {
+ %attrs{$_.name} := $_;
+ }
+
+ unless $local {
+ for self.parents($obj, :excl($excl), :all($all)) {
+ for $_.HOW.attributes($_, :local(1)) {
+ %attrs{$_.name} := $_;
+ }
+ }
+ }
+
+ %attrs
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment