Skip to content

Commit

Permalink
Implement rw handling for types in AttributeContainer role; also fact…
Browse files Browse the repository at this point in the history
…or attribute composition into that role to take a little more bulk out of ClassHOW.
  • Loading branch information
jnthn committed Jul 28, 2011
1 parent 9246ce6 commit 0ca6dad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/Perl6/Metamodel/AttributeContainer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ role Perl6::Metamodel::AttributeContainer {
# Attributes list.
has @!attributes;
has %!attribute_lookup;

# Do we default them to rw?
has $!attr_rw_by_default;

# Adds an attribute.
method add_attribute($obj, $meta_attr) {
Expand All @@ -14,6 +17,25 @@ role Perl6::Metamodel::AttributeContainer {
%!attribute_lookup{$name} := $meta_attr;
}

# Composes all attributes.
method compose_attributes($obj) {
for @!attributes {
if $!attr_rw_by_default { $_.default_to_rw() }
$_.compose($obj);
}
}

# Makes setting the type represented by the meta-object rw mean that its
# attributes are rw by default.
method set_rw($obj) {
$!attr_rw_by_default := 1;
}

# Is this type's attributes rw by default?
method rw($obj) {
$!attr_rw_by_default
}

# Gets the attribute meta-object for an attribute if it exists.
# This is called by the parser so it should only return attributes
# that are visible inside the current package.
Expand Down
4 changes: 1 addition & 3 deletions src/Perl6/Metamodel/ClassHOW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class Perl6::Metamodel::ClassHOW
self.incorporate_multi_candidates($obj);

# Compose attributes.
for self.attributes($obj, :local) {
$_.compose($obj);
}
self.compose_attributes($obj);

# Publish type and method caches.
self.publish_type_cache($obj);
Expand Down

0 comments on commit 0ca6dad

Please sign in to comment.