In a message dated Wed, 4 Oct 2006, Jonathan Lang writes:
In Perl 6, the abstract SystemMonitor could be a role, and a concrete
ScriptedMonitor could be a class that does SystemMonitor, but it's not at
all clear to me what HardwareMonitor would be, since classes can't be
abstract and roles can't inherit from classes.
S12 says:
*> A role is allowed to declare an additional inheritance for its
*> class when that is considered an implementation detail:
*>
*> role Pet {
*> is Friend;
*> }
Thanks. This is what I was missing. I read the above, together with "A
role may not inherit from a class, but may be composed of other roles," as
specifying that any class doing Pet must already be a Friend, not that
doing Pet caused you to inherit from Friend.
I now see that what it meant was "a role may not *inherit* from a class,
because inheritance is a concept that only applies to instantiated
objects, but a role can *cause* its class to inherit from a class, which
works out to pretty much the same thing..."
So long as .post_data would work on a TempMonitor object below:
role SystemMonitor {
method post_data ($value, :$units, :$timestamp) {
# complete implementation here
}
}
class ScriptedMonitor is SystemMonitor {
# post_data never mentioned
}
role HardwareMonitor is ScriptedMonitor {
method post_data { next METHOD }
}
class TempMonitor is HardwareMonitor {
method post_data ($value, *%_) { call($value, :units(Celsius), |%_) }
}
I'm happy. It sounds like it should.
Trey