Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Catch invalid inheritance/composition operations, and fill out suppor…
…t for types that know how to produce inheritable/composable types.
  • Loading branch information
jnthn committed Sep 9, 2011
1 parent 9a0650a commit 8c9dd1a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/core/traits.pm
Expand Up @@ -7,7 +7,16 @@ my role Callable { ... }

proto trait_mod:<is>(|$) { * }
multi trait_mod:<is>(Mu:U $child, Mu:U $parent) {
$child.HOW.add_parent($child, $parent);
if $parent.HOW.archetypes.inheritable() {
$child.HOW.add_parent($child, $parent);
}
elsif $parent.HOW.archetypes.inheritalizable() {
$child.HOW.add_parent($child, $parent.HOW.inheritalize($parent))
}
else {
die $child.HOW.name($child) ~ " cannot inherit from " ~
$parent.HOW.name($parent) ~ " because it is not inheritable"
}
}
multi trait_mod:<is>(Mu:U $type, :$rw!) {
$type.HOW.set_rw($type);
Expand Down Expand Up @@ -76,7 +85,16 @@ multi trait_mod:<is>(Mu:U $docee, $doc, :$docs!) {

proto trait_mod:<does>(|$) { * }
multi trait_mod:<does>(Mu:U $doee, Mu:U $role) {
$doee.HOW.add_role($doee, $role)
if $role.HOW.archetypes.composable() {
$doee.HOW.add_role($doee, $role)
}
elsif $role.HOW.archetypes.composalizable() {
$doee.HOW.add_role($doee, $role.HOW.composalize($role))
}
else {
die $doee.HOW.name($doee) ~ " cannot compose " ~
$role.HOW.name($role) ~ " because it is not composable"
}
}

proto trait_mod:<of>(|$) { * }
Expand Down

0 comments on commit 8c9dd1a

Please sign in to comment.