Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Class::Role, Class::Roles, and run-time role composition for Perl5

3 views
Skip to first unread message

Tim Bunce

unread,
Oct 21, 2005, 6:48:24 AM10/21/05
to perl6-l...@perl.org, chromatic, Luke Palmer, Tim Bunce
The Class::Role and Class::Roles modules on CPAN implement a form of
compile-time Perl6 role composition for Perl5.

Neither supports run-time role composition, as-in:
http://dev.perl.org/perl6/doc/design/syn/S12.html#Roles

The does operator returns the object so you can nest mixins:

$fido does Sentry does Tricks does TailChasing does Scratch;

Unlike the compile-time role composition, each of these layers on a new
mixin with a new level of inheritance, creating a new anonymous class
for dear old Fido, so that a .chase method from TailChasing hides a
.chase method from Sentry.

To help with DBI v2 I need a Perl5 implementation of roles that supports
run-time role composition.

I figure it just needs to generate a new class with @ISA set to
ref($random_object), link-in the methods, then rebless $random_object into it.
Plus a cache to avoid setting up a new class if it's already generated
one for ref($random_object)+$role_name.

I'd work on it myself but I'm busier than usual at the moment[1] and I
don't know which of Class::Role or Class::Roles I should add it to.
If no one volunteers I'll have a go in a week or three.

Tim.

[1] Our second child will be arriving 'any day'.

0 new messages