There are a lot of funky things about Perl5. Paradoxically, sometimes these are beautiful things as well. But oftentimes, they're just funky. As I've said before "I suspect with Perl 6, I'll only hate it on Tuesdays". I could rag about the weak encapsulation and the lack of useful method signature support in Perl5. But since I've really come to love Java's use of interfaces to compose an object's capabilities and disallowed multiple inheritance, I was interested in reading about Perl6's roles. Yes, in Perl6 a class can have a bunch of different roles. Here's a little bit of Larry from Apocalypse 12:
Roles can encompass both interface and implementation of object relationships. A role without implementation degenerates to an interface. A role without interface degenerates to privately instantiated generics. But the typical role will provide both interface and at least a default implementation.A little later, in discussing how roles are kinda like second class classes but not really, we see some hypothetical code:
The universe is a big place. And it keeps getting bigger. I guess I'll wait for Damian Conway to chime in. If Larry Wall writes the bible; Damian has to write the talmud.If you want to parameterize the initial value of a role attribute, be sure to put a colon if you don't want the parameter to be considered part of the long name:
role Pet[IDholder $id: $tag] { has IDholder $.collar .= new($tag); } class Dog does Pet[Collar, DogLicense("fido")] {...} class Pigeon does Pet[LegBand, RacerId()] {...} my $dog = new Dog; my $pigeon = new Pigeon;
In which case the long names of the roles in question are
Pet[Collar]
andPet[LegBand]
. In which case all of these are true:$dog.does(Dog) $dog.does(Pet) $dog.does(Pet[Collar])
but this is false:
$dog.does(Pet[LegBand])