Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday February 12, 2004
03:49 PM

Traits in Perl

[ #17380 ]

chromatic has Class::Roles on the CPAN. This is an attempt to implement traits in Perl. I think it's a great start,but there are a few features of traits that it doesn't implement yet. I've been thinking about the problem and I think I've got it licked. When all of the traits (roles) are used, a dynamically created interface is generated and it validates the integrity of the flattened class. It's a bit more complicated than it sounds, but I'll send chromatic some code when I'm done -- if it works.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I'm waiting to see what shakes out of A12 before I do much more work on it. Very few people really understand the point of roles; I hope that Larry will explain it far better than I've been able to do.

    • I don't blame you. It looks like there's a lot of potential there, but how it integrates into Perl 6 will be interesting.

      I just finished an alpha version of Class::Trait and I'm writing the docs now. I don't have a tarball uploaded, but the interface looks like this (borrowing heavily from your examples):

      package Person;
      # make them a lifeguard, but ensure that they use &Trait::Dog::swim and not
      # &Trait::LifeGuard::swim
      use Class::Trait 'Trait::LifeGuard';
      use Class::Trait 'Trait::Dog' => { exp

    • I forgot to mention that since I don't know how Perl 6 roles are to be implemented, my design goals were driven by my understanding of the original traits document. That's one of the reasons why I call them "traits" instead of "roles". I've thought about uploading this to the CPAN, but I have two concerns. First, I don't want to cause potential confusion when Perl 6 comes out. Second, since there are already beginning implementations of roles, I don't necessarily want to provide competing modules unless